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.cpp
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
29namespace FontValues
30{
31 static float limitFontHeight (const float height) noexcept
32 {
33 return jlimit (0.1f, 10000.0f, height);
34 }
35
36 const float defaultFontHeight = 14.0f;
37 float minimumHorizontalScale = 0.7f;
38 String fallbackFont;
39 String fallbackFontStyle;
40}
41
42using GetTypefaceForFont = Typeface::Ptr (*)(const Font&);
43GetTypefaceForFont juce_getTypefaceForFont = nullptr;
44
45float Font::getDefaultMinimumHorizontalScaleFactor() noexcept { return FontValues::minimumHorizontalScale; }
46void Font::setDefaultMinimumHorizontalScaleFactor (float newValue) noexcept { FontValues::minimumHorizontalScale = newValue; }
47
48//==============================================================================
50{
51public:
53 {
54 setSize (10);
55 }
56
58 {
60 }
61
63
64 void setSize (const int numToCache)
65 {
66 const ScopedWriteLock sl (lock);
67
68 faces.clear();
69 faces.insertMultiple (-1, CachedFace(), numToCache);
70 }
71
72 void clear()
73 {
74 const ScopedWriteLock sl (lock);
75
76 setSize (faces.size());
77 defaultFace = nullptr;
78 }
79
80 Typeface::Ptr findTypefaceFor (const Font& font)
81 {
82 const auto faceName = font.getTypefaceName();
83 const auto faceStyle = font.getTypefaceStyle();
84
85 jassert (faceName.isNotEmpty());
86
87 {
88 const ScopedReadLock slr (lock);
89
90 for (int i = faces.size(); --i >= 0;)
91 {
92 CachedFace& face = faces.getReference (i);
93
94 if (face.typefaceName == faceName
95 && face.typefaceStyle == faceStyle
96 && face.typeface != nullptr
97 && face.typeface->isSuitableForFont (font))
98 {
99 face.lastUsageCount = ++counter;
100 return face.typeface;
101 }
102 }
103 }
104
105 const ScopedWriteLock slw (lock);
106 int replaceIndex = 0;
108
109 for (int i = faces.size(); --i >= 0;)
110 {
111 auto lu = faces.getReference (i).lastUsageCount;
112
114 {
116 replaceIndex = i;
117 }
118 }
119
120 auto& face = faces.getReference (replaceIndex);
121 face.typefaceName = faceName;
122 face.typefaceStyle = faceStyle;
123 face.lastUsageCount = ++counter;
124
125 if (juce_getTypefaceForFont == nullptr)
126 face.typeface = Font::getDefaultTypefaceForFont (font);
127 else
128 face.typeface = juce_getTypefaceForFont (font);
129
130 jassert (face.typeface != nullptr); // the look and feel must return a typeface!
131
132 if (defaultFace == nullptr && font == Font())
133 defaultFace = face.typeface;
134
135 return face.typeface;
136 }
137
138 Typeface::Ptr getDefaultFace() const noexcept
139 {
140 const ScopedReadLock slr (lock);
141 return defaultFace;
142 }
143
144private:
145 struct CachedFace
146 {
147 CachedFace() noexcept {}
148
149 // Although it seems a bit wacky to store the name here, it's because it may be a
150 // placeholder rather than a real one, e.g. "<Sans-Serif>" vs the actual typeface name.
151 // Since the typeface itself doesn't know that it may have this alias, the name under
152 // which it was fetched needs to be stored separately.
153 String typefaceName, typefaceStyle;
154 size_t lastUsageCount = 0;
155 Typeface::Ptr typeface;
156 };
157
158 Typeface::Ptr defaultFace;
159 ReadWriteLock lock;
160 Array<CachedFace> faces;
161 size_t counter = 0;
162
164};
165
167
168void Typeface::setTypefaceCacheSize (int numFontsToCache)
169{
170 TypefaceCache::getInstance()->setSize (numFontsToCache);
171}
172
173void (*clearOpenGLGlyphCache)() = nullptr;
174
176{
177 TypefaceCache::getInstance()->clear();
178
179 RenderingHelpers::SoftwareRendererSavedState::clearGlyphCache();
180
181 NullCheckedInvocation::invoke (clearOpenGLGlyphCache);
182}
183
184//==============================================================================
186{
187public:
188 SharedFontInternal() noexcept
189 : typeface (TypefaceCache::getInstance()->getDefaultFace()),
190 typefaceName (Font::getDefaultSansSerifFontName()),
191 typefaceStyle (Font::getDefaultStyle()),
192 height (FontValues::defaultFontHeight)
193 {
194 }
195
196 SharedFontInternal (int styleFlags, float fontHeight) noexcept
197 : typefaceName (Font::getDefaultSansSerifFontName()),
198 typefaceStyle (FontStyleHelpers::getStyleName (styleFlags)),
199 height (fontHeight),
200 underline ((styleFlags & underlined) != 0)
201 {
202 if (styleFlags == plain)
203 typeface = TypefaceCache::getInstance()->getDefaultFace();
204 }
205
206 SharedFontInternal (const String& name, int styleFlags, float fontHeight) noexcept
207 : typefaceName (name),
208 typefaceStyle (FontStyleHelpers::getStyleName (styleFlags)),
209 height (fontHeight),
210 underline ((styleFlags & underlined) != 0)
211 {
212 if (styleFlags == plain && typefaceName.isEmpty())
213 typeface = TypefaceCache::getInstance()->getDefaultFace();
214 }
215
216 SharedFontInternal (const String& name, const String& style, float fontHeight) noexcept
217 : typefaceName (name), typefaceStyle (style), height (fontHeight)
218 {
219 if (typefaceName.isEmpty())
220 typefaceName = Font::getDefaultSansSerifFontName();
221 }
222
223 explicit SharedFontInternal (const Typeface::Ptr& face) noexcept
224 : typeface (face),
225 typefaceName (face->getName()),
226 typefaceStyle (face->getStyle()),
227 height (FontValues::defaultFontHeight)
228 {
229 jassert (typefaceName.isNotEmpty());
230 }
231
234 typeface (other.typeface),
235 typefaceName (other.typefaceName),
236 typefaceStyle (other.typefaceStyle),
237 height (other.height),
238 horizontalScale (other.horizontalScale),
239 kerning (other.kerning),
240 ascent (other.ascent),
241 underline (other.underline)
242 {
243 }
244
245 auto tie() const
246 {
247 return std::tie (height, underline, horizontalScale, kerning, typefaceName, typefaceStyle);
248 }
249
250 bool operator== (const SharedFontInternal& other) const noexcept
251 {
252 return tie() == other.tie();
253 }
254
255 bool operator< (const SharedFontInternal& other) const noexcept
256 {
257 return tie() < other.tie();
258 }
259
260 /* The typeface and ascent data members may be read/set from multiple threads
261 simultaneously, e.g. in the case that two Font instances reference the same
262 SharedFontInternal and call getTypefacePtr() simultaneously.
263
264 We lock in functions that modify the typeface or ascent in order to
265 ensure thread safety.
266 */
267
269 {
270 const ScopedLock lock (mutex);
271
272 if (typeface == nullptr)
273 {
274 typeface = TypefaceCache::getInstance()->findTypefaceFor (f);
275 jassert (typeface != nullptr);
276 }
277
278 return typeface;
279 }
280
281 void checkTypefaceSuitability (const Font& f)
282 {
283 const ScopedLock lock (mutex);
284
285 if (typeface != nullptr && ! typeface->isSuitableForFont (f))
286 typeface = nullptr;
287 }
288
289 float getAscent (const Font& f)
290 {
291 const ScopedLock lock (mutex);
292
293 if (approximatelyEqual (ascent, 0.0f))
294 ascent = getTypefacePtr (f)->getAscent();
295
296 return height * ascent;
297 }
298
299 /* We do not need to lock in these functions, as it's guaranteed
300 that these data members can only change if there is a single Font
301 instance referencing the shared state.
302 */
303
304 String getTypefaceName() const { return typefaceName; }
305 String getTypefaceStyle() const { return typefaceStyle; }
306 float getHeight() const { return height; }
307 float getHorizontalScale() const { return horizontalScale; }
308 float getKerning() const { return kerning; }
309 bool getUnderline() const { return underline; }
310
311 /* This shared state may be shared between two or more Font instances that are being
312 read/modified from multiple threads.
313 Before modifying a shared instance you *must* call dupeInternalIfShared to
314 ensure that only one Font instance is pointing to the SharedFontInternal instance
315 during the modification.
316 */
317
318 void setTypeface (Typeface::Ptr x)
319 {
320 jassert (getReferenceCount() == 1);
321 typeface = std::move (x);
322 }
323
324 void setTypefaceName (String x)
325 {
326 jassert (getReferenceCount() == 1);
327 typefaceName = std::move (x);
328 }
329
330 void setTypefaceStyle (String x)
331 {
332 jassert (getReferenceCount() == 1);
333 typefaceStyle = std::move (x);
334 }
335
336 void setHeight (float x)
337 {
338 jassert (getReferenceCount() == 1);
339 height = x;
340 }
341
342 void setHorizontalScale (float x)
343 {
344 jassert (getReferenceCount() == 1);
345 horizontalScale = x;
346 }
347
348 void setKerning (float x)
349 {
350 jassert (getReferenceCount() == 1);
351 kerning = x;
352 }
353
354 void setAscent (float x)
355 {
356 jassert (getReferenceCount() == 1);
357 ascent = x;
358 }
359
360 void setUnderline (bool x)
361 {
362 jassert (getReferenceCount() == 1);
363 underline = x;
364 }
365
366private:
367 Typeface::Ptr typeface;
368 String typefaceName, typefaceStyle;
369 float height = 0.0f, horizontalScale = 1.0f, kerning = 0.0f, ascent = 0.0f;
370 bool underline = false;
371
372 CriticalSection mutex;
373};
374
375//==============================================================================
377Font::Font (const Typeface::Ptr& typeface) : font (new SharedFontInternal (typeface)) {}
378Font::Font (const Font& other) noexcept : font (other.font) {}
379
380Font::Font (float fontHeight, int styleFlags)
381 : font (new SharedFontInternal (styleFlags, FontValues::limitFontHeight (fontHeight)))
382{
383}
384
385Font::Font (const String& typefaceName, float fontHeight, int styleFlags)
386 : font (new SharedFontInternal (typefaceName, styleFlags, FontValues::limitFontHeight (fontHeight)))
387{
388}
389
390Font::Font (const String& typefaceName, const String& typefaceStyle, float fontHeight)
391 : font (new SharedFontInternal (typefaceName, typefaceStyle, FontValues::limitFontHeight (fontHeight)))
392{
393}
394
396{
397 font = other.font;
398 return *this;
399}
400
402 : font (std::move (other.font))
403{
404}
405
407{
408 font = std::move (other.font);
409 return *this;
410}
411
412Font::~Font() noexcept = default;
413
414bool Font::operator== (const Font& other) const noexcept
415{
416 return font == other.font
417 || *font == *other.font;
418}
419
420bool Font::operator!= (const Font& other) const noexcept
421{
422 return ! operator== (other);
423}
424
425bool Font::compare (const Font& a, const Font& b) noexcept
426{
427 return *a.font < *b.font;
428}
429
430void Font::dupeInternalIfShared()
431{
432 if (font->getReferenceCount() > 1)
433 font = *new SharedFontInternal (*font);
434}
435
436void Font::checkTypefaceSuitability()
437{
438 font->checkTypefaceSuitability (*this);
439}
440
441//==============================================================================
443{
444 String sans { "<Sans-Serif>" },
445 serif { "<Serif>" },
446 mono { "<Monospaced>" },
447 regular { "<Regular>" };
448};
449
450static const FontPlaceholderNames& getFontPlaceholderNames()
451{
452 static FontPlaceholderNames names;
453 return names;
454}
455
456#if JUCE_MSVC
457// This is a workaround for the lack of thread-safety in MSVC's handling of function-local
458// statics - if multiple threads all try to create the first Font object at the same time,
459// it can cause a race-condition in creating these placeholder strings.
460struct FontNamePreloader { FontNamePreloader() { getFontPlaceholderNames(); } };
462#endif
463
464const String& Font::getDefaultSansSerifFontName() { return getFontPlaceholderNames().sans; }
465const String& Font::getDefaultSerifFontName() { return getFontPlaceholderNames().serif; }
466const String& Font::getDefaultMonospacedFontName() { return getFontPlaceholderNames().mono; }
467const String& Font::getDefaultStyle() { return getFontPlaceholderNames().regular; }
468
469String Font::getTypefaceName() const noexcept { return font->getTypefaceName(); }
470String Font::getTypefaceStyle() const noexcept { return font->getTypefaceStyle(); }
471
473{
474 if (faceName != font->getTypefaceName())
475 {
476 jassert (faceName.isNotEmpty());
477
478 dupeInternalIfShared();
479 font->setTypefaceName (faceName);
480 font->setTypeface (nullptr);
481 font->setAscent (0);
482 }
483}
484
485void Font::setTypefaceStyle (const String& typefaceStyle)
486{
487 if (typefaceStyle != font->getTypefaceStyle())
488 {
489 dupeInternalIfShared();
490 font->setTypefaceStyle (typefaceStyle);
491 font->setTypeface (nullptr);
492 font->setAscent (0);
493 }
494}
495
497{
498 Font f (*this);
500 return f;
501}
502
507
509{
510 return font->getTypefacePtr (*this);
511}
512
513Typeface* Font::getTypeface() const
514{
515 return getTypefacePtr().get();
516}
517
518//==============================================================================
520{
521 return FontValues::fallbackFont;
522}
523
525{
526 FontValues::fallbackFont = name;
527
528 #if JUCE_MAC || JUCE_IOS
529 jassertfalse; // Note that use of a fallback font isn't currently implemented in OSX..
530 #endif
531}
532
534{
535 return FontValues::fallbackFontStyle;
536}
537
539{
540 FontValues::fallbackFontStyle = style;
541
542 #if JUCE_MAC || JUCE_IOS
543 jassertfalse; // Note that use of a fallback font isn't currently implemented in OSX..
544 #endif
545}
546
547//==============================================================================
548Font Font::withHeight (const float newHeight) const
549{
550 Font f (*this);
552 return f;
553}
554
555float Font::getHeightToPointsFactor() const
556{
558}
559
561{
562 Font f (*this);
563 f.setHeight (heightInPoints / getHeightToPointsFactor());
564 return f;
565}
566
568{
569 newHeight = FontValues::limitFontHeight (newHeight);
570
571 if (! approximatelyEqual (font->getHeight(), newHeight))
572 {
573 dupeInternalIfShared();
574 font->setHeight (newHeight);
575 checkTypefaceSuitability();
576 }
577}
578
580{
581 newHeight = FontValues::limitFontHeight (newHeight);
582
583 if (! approximatelyEqual (font->getHeight(), newHeight))
584 {
585 dupeInternalIfShared();
586 font->setHorizontalScale (font->getHorizontalScale() * (font->getHeight() / newHeight));
587 font->setHeight (newHeight);
588 checkTypefaceSuitability();
589 }
590}
591
593{
594 int styleFlags = font->getUnderline() ? underlined : plain;
595
596 if (isBold()) styleFlags |= bold;
597 if (isItalic()) styleFlags |= italic;
598
599 return styleFlags;
600}
601
603{
604 Font f (*this);
606 return f;
607}
608
610{
611 if (getStyleFlags() != newFlags)
612 {
613 dupeInternalIfShared();
614 font->setTypeface (nullptr);
615 font->setTypefaceStyle (FontStyleHelpers::getStyleName (newFlags));
616 font->setUnderline ((newFlags & underlined) != 0);
617 font->setAscent (0);
618 }
619}
620
622 const int newStyleFlags,
623 const float newHorizontalScale,
624 const float newKerningAmount)
625{
626 newHeight = FontValues::limitFontHeight (newHeight);
627
628 if (! approximatelyEqual (font->getHeight(), newHeight)
629 || ! approximatelyEqual (font->getHorizontalScale(), newHorizontalScale)
630 || ! approximatelyEqual (font->getKerning(), newKerningAmount))
631 {
632 dupeInternalIfShared();
633 font->setHeight (newHeight);
634 font->setHorizontalScale (newHorizontalScale);
635 font->setKerning (newKerningAmount);
636 checkTypefaceSuitability();
637 }
638
640}
641
643 const String& newStyle,
644 const float newHorizontalScale,
645 const float newKerningAmount)
646{
647 newHeight = FontValues::limitFontHeight (newHeight);
648
649 if (! approximatelyEqual (font->getHeight(), newHeight)
650 || ! approximatelyEqual (font->getHorizontalScale(), newHorizontalScale)
651 || ! approximatelyEqual (font->getKerning(), newKerningAmount))
652 {
653 dupeInternalIfShared();
654 font->setHeight (newHeight);
655 font->setHorizontalScale (newHorizontalScale);
656 font->setKerning (newKerningAmount);
657 checkTypefaceSuitability();
658 }
659
661}
662
664{
665 Font f (*this);
667 return f;
668}
669
670void Font::setHorizontalScale (const float scaleFactor)
671{
672 dupeInternalIfShared();
673 font->setHorizontalScale (scaleFactor);
674 checkTypefaceSuitability();
675}
676
678{
679 return font->getHorizontalScale();
680}
681
683{
684 return font->getKerning();
685}
686
688{
689 Font f (*this);
691 return f;
692}
693
695{
696 dupeInternalIfShared();
697 font->setKerning (extraKerning);
698 checkTypefaceSuitability();
699}
700
703
704bool Font::isBold() const noexcept { return FontStyleHelpers::isBold (font->getTypefaceStyle()); }
705bool Font::isItalic() const noexcept { return FontStyleHelpers::isItalic (font->getTypefaceStyle()); }
706bool Font::isUnderlined() const noexcept { return font->getUnderline(); }
707
709{
710 auto flags = getStyleFlags();
711 setStyleFlags (shouldBeBold ? (flags | bold)
712 : (flags & ~bold));
713}
714
716{
717 auto flags = getStyleFlags();
719 : (flags & ~italic));
720}
721
723{
724 dupeInternalIfShared();
725 font->setUnderline (shouldBeUnderlined);
726 checkTypefaceSuitability();
727}
728
729float Font::getAscent() const
730{
731 return font->getAscent (*this);
732}
733
734float Font::getHeight() const noexcept { return font->getHeight(); }
735float Font::getDescent() const { return font->getHeight() - getAscent(); }
736
737float Font::getHeightInPoints() const { return getHeight() * getHeightToPointsFactor(); }
738float Font::getAscentInPoints() const { return getAscent() * getHeightToPointsFactor(); }
739float Font::getDescentInPoints() const { return getDescent() * getHeightToPointsFactor(); }
740
741int Font::getStringWidth (const String& text) const
742{
743 return (int) std::ceil (getStringWidthFloat (text));
744}
745
746float Font::getStringWidthFloat (const String& text) const
747{
748 auto w = getTypefacePtr()->getStringWidth (text);
749
750 if (! approximatelyEqual (font->getKerning(), 0.0f))
751 w += font->getKerning() * (float) text.length();
752
753 return w * font->getHeight() * font->getHorizontalScale();
754}
755
757{
758 getTypefacePtr()->getGlyphPositions (text, glyphs, xOffsets);
759
760 if (auto num = xOffsets.size())
761 {
762 auto scale = font->getHeight() * font->getHorizontalScale();
763 auto* x = xOffsets.getRawDataPointer();
764
765 if (! approximatelyEqual (font->getKerning(), 0.0f))
766 {
767 for (int i = 0; i < num; ++i)
768 x[i] = (x[i] + (float) i * font->getKerning()) * scale;
769 }
770 else
771 {
772 for (int i = 0; i < num; ++i)
773 x[i] *= scale;
774 }
775 }
776}
777
779{
780 for (auto& name : findAllTypefaceNames())
781 {
782 auto styles = findAllTypefaceStyles (name);
783
784 String style ("Regular");
785
786 if (! styles.contains (style, true))
787 style = styles[0];
788
789 destArray.add (Font (name, style, FontValues::defaultFontHeight));
790 }
791}
792
793//==============================================================================
795{
796 String s;
797
799 s << getTypefaceName() << "; ";
800
801 s << String (getHeight(), 1);
802
804 s << ' ' << getTypefaceStyle();
805
806 return s;
807}
808
810{
811 const int separator = fontDescription.indexOfChar (';');
812 String name;
813
814 if (separator > 0)
815 name = fontDescription.substring (0, separator).trim();
816
817 if (name.isEmpty())
819
820 String sizeAndStyle (fontDescription.substring (separator + 1).trimStart());
821
822 float height = sizeAndStyle.getFloatValue();
823 if (height <= 0)
824 height = 10.0f;
825
826 const String style (sizeAndStyle.fromFirstOccurrenceOf (" ", false, false));
827
828 return Font (name, style, height);
829}
830
831} // namespace juce
T ceil(T... args)
Holds a resizable array of primitive or copy-by-value objects.
Definition juce_Array.h:56
int size() const noexcept
Returns the current number of elements in the array.
Definition juce_Array.h:215
void insertMultiple(int indexToInsertAt, ParameterType newElement, int numberOfTimesToInsertIt)
Inserts multiple copies of an element into the array at a given position.
Definition juce_Array.h:480
void clear()
Removes all elements from the array.
Definition juce_Array.h:188
ElementType & getReference(int index) noexcept
Returns a direct reference to one of the elements in the array, without checking the index passed in.
Definition juce_Array.h:267
Classes derived from this will be automatically deleted when the application exits.
Represents a particular font, including its size, style, etc.
Definition juce_Font.h:42
Font withExtraKerningFactor(float extraKerning) const
Returns a copy of this font with a new kerning factor.
void setExtraKerningFactor(float extraKerning)
Changes the font's kerning.
static const String & getFallbackFontStyle()
Returns the font style of the typeface to be used for rendering glyphs that aren't found in the reque...
Font withHeight(float height) const
Returns a copy of this font with a new height.
int getStyleFlags() const noexcept
Returns the font's style flags.
float getHeightInPoints() const
Returns the total height of this font, in points.
static const String & getDefaultStyle()
Returns a font style name that represents the default style.
static const String & getFallbackFontName()
Returns the font family of the typeface to be used for rendering glyphs that aren't found in the requ...
void getGlyphPositions(const String &text, Array< int > &glyphs, Array< float > &xOffsets) const
Returns the series of glyph numbers and their x offsets needed to represent a string.
void setUnderline(bool shouldBeUnderlined)
Makes the font underlined or non-underlined.
static float getDefaultMinimumHorizontalScaleFactor() noexcept
Returns the minimum horizontal scale to which fonts may be squashed when trying to create a layout.
Definition juce_Font.cpp:45
static Typeface::Ptr getDefaultTypefaceForFont(const Font &font)
Returns the default system typeface for the given font.
void setSizeAndStyle(float newHeight, int newStyleFlags, float newHorizontalScale, float newKerningAmount)
Changes all the font's characteristics with one call.
static const String & getDefaultSansSerifFontName()
Returns a typeface font family that represents the default sans-serif font.
static Font fromString(const String &fontDescription)
Recreates a font from its stringified encoding.
float getDescent() const
Returns the amount that the font descends below its baseline, in pixels.
Typeface::Ptr getTypefacePtr() const
Returns the typeface used by this font.
float getHeight() const noexcept
Returns the total height of this font, in pixels.
String getTypefaceName() const noexcept
Returns the font family of the typeface that this font uses.
static const String & getDefaultMonospacedFontName()
Returns a typeface font family that represents the default monospaced font.
void setStyleFlags(int newFlags)
Changes the font's style.
String getTypefaceStyle() const noexcept
Returns the font style of the typeface that this font uses.
String toString() const
Creates a string to describe this font.
bool isItalic() const noexcept
Returns true if the font is italic.
static StringArray findAllTypefaceStyles(const String &family)
Returns a list of all the available typeface font styles.
float getStringWidthFloat(const String &text) const
Returns the total width of a string as it would be drawn using this font.
void setItalic(bool shouldBeItalic)
Makes the font italic or non-italic.
void setBold(bool shouldBeBold)
Makes the font bold or non-bold.
int getStringWidth(const String &text) const
Returns the total width of a string as it would be drawn using this font.
StringArray getAvailableStyles() const
Returns a list of the styles that this font can use.
void setTypefaceStyle(const String &newStyle)
Changes the font style of the typeface.
void setHorizontalScale(float scaleFactor)
Changes the font's horizontal scale factor.
void setTypefaceName(const String &faceName)
Changes the font family of the typeface.
float getAscent() const
Returns the height of the font above its baseline, in pixels.
~Font() noexcept
Destructor.
static StringArray findAllTypefaceNames()
Returns a list of all the available typeface font families.
static void findFonts(Array< Font > &results)
Creates an array of Font objects to represent all the fonts on the system.
Font boldened() const
Returns a copy of this font with the bold attribute set.
Font withTypefaceStyle(const String &newStyle) const
Returns a copy of this font with a new typeface style.
Font withStyle(int styleFlags) const
Returns a copy of this font with the given set of style flags.
bool isBold() const noexcept
Returns true if the font is bold.
float getExtraKerningFactor() const noexcept
Returns the font's kerning.
Font italicised() const
Returns a copy of this font with the italic attribute set.
@ bold
boldens the font.
Definition juce_Font.h:51
@ underlined
underlines the font.
Definition juce_Font.h:53
@ plain
indicates a plain, non-bold, non-italic version of the font.
Definition juce_Font.h:50
@ italic
finds an italic version of the font.
Definition juce_Font.h:52
bool isUnderlined() const noexcept
Returns true if the font is underlined.
Font()
Creates a basic sans-serif font at a default height.
float getAscentInPoints() const
Returns the height of the font above its baseline, in points.
float getDescentInPoints() const
Returns the amount that the font descends below its baseline, in points.
static const String & getDefaultSerifFontName()
Returns a typeface font family that represents the default serif font.
void setHeightWithoutChangingWidth(float newHeight)
Changes the font's height without changing its width.
void setHeight(float newHeight)
Changes the font's height.
Font withHorizontalScale(float scaleFactor) const
Returns a copy of this font with a new horizontal scale.
static void setDefaultMinimumHorizontalScaleFactor(float newMinimumScaleFactor) noexcept
Sets the minimum horizontal scale to which fonts may be squashed when trying to create a text layout.
Definition juce_Font.cpp:46
Font & operator=(Font &&other) noexcept
Move assignment operator.
float getHorizontalScale() const noexcept
Returns the font's horizontal scale.
Font withPointHeight(float heightInPoints) const
Returns a copy of this font with a new height, specified in points.
static void setFallbackFontName(const String &name)
Sets the (platform-specific) font family of the typeface to use to find glyphs that aren't available ...
static void setFallbackFontStyle(const String &style)
Sets the (platform-specific) font style of the typeface to use to find glyphs that aren't available i...
Automatically locks and unlocks a mutex object.
A critical section that allows multiple simultaneous readers.
ReferencedType * get() const noexcept
Returns the object that this pointer references.
A base class which provides methods for reference-counting.
ReferenceCountedObject()=default
Creates the reference-counted object (with an initial ref count of zero).
int getReferenceCount() const noexcept
Returns the object's current reference count.
Automatically locks and unlocks a ReadWriteLock object.
Automatically locks and unlocks a ReadWriteLock object.
A special array for holding a list of strings.
The JUCE String class!
Definition juce_String.h:53
int length() const noexcept
Returns the number of characters in the string.
String trim() const
Returns a copy of this string with any whitespace characters removed from the start and end.
bool isEmpty() const noexcept
Returns true if the string contains no characters.
String substring(int startIndex, int endIndex) const
Returns a subsection of the string.
bool isNotEmpty() const noexcept
Returns true if the string contains at least one character.
A typeface represents a size-independent font.
virtual float getStringWidth(const String &text)=0
Measures the width of a line of text.
virtual float getAscent() const =0
Returns the ascent of the font, as a proportion of its height.
const String & getStyle() const noexcept
Returns the font style of the typeface.
virtual bool isSuitableForFont(const Font &) const
Returns true if this typeface can be used to render the specified font.
const String & getName() const noexcept
Returns the font family of the typeface.
virtual float getHeightToPointsFactor() const =0
Returns the value by which you should multiply a JUCE font-height value to convert it to the equivale...
ReferenceCountedObjectPtr< Typeface > Ptr
A handy typedef for a pointer to a typeface.
static void clearTypefaceCache()
Clears any fonts that are currently cached in memory.
virtual void getGlyphPositions(const String &text, Array< int > &glyphs, Array< float > &xOffsets)=0
Converts a line of text into its glyph numbers and their positions.
#define jassert(expression)
Platform-independent assertion macro.
#define JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(className)
This is a shorthand way of writing both a JUCE_DECLARE_NON_COPYABLE and JUCE_LEAK_DETECTOR macro for ...
#define jassertfalse
This will always cause an assertion failure.
#define JUCE_IMPLEMENT_SINGLETON(Classname)
This is a counterpart to the JUCE_DECLARE_SINGLETON macros.
#define JUCE_DECLARE_SINGLETON(Classname, doNotRecreateAfterDeletion)
Macro to generate the appropriate methods and boilerplate for a singleton class.
typedef float
T max(T... args)
JUCE Namespace.
constexpr bool approximatelyEqual(Type a, Type b, Tolerance< Type > tolerance=Tolerance< Type >{} .withAbsolute(std::numeric_limits< Type >::min()) .withRelative(std::numeric_limits< Type >::epsilon()))
Returns true if the two floating-point numbers are approximately equal.
Type jlimit(Type lowerLimit, Type upperLimit, Type valueToConstrain) noexcept
Constrains a value to keep it within a given range.
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
T tie(T... args)