Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

juce_Font.cpp 21KB

9 years ago
9 years ago
10 years ago
10 years ago
9 years ago
10 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721
  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2015 - ROLI Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. namespace FontValues
  18. {
  19. static float limitFontHeight (const float height) noexcept
  20. {
  21. return jlimit (0.1f, 10000.0f, height);
  22. }
  23. const float defaultFontHeight = 14.0f;
  24. float minimumHorizontalScale = 0.7f;
  25. String fallbackFont;
  26. String fallbackFontStyle;
  27. }
  28. typedef Typeface::Ptr (*GetTypefaceForFont) (const Font&);
  29. GetTypefaceForFont juce_getTypefaceForFont = nullptr;
  30. float Font::getDefaultMinimumHorizontalScaleFactor() noexcept { return FontValues::minimumHorizontalScale; }
  31. void Font::setDefaultMinimumHorizontalScaleFactor (float newValue) noexcept { FontValues::minimumHorizontalScale = newValue; }
  32. //==============================================================================
  33. class TypefaceCache : private DeletedAtShutdown
  34. {
  35. public:
  36. TypefaceCache() : counter (0)
  37. {
  38. setSize (10);
  39. }
  40. ~TypefaceCache()
  41. {
  42. clearSingletonInstance();
  43. }
  44. juce_DeclareSingleton (TypefaceCache, false)
  45. void setSize (const int numToCache)
  46. {
  47. const ScopedWriteLock sl (lock);
  48. faces.clear();
  49. faces.insertMultiple (-1, CachedFace(), numToCache);
  50. }
  51. void clear()
  52. {
  53. const ScopedWriteLock sl (lock);
  54. setSize (faces.size());
  55. defaultFace = nullptr;
  56. }
  57. Typeface::Ptr findTypefaceFor (const Font& font)
  58. {
  59. const ScopedReadLock slr (lock);
  60. const String faceName (font.getTypefaceName());
  61. const String faceStyle (font.getTypefaceStyle());
  62. jassert (faceName.isNotEmpty());
  63. for (int i = faces.size(); --i >= 0;)
  64. {
  65. CachedFace& face = faces.getReference(i);
  66. if (face.typefaceName == faceName
  67. && face.typefaceStyle == faceStyle
  68. && face.typeface != nullptr
  69. && face.typeface->isSuitableForFont (font))
  70. {
  71. face.lastUsageCount = ++counter;
  72. return face.typeface;
  73. }
  74. }
  75. const ScopedWriteLock slw (lock);
  76. int replaceIndex = 0;
  77. size_t bestLastUsageCount = std::numeric_limits<size_t>::max();
  78. for (int i = faces.size(); --i >= 0;)
  79. {
  80. const size_t lu = faces.getReference(i).lastUsageCount;
  81. if (bestLastUsageCount > lu)
  82. {
  83. bestLastUsageCount = lu;
  84. replaceIndex = i;
  85. }
  86. }
  87. CachedFace& face = faces.getReference (replaceIndex);
  88. face.typefaceName = faceName;
  89. face.typefaceStyle = faceStyle;
  90. face.lastUsageCount = ++counter;
  91. if (juce_getTypefaceForFont == nullptr)
  92. face.typeface = Font::getDefaultTypefaceForFont (font);
  93. else
  94. face.typeface = juce_getTypefaceForFont (font);
  95. jassert (face.typeface != nullptr); // the look and feel must return a typeface!
  96. if (defaultFace == nullptr && font == Font())
  97. defaultFace = face.typeface;
  98. return face.typeface;
  99. }
  100. Typeface::Ptr defaultFace;
  101. private:
  102. struct CachedFace
  103. {
  104. CachedFace() noexcept : lastUsageCount (0) {}
  105. // Although it seems a bit wacky to store the name here, it's because it may be a
  106. // placeholder rather than a real one, e.g. "<Sans-Serif>" vs the actual typeface name.
  107. // Since the typeface itself doesn't know that it may have this alias, the name under
  108. // which it was fetched needs to be stored separately.
  109. String typefaceName, typefaceStyle;
  110. size_t lastUsageCount;
  111. Typeface::Ptr typeface;
  112. };
  113. ReadWriteLock lock;
  114. Array<CachedFace> faces;
  115. size_t counter;
  116. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (TypefaceCache)
  117. };
  118. juce_ImplementSingleton (TypefaceCache)
  119. void Typeface::setTypefaceCacheSize (int numFontsToCache)
  120. {
  121. TypefaceCache::getInstance()->setSize (numFontsToCache);
  122. }
  123. void (*clearOpenGLGlyphCache)() = nullptr;
  124. void Typeface::clearTypefaceCache()
  125. {
  126. TypefaceCache::getInstance()->clear();
  127. RenderingHelpers::SoftwareRendererSavedState::clearGlyphCache();
  128. if (clearOpenGLGlyphCache != nullptr)
  129. clearOpenGLGlyphCache();
  130. }
  131. //==============================================================================
  132. class Font::SharedFontInternal : public ReferenceCountedObject
  133. {
  134. public:
  135. SharedFontInternal() noexcept
  136. : typeface (TypefaceCache::getInstance()->defaultFace),
  137. typefaceName (Font::getDefaultSansSerifFontName()),
  138. typefaceStyle (Font::getDefaultStyle()),
  139. height (FontValues::defaultFontHeight),
  140. horizontalScale (1.0f), kerning (0), ascent (0), underline (false)
  141. {
  142. }
  143. SharedFontInternal (int styleFlags, float fontHeight) noexcept
  144. : typefaceName (Font::getDefaultSansSerifFontName()),
  145. typefaceStyle (FontStyleHelpers::getStyleName (styleFlags)),
  146. height (fontHeight),
  147. horizontalScale (1.0f), kerning (0), ascent (0), underline ((styleFlags & underlined) != 0)
  148. {
  149. if (styleFlags == plain)
  150. typeface = TypefaceCache::getInstance()->defaultFace;
  151. }
  152. SharedFontInternal (const String& name, int styleFlags, float fontHeight) noexcept
  153. : typefaceName (name),
  154. typefaceStyle (FontStyleHelpers::getStyleName (styleFlags)),
  155. height (fontHeight),
  156. horizontalScale (1.0f), kerning (0), ascent (0), underline ((styleFlags & underlined) != 0)
  157. {
  158. if (styleFlags == plain && typefaceName.isEmpty())
  159. typeface = TypefaceCache::getInstance()->defaultFace;
  160. }
  161. SharedFontInternal (const String& name, const String& style, float fontHeight) noexcept
  162. : typefaceName (name), typefaceStyle (style), height (fontHeight),
  163. horizontalScale (1.0f), kerning (0), ascent (0), underline (false)
  164. {
  165. if (typefaceName.isEmpty())
  166. typefaceName = Font::getDefaultSansSerifFontName();
  167. }
  168. explicit SharedFontInternal (const Typeface::Ptr& face) noexcept
  169. : typeface (face),
  170. typefaceName (face->getName()),
  171. typefaceStyle (face->getStyle()),
  172. height (FontValues::defaultFontHeight),
  173. horizontalScale (1.0f), kerning (0), ascent (0), underline (false)
  174. {
  175. jassert (typefaceName.isNotEmpty());
  176. }
  177. SharedFontInternal (const SharedFontInternal& other) noexcept
  178. : ReferenceCountedObject(),
  179. typeface (other.typeface),
  180. typefaceName (other.typefaceName),
  181. typefaceStyle (other.typefaceStyle),
  182. height (other.height),
  183. horizontalScale (other.horizontalScale),
  184. kerning (other.kerning),
  185. ascent (other.ascent),
  186. underline (other.underline)
  187. {
  188. }
  189. bool operator== (const SharedFontInternal& other) const noexcept
  190. {
  191. return height == other.height
  192. && underline == other.underline
  193. && horizontalScale == other.horizontalScale
  194. && kerning == other.kerning
  195. && typefaceName == other.typefaceName
  196. && typefaceStyle == other.typefaceStyle;
  197. }
  198. Typeface::Ptr typeface;
  199. String typefaceName, typefaceStyle;
  200. float height, horizontalScale, kerning, ascent;
  201. bool underline;
  202. };
  203. //==============================================================================
  204. Font::Font() : font (new SharedFontInternal()) {}
  205. Font::Font (const Typeface::Ptr& typeface) : font (new SharedFontInternal (typeface)) {}
  206. Font::Font (const Font& other) noexcept : font (other.font) {}
  207. Font::Font (float fontHeight, int styleFlags)
  208. : font (new SharedFontInternal (styleFlags, FontValues::limitFontHeight (fontHeight)))
  209. {
  210. }
  211. Font::Font (const String& typefaceName, float fontHeight, int styleFlags)
  212. : font (new SharedFontInternal (typefaceName, styleFlags, FontValues::limitFontHeight (fontHeight)))
  213. {
  214. }
  215. Font::Font (const String& typefaceName, const String& typefaceStyle, float fontHeight)
  216. : font (new SharedFontInternal (typefaceName, typefaceStyle, FontValues::limitFontHeight (fontHeight)))
  217. {
  218. }
  219. Font& Font::operator= (const Font& other) noexcept
  220. {
  221. font = other.font;
  222. return *this;
  223. }
  224. #if JUCE_COMPILER_SUPPORTS_MOVE_SEMANTICS
  225. Font::Font (Font&& other) noexcept
  226. : font (static_cast<ReferenceCountedObjectPtr<SharedFontInternal>&&> (other.font))
  227. {
  228. }
  229. Font& Font::operator= (Font&& other) noexcept
  230. {
  231. font = static_cast<ReferenceCountedObjectPtr<SharedFontInternal>&&> (other.font);
  232. return *this;
  233. }
  234. #endif
  235. Font::~Font() noexcept
  236. {
  237. }
  238. bool Font::operator== (const Font& other) const noexcept
  239. {
  240. return font == other.font
  241. || *font == *other.font;
  242. }
  243. bool Font::operator!= (const Font& other) const noexcept
  244. {
  245. return ! operator== (other);
  246. }
  247. void Font::dupeInternalIfShared()
  248. {
  249. if (font->getReferenceCount() > 1)
  250. font = new SharedFontInternal (*font);
  251. }
  252. void Font::checkTypefaceSuitability()
  253. {
  254. if (font->typeface != nullptr && ! font->typeface->isSuitableForFont (*this))
  255. font->typeface = nullptr;
  256. }
  257. //==============================================================================
  258. struct FontPlaceholderNames
  259. {
  260. FontPlaceholderNames()
  261. : sans ("<Sans-Serif>"),
  262. serif ("<Serif>"),
  263. mono ("<Monospaced>"),
  264. regular ("<Regular>")
  265. {
  266. }
  267. String sans, serif, mono, regular;
  268. };
  269. const FontPlaceholderNames& getFontPlaceholderNames()
  270. {
  271. static FontPlaceholderNames names;
  272. return names;
  273. }
  274. #if JUCE_MSVC
  275. // This is a workaround for the lack of thread-safety in MSVC's handling of function-local
  276. // statics - if multiple threads all try to create the first Font object at the same time,
  277. // it can cause a race-condition in creating these placeholder strings.
  278. struct FontNamePreloader { FontNamePreloader() { getFontPlaceholderNames(); } };
  279. static FontNamePreloader fnp;
  280. #endif
  281. const String& Font::getDefaultSansSerifFontName() { return getFontPlaceholderNames().sans; }
  282. const String& Font::getDefaultSerifFontName() { return getFontPlaceholderNames().serif; }
  283. const String& Font::getDefaultMonospacedFontName() { return getFontPlaceholderNames().mono; }
  284. const String& Font::getDefaultStyle() { return getFontPlaceholderNames().regular; }
  285. const String& Font::getTypefaceName() const noexcept { return font->typefaceName; }
  286. const String& Font::getTypefaceStyle() const noexcept { return font->typefaceStyle; }
  287. void Font::setTypefaceName (const String& faceName)
  288. {
  289. if (faceName != font->typefaceName)
  290. {
  291. jassert (faceName.isNotEmpty());
  292. dupeInternalIfShared();
  293. font->typefaceName = faceName;
  294. font->typeface = nullptr;
  295. font->ascent = 0;
  296. }
  297. }
  298. void Font::setTypefaceStyle (const String& typefaceStyle)
  299. {
  300. if (typefaceStyle != font->typefaceStyle)
  301. {
  302. dupeInternalIfShared();
  303. font->typefaceStyle = typefaceStyle;
  304. font->typeface = nullptr;
  305. font->ascent = 0;
  306. }
  307. }
  308. Font Font::withTypefaceStyle (const String& newStyle) const
  309. {
  310. Font f (*this);
  311. f.setTypefaceStyle (newStyle);
  312. return f;
  313. }
  314. StringArray Font::getAvailableStyles() const
  315. {
  316. return findAllTypefaceStyles (getTypeface()->getName());
  317. }
  318. Typeface* Font::getTypeface() const
  319. {
  320. if (font->typeface == nullptr)
  321. {
  322. font->typeface = TypefaceCache::getInstance()->findTypefaceFor (*this);
  323. jassert (font->typeface != nullptr);
  324. }
  325. return font->typeface;
  326. }
  327. //==============================================================================
  328. const String& Font::getFallbackFontName()
  329. {
  330. return FontValues::fallbackFont;
  331. }
  332. void Font::setFallbackFontName (const String& name)
  333. {
  334. FontValues::fallbackFont = name;
  335. #if JUCE_MAC || JUCE_IOS
  336. jassertfalse; // Note that use of a fallback font isn't currently implemented in OSX..
  337. #endif
  338. }
  339. const String& Font::getFallbackFontStyle()
  340. {
  341. return FontValues::fallbackFontStyle;
  342. }
  343. void Font::setFallbackFontStyle (const String& style)
  344. {
  345. FontValues::fallbackFontStyle = style;
  346. #if JUCE_MAC || JUCE_IOS
  347. jassertfalse; // Note that use of a fallback font isn't currently implemented in OSX..
  348. #endif
  349. }
  350. //==============================================================================
  351. Font Font::withHeight (const float newHeight) const
  352. {
  353. Font f (*this);
  354. f.setHeight (newHeight);
  355. return f;
  356. }
  357. float Font::getHeightToPointsFactor() const
  358. {
  359. return getTypeface()->getHeightToPointsFactor();
  360. }
  361. Font Font::withPointHeight (float heightInPoints) const
  362. {
  363. Font f (*this);
  364. f.setHeight (heightInPoints / getHeightToPointsFactor());
  365. return f;
  366. }
  367. void Font::setHeight (float newHeight)
  368. {
  369. newHeight = FontValues::limitFontHeight (newHeight);
  370. if (font->height != newHeight)
  371. {
  372. dupeInternalIfShared();
  373. font->height = newHeight;
  374. checkTypefaceSuitability();
  375. }
  376. }
  377. void Font::setHeightWithoutChangingWidth (float newHeight)
  378. {
  379. newHeight = FontValues::limitFontHeight (newHeight);
  380. if (font->height != newHeight)
  381. {
  382. dupeInternalIfShared();
  383. font->horizontalScale *= (font->height / newHeight);
  384. font->height = newHeight;
  385. checkTypefaceSuitability();
  386. }
  387. }
  388. int Font::getStyleFlags() const noexcept
  389. {
  390. int styleFlags = font->underline ? underlined : plain;
  391. if (isBold()) styleFlags |= bold;
  392. if (isItalic()) styleFlags |= italic;
  393. return styleFlags;
  394. }
  395. Font Font::withStyle (const int newFlags) const
  396. {
  397. Font f (*this);
  398. f.setStyleFlags (newFlags);
  399. return f;
  400. }
  401. void Font::setStyleFlags (const int newFlags)
  402. {
  403. if (getStyleFlags() != newFlags)
  404. {
  405. dupeInternalIfShared();
  406. font->typeface = nullptr;
  407. font->typefaceStyle = FontStyleHelpers::getStyleName (newFlags);
  408. font->underline = (newFlags & underlined) != 0;
  409. font->ascent = 0;
  410. }
  411. }
  412. void Font::setSizeAndStyle (float newHeight,
  413. const int newStyleFlags,
  414. const float newHorizontalScale,
  415. const float newKerningAmount)
  416. {
  417. newHeight = FontValues::limitFontHeight (newHeight);
  418. if (font->height != newHeight
  419. || font->horizontalScale != newHorizontalScale
  420. || font->kerning != newKerningAmount)
  421. {
  422. dupeInternalIfShared();
  423. font->height = newHeight;
  424. font->horizontalScale = newHorizontalScale;
  425. font->kerning = newKerningAmount;
  426. checkTypefaceSuitability();
  427. }
  428. setStyleFlags (newStyleFlags);
  429. }
  430. void Font::setSizeAndStyle (float newHeight,
  431. const String& newStyle,
  432. const float newHorizontalScale,
  433. const float newKerningAmount)
  434. {
  435. newHeight = FontValues::limitFontHeight (newHeight);
  436. if (font->height != newHeight
  437. || font->horizontalScale != newHorizontalScale
  438. || font->kerning != newKerningAmount)
  439. {
  440. dupeInternalIfShared();
  441. font->height = newHeight;
  442. font->horizontalScale = newHorizontalScale;
  443. font->kerning = newKerningAmount;
  444. checkTypefaceSuitability();
  445. }
  446. setTypefaceStyle (newStyle);
  447. }
  448. Font Font::withHorizontalScale (const float newHorizontalScale) const
  449. {
  450. Font f (*this);
  451. f.setHorizontalScale (newHorizontalScale);
  452. return f;
  453. }
  454. void Font::setHorizontalScale (const float scaleFactor)
  455. {
  456. dupeInternalIfShared();
  457. font->horizontalScale = scaleFactor;
  458. checkTypefaceSuitability();
  459. }
  460. float Font::getHorizontalScale() const noexcept
  461. {
  462. return font->horizontalScale;
  463. }
  464. float Font::getExtraKerningFactor() const noexcept
  465. {
  466. return font->kerning;
  467. }
  468. Font Font::withExtraKerningFactor (const float extraKerning) const
  469. {
  470. Font f (*this);
  471. f.setExtraKerningFactor (extraKerning);
  472. return f;
  473. }
  474. void Font::setExtraKerningFactor (const float extraKerning)
  475. {
  476. dupeInternalIfShared();
  477. font->kerning = extraKerning;
  478. checkTypefaceSuitability();
  479. }
  480. Font Font::boldened() const { return withStyle (getStyleFlags() | bold); }
  481. Font Font::italicised() const { return withStyle (getStyleFlags() | italic); }
  482. bool Font::isBold() const noexcept { return FontStyleHelpers::isBold (font->typefaceStyle); }
  483. bool Font::isItalic() const noexcept { return FontStyleHelpers::isItalic (font->typefaceStyle); }
  484. bool Font::isUnderlined() const noexcept { return font->underline; }
  485. void Font::setBold (const bool shouldBeBold)
  486. {
  487. const int flags = getStyleFlags();
  488. setStyleFlags (shouldBeBold ? (flags | bold)
  489. : (flags & ~bold));
  490. }
  491. void Font::setItalic (const bool shouldBeItalic)
  492. {
  493. const int flags = getStyleFlags();
  494. setStyleFlags (shouldBeItalic ? (flags | italic)
  495. : (flags & ~italic));
  496. }
  497. void Font::setUnderline (const bool shouldBeUnderlined)
  498. {
  499. dupeInternalIfShared();
  500. font->underline = shouldBeUnderlined;
  501. checkTypefaceSuitability();
  502. }
  503. float Font::getAscent() const
  504. {
  505. if (font->ascent == 0)
  506. font->ascent = getTypeface()->getAscent();
  507. return font->height * font->ascent;
  508. }
  509. float Font::getHeight() const noexcept { return font->height; }
  510. float Font::getDescent() const { return font->height - getAscent(); }
  511. float Font::getHeightInPoints() const { return getHeight() * getHeightToPointsFactor(); }
  512. float Font::getAscentInPoints() const { return getAscent() * getHeightToPointsFactor(); }
  513. float Font::getDescentInPoints() const { return getDescent() * getHeightToPointsFactor(); }
  514. int Font::getStringWidth (const String& text) const
  515. {
  516. return (int) std::ceil (getStringWidthFloat (text));
  517. }
  518. float Font::getStringWidthFloat (const String& text) const
  519. {
  520. float w = getTypeface()->getStringWidth (text);
  521. if (font->kerning != 0)
  522. w += font->kerning * text.length();
  523. return w * font->height * font->horizontalScale;
  524. }
  525. void Font::getGlyphPositions (const String& text, Array<int>& glyphs, Array<float>& xOffsets) const
  526. {
  527. getTypeface()->getGlyphPositions (text, glyphs, xOffsets);
  528. const int num = xOffsets.size();
  529. if (num > 0)
  530. {
  531. const float scale = font->height * font->horizontalScale;
  532. float* const x = xOffsets.getRawDataPointer();
  533. if (font->kerning != 0)
  534. {
  535. for (int i = 0; i < num; ++i)
  536. x[i] = (x[i] + i * font->kerning) * scale;
  537. }
  538. else
  539. {
  540. for (int i = 0; i < num; ++i)
  541. x[i] *= scale;
  542. }
  543. }
  544. }
  545. void Font::findFonts (Array<Font>& destArray)
  546. {
  547. const StringArray names (findAllTypefaceNames());
  548. for (int i = 0; i < names.size(); ++i)
  549. {
  550. const StringArray styles (findAllTypefaceStyles (names[i]));
  551. String style ("Regular");
  552. if (! styles.contains (style, true))
  553. style = styles[0];
  554. destArray.add (Font (names[i], style, FontValues::defaultFontHeight));
  555. }
  556. }
  557. //==============================================================================
  558. String Font::toString() const
  559. {
  560. String s;
  561. if (getTypefaceName() != getDefaultSansSerifFontName())
  562. s << getTypefaceName() << "; ";
  563. s << String (getHeight(), 1);
  564. if (getTypefaceStyle() != getDefaultStyle())
  565. s << ' ' << getTypefaceStyle();
  566. return s;
  567. }
  568. Font Font::fromString (const String& fontDescription)
  569. {
  570. const int separator = fontDescription.indexOfChar (';');
  571. String name;
  572. if (separator > 0)
  573. name = fontDescription.substring (0, separator).trim();
  574. if (name.isEmpty())
  575. name = getDefaultSansSerifFontName();
  576. String sizeAndStyle (fontDescription.substring (separator + 1).trimStart());
  577. float height = sizeAndStyle.getFloatValue();
  578. if (height <= 0)
  579. height = 10.0f;
  580. const String style (sizeAndStyle.fromFirstOccurrenceOf (" ", false, false));
  581. return Font (name, style, height);
  582. }