From ec2d221b08850a8bf0378c4f763509a8df256bdb Mon Sep 17 00:00:00 2001 From: reuk Date: Thu, 29 Feb 2024 19:41:24 +0000 Subject: [PATCH] Font: Update return type of getOutlineForGlyph --- BREAKING_CHANGES.md | 18 ++++++++++++++++++ modules/juce_graphics/fonts/juce_Typeface.cpp | 7 +++---- modules/juce_graphics/fonts/juce_Typeface.h | 2 +- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/BREAKING_CHANGES.md b/BREAKING_CHANGES.md index d5951ea1d1..a45209f594 100644 --- a/BREAKING_CHANGES.md +++ b/BREAKING_CHANGES.md @@ -2,6 +2,24 @@ # Version 8.0.0 +## Change + +Typeface::getOutlineForGlyph now returns void instead of bool. + +**Possible Issues** + +Code that checks the result of this function will fail to compile. + +**Workaround** + +Omit any checks against the result of this function. + +**Rationale** + +This function can no longer fail. It may still output an empty path if the +requested glyph isn't present in the typeface. + + ## Change CustomTypeface has been removed. diff --git a/modules/juce_graphics/fonts/juce_Typeface.cpp b/modules/juce_graphics/fonts/juce_Typeface.cpp index 196cce087b..e5afacf04c 100644 --- a/modules/juce_graphics/fonts/juce_Typeface.cpp +++ b/modules/juce_graphics/fonts/juce_Typeface.cpp @@ -261,15 +261,13 @@ static Path getTypefaceGlyph (const Typeface& typeface, int glyphNumber) return result; } -bool Typeface::getOutlineForGlyph (int glyphNumber, Path& path) +void Typeface::getOutlineForGlyph (int glyphNumber, Path& path) { const auto metrics = getNativeDetails().getLegacyMetrics(); // getTypefaceGlyph returns glyphs in em space, getOutlineForGlyph returns glyphs in "special JUCE units" space path = getTypefaceGlyph (*this, glyphNumber); path.applyTransform (AffineTransform::scale (metrics.getHeightToPointsFactor())); - - return true; } void Typeface::applyVerticalHintingTransform (float, Path&) @@ -280,8 +278,9 @@ void Typeface::applyVerticalHintingTransform (float, Path&) EdgeTable* Typeface::getEdgeTableForGlyph (int glyphNumber, const AffineTransform& transform, float) { Path path; + getOutlineForGlyph (glyphNumber, path); - if (! getOutlineForGlyph (glyphNumber, path) || path.isEmpty()) + if (path.isEmpty()) return nullptr; return new EdgeTable (path.getBoundsTransformed (transform).getSmallestIntegerContainer().expanded (1, 0), diff --git a/modules/juce_graphics/fonts/juce_Typeface.h b/modules/juce_graphics/fonts/juce_Typeface.h index cbefde8fdf..626fd73227 100644 --- a/modules/juce_graphics/fonts/juce_Typeface.h +++ b/modules/juce_graphics/fonts/juce_Typeface.h @@ -164,7 +164,7 @@ public: /** Returns the outline for a glyph. The path returned will be normalised to a font height of 1.0. */ - bool getOutlineForGlyph (int glyphNumber, Path& path); + void getOutlineForGlyph (int glyphNumber, Path& path); /** Returns a new EdgeTable that contains the path for the given glyph, with the specified transform applied. */ EdgeTable* getEdgeTableForGlyph (int glyphNumber, const AffineTransform& transform, float fontHeight);