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 <config_options.h>
23 #include <svtools/svtdllapi.h>
24 #include <rtl/ustring.hxx>
25 #include <sal/types.h>
26 #include <vcl/metric.hxx>
27 #include <vcl/vclptr.hxx>
31 #include <string_view>
33 class ImplFontListNameInfo
;
43 This class manages all fonts which can be display on one or two output devices.
44 Additionally, this class offers methods for generating the StyleName from
45 bold and italics or the missing attributes from a StyleName.
46 Furthermore, this class can handle synthetically reproduced fonts.
47 It also works with several standard controls and standard menus.
51 class FontNameBox, class FontStyleBox, class FontSizeBox,
52 class FontNameMenu, class FontSizeMenu
54 --------------------------------------------------------------------------
56 FontList::FontList( OutputDevice* pDevice, OutputDevice* pDevice2 = NULL,
59 Constructor of the FontList class. The relevant fonts will be queried from
60 the OutputDevice. The OutputDevice needs to exist as long as the FontList
61 class exists. Optionally, a second output device can be given in order to,
62 e.g., manage the fonts from both, a printer and a screen in a single FontList
63 and thus also give FontMenus the fonts if both OutputDevices.
64 The pDevice2 needs to exist as long as the FontList class exists.
66 The OutputDevice given first should be the preferred one. This is usually
67 the printer. Because if two different device fonts (one for the printer and
68 one for the screen) exist, the ones from the "pDevice" are preferred.
70 The third parameter governs whether only scalable or all fonts shall be queried.
71 With sal_True bitmap fonts will also be queried.
72 With sal_False vectorized and scalable fonts will be queried.
74 --------------------------------------------------------------------------
76 String FontList::GetStyleName( const FontMetric& rFontMetric ) const;
78 This method returns the StyleName of a FontMetric.
79 If no StyleName is set, a name will be generated from the set attributes.
81 --------------------------------------------------------------------------
83 OUString FontList::GetFontMapText( const FontMetric& rFontMetric ) const;
85 This method returns a Matchstring which indicates the problem that could
86 arise when using a font. This string should be displayed to the user.
88 --------------------------------------------------------------------------
90 FontMetric FontList::Get( const String& rName, const String& rStyleName ) const;
92 This method search a FontMetric for the given name and the given style name.
93 The Stylename can also be a synthetic one.
94 In that case the relevant FontMetric fields will be set.
95 If a StyleName is provided, a FontMetric structure without a Stylename can be
96 returned. To get a representation of the StyleName for displaying it to the user,
97 call GetStyleName() on this FontMetric structure.
101 FontList::GetStyleName()
103 --------------------------------------------------------------------------
105 FontMetric FontList::Get( const String& rName, FontWeight eWeight,
106 FontItalic eItalic ) const;
108 This method search a FontMetric structure for a provided name and styles.
109 This method can also return a FontMetric without a Stylename.
110 To get a representation of the StyleName to be presented to the user
111 call GetStyleName() with this FontMetric.
115 FontList::GetStyleName()
117 --------------------------------------------------------------------------
119 static const int* FontList::GetStdSizeAry();
121 This method returns the available sizes for the given font.
122 As all fonts are scalable, standard sizes are returned.
123 The array contains the heights of the font in tenth (1/10) point.
124 The last value of the array is 0.
125 The returned array will destroyed by the FontList.
126 You should thus not reference the array after the next method call on the
130 class SVT_DLLPUBLIC FontList
133 static const int aStdSizeAry
[];
136 OUString maMapPrinterOnly
;
137 OUString maMapStyleNotAvailable
;
138 mutable OUString maMapNotAvailable
;
140 OUString maLightItalic
;
142 OUString maNormalItalic
;
144 OUString maBoldItalic
;
146 OUString maBlackItalic
;
147 VclPtr
<OutputDevice
> mpDev
;
148 VclPtr
<OutputDevice
> mpDev2
;
149 std::vector
<std::unique_ptr
<ImplFontListNameInfo
>> m_Entries
;
151 SVT_DLLPRIVATE ImplFontListNameInfo
* ImplFind( std::u16string_view rSearchName
, sal_uInt32
* pIndex
) const;
152 SVT_DLLPRIVATE ImplFontListNameInfo
* ImplFindByName( std::u16string_view rStr
) const;
153 SVT_DLLPRIVATE
void ImplInsertFonts(OutputDevice
* pDev
, bool bInsertData
);
156 FontList( OutputDevice
* pDevice
,
157 OutputDevice
* pDevice2
= nullptr);
160 std::unique_ptr
<FontList
> Clone() const;
162 const OUString
& GetFontMapText( const FontMetric
& rFontMetric
) const;
164 const OUString
& GetNormalStr() const { return maNormal
; }
165 const OUString
& GetItalicStr() const { return maNormalItalic
; }
166 const OUString
& GetBoldStr() const { return maBold
; }
167 const OUString
& GetBoldItalicStr() const { return maBoldItalic
; }
168 const OUString
& GetStyleName( FontWeight eWeight
, FontItalic eItalic
) const;
169 OUString
GetStyleName( const FontMetric
& rFontMetric
) const;
171 FontMetric
Get( const OUString
& rName
,
172 const OUString
& rStyleName
) const;
173 FontMetric
Get( const OUString
& rName
,
175 FontItalic eItalic
) const;
177 bool IsAvailable( std::u16string_view rName
) const;
178 size_t GetFontNameCount() const
180 return m_Entries
.size();
182 const FontMetric
& GetFontName(size_t nFont
) const;
183 sal_Handle
GetFirstFontMetric( std::u16string_view rName
) const;
184 static sal_Handle
GetNextFontMetric( sal_Handle hFontMetric
);
185 static const FontMetric
& GetFontMetric( sal_Handle hFontMetric
);
187 static const int* GetStdSizeAry() { return aStdSizeAry
; }
190 FontList( const FontList
& ) = delete;
191 FontList
& operator =( const FontList
& ) = delete;
194 class UNLESS_MERGELIBS(SVT_DLLPUBLIC
) FontSizeNames
197 const struct ImplFSNameItem
* mpArray
;
201 FontSizeNames( LanguageType eLanguage
/* = LANGUAGE_DONTKNOW */ );
203 sal_Int32
Count() const { return mnElem
; }
204 bool IsEmpty() const { return !mnElem
; }
206 sal_Int32
Name2Size( std::u16string_view
) const;
207 OUString
Size2Name( sal_Int32
) const;
209 OUString
GetIndexName( sal_Int32 nIndex
) const;
210 sal_Int32
GetIndexSize( sal_Int32 nIndex
) const;
213 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */