JUCE-7.0.12-0-g4f43011b96 JUCE-7.0.12-0-g4f43011b96
JUCE — C++ application framework with suport for VST, VST3, LV2 audio plug-ins

« « « Anklang Documentation
Loading...
Searching...
No Matches
juce_Font.h
Go to the documentation of this file.
1 /*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
6
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
9
10 By using JUCE, you agree to the terms of both the JUCE 7 End-User License
11 Agreement and JUCE Privacy Policy.
12
13 End User License Agreement: www.juce.com/juce-7-licence
14 Privacy Policy: www.juce.com/juce-privacy-policy
15
16 Or: You may also use this code under the terms of the GPL v3 (see
17 www.gnu.org/licenses).
18
19 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
20 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
21 DISCLAIMED.
22
23 ==============================================================================
24*/
25
26namespace juce
27{
28
29//==============================================================================
41class JUCE_API Font final
42{
43public:
44 //==============================================================================
49 {
50 plain = 0,
51 bold = 1,
52 italic = 2,
53 underlined = 4
54 };
55
56 //==============================================================================
65 Font (float fontHeight, int styleFlags = plain);
66
76 Font (const String& typefaceName, float fontHeight, int styleFlags);
77
84 Font (const String& typefaceName, const String& typefaceStyle, float fontHeight);
85
87 Font (const Font& other) noexcept;
88
90 Font (const Typeface::Ptr& typeface);
91
98 Font();
99
101 Font (Font&& other) noexcept;
102
104 Font& operator= (Font&& other) noexcept;
105
107 Font& operator= (const Font& other) noexcept;
108
109 bool operator== (const Font& other) const noexcept;
110 bool operator!= (const Font& other) const noexcept;
111
113 ~Font() noexcept;
114
115 //==============================================================================
128 void setTypefaceName (const String& faceName);
129
141 String getTypefaceName() const noexcept;
142
143 //==============================================================================
147 String getTypefaceStyle() const noexcept;
148
152 void setTypefaceStyle (const String& newStyle);
153
157 [[nodiscard]] Font withTypefaceStyle (const String& newStyle) const;
158
160 StringArray getAvailableStyles() const;
161
162 //==============================================================================
173 static const String& getDefaultSansSerifFontName();
174
182 static const String& getDefaultSerifFontName();
183
191 static const String& getDefaultMonospacedFontName();
192
200 static const String& getDefaultStyle();
201
203 static Typeface::Ptr getDefaultTypefaceForFont (const Font& font);
204
205 //==============================================================================
207 [[nodiscard]] Font withHeight (float height) const;
208
210 [[nodiscard]] Font withPointHeight (float heightInPoints) const;
211
215 void setHeight (float newHeight);
216
220 void setHeightWithoutChangingWidth (float newHeight);
221
228 float getHeight() const noexcept;
229
236 float getHeightInPoints() const;
237
242 float getAscent() const;
243
248 float getAscentInPoints() const;
249
254 float getDescent() const;
255
260 float getDescentInPoints() const;
261
262 //==============================================================================
268 int getStyleFlags() const noexcept;
269
274 [[nodiscard]] Font withStyle (int styleFlags) const;
275
280 void setStyleFlags (int newFlags);
281
282 //==============================================================================
284 void setBold (bool shouldBeBold);
285
289 [[nodiscard]] Font boldened() const;
290
292 bool isBold() const noexcept;
293
295 void setItalic (bool shouldBeItalic);
297 [[nodiscard]] Font italicised() const;
299 bool isItalic() const noexcept;
300
302 void setUnderline (bool shouldBeUnderlined);
304 bool isUnderlined() const noexcept;
305
306 //==============================================================================
313 float getHorizontalScale() const noexcept;
314
320 [[nodiscard]] Font withHorizontalScale (float scaleFactor) const;
321
326 void setHorizontalScale (float scaleFactor);
327
332 static float getDefaultMinimumHorizontalScaleFactor() noexcept;
333
338 static void setDefaultMinimumHorizontalScaleFactor (float newMinimumScaleFactor) noexcept;
339
348 float getExtraKerningFactor() const noexcept;
349
356 [[nodiscard]] Font withExtraKerningFactor (float extraKerning) const;
357
364 void setExtraKerningFactor (float extraKerning);
365
366 //==============================================================================
368 void setSizeAndStyle (float newHeight,
369 int newStyleFlags,
370 float newHorizontalScale,
371 float newKerningAmount);
372
374 void setSizeAndStyle (float newHeight,
375 const String& newStyle,
376 float newHorizontalScale,
377 float newKerningAmount);
378
379 //==============================================================================
383 int getStringWidth (const String& text) const;
384
388 float getStringWidthFloat (const String& text) const;
389
395 void getGlyphPositions (const String& text, Array<int>& glyphs, Array<float>& xOffsets) const;
396
397 //==============================================================================
398 #ifndef DOXYGEN
404 [[deprecated ("This method is unsafe, use getTypefacePtr() instead.")]]
405 Typeface* getTypeface() const;
406 #endif
407
409 Typeface::Ptr getTypefacePtr() const;
410
418 static void findFonts (Array<Font>& results);
419
427 static StringArray findAllTypefaceNames();
428
436 static StringArray findAllTypefaceStyles (const String& family);
437
438 //==============================================================================
442 static const String& getFallbackFontName();
443
447 static void setFallbackFontName (const String& name);
448
452 static const String& getFallbackFontStyle();
453
457 static void setFallbackFontStyle (const String& style);
458
459 //==============================================================================
464 String toString() const;
465
470 static Font fromString (const String& fontDescription);
471
472private:
473 //==============================================================================
474 static bool compare (const Font&, const Font&) noexcept;
475
476 void dupeInternalIfShared();
477 void checkTypefaceSuitability();
478 float getHeightToPointsFactor() const;
479
480 friend struct GraphicsFontHelpers;
481
482 class SharedFontInternal;
484
486};
487
488} // namespace juce
Holds a resizable array of primitive or copy-by-value objects.
Definition juce_Array.h:56
Represents a particular font, including its size, style, etc.
Definition juce_Font.h:42
~Font() noexcept
Destructor.
FontStyleFlags
A combination of these values is used by the constructor to specify the style of font to use.
Definition juce_Font.h:49
A special array for holding a list of strings.
The JUCE String class!
Definition juce_String.h:53
A typeface represents a size-independent font.
#define JUCE_LEAK_DETECTOR(OwnerClass)
This macro lets you embed a leak-detecting object inside a class.
JUCE Namespace.
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...
Definition juce_Memory.h:88