адаптация s13bby/osc под vst и gui. (вайбкод)

вайбкод потому что мне в моменте стало понятно. что проще было сразу писать на фреймворке JUCE, чем адаптировать консольное приложение на MiniAudio.
обновляться данный репозиторий не будет. СmakeLists адаптирован онли под linux.
This commit is contained in:
2026-11-20 14:52:33 +06:00
parent 8384123f87
commit b0a75e98db
10387 changed files with 4025195 additions and 0 deletions
@@ -0,0 +1,621 @@
/*
==============================================================================
This file is part of the JUCE framework.
Copyright (c) Raw Material Software Limited
JUCE is an open source framework subject to commercial or open source
licensing.
By downloading, installing, or using the JUCE framework, or combining the
JUCE framework with any other source code, object code, content or any other
copyrightable work, you agree to the terms of the JUCE End User Licence
Agreement, and all incorporated terms including the JUCE Privacy Policy and
the JUCE Website Terms of Service, as applicable, which will bind you. If you
do not agree to the terms of these agreements, we will not license the JUCE
framework to you, and you must discontinue the installation or download
process and cease use of the JUCE framework.
JUCE End User Licence Agreement: https://juce.com/legal/juce-9-licence/
JUCE Privacy Policy: https://juce.com/juce-privacy-policy
JUCE Website Terms of Service: https://juce.com/juce-website-terms-of-service/
Or:
You may also use this code under the terms of the AGPLv3:
https://www.gnu.org/licenses/agpl-3.0.en.html
THE JUCE FRAMEWORK IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL
WARRANTIES, WHETHER EXPRESSED OR IMPLIED, INCLUDING WARRANTY OF
MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, ARE DISCLAIMED.
==============================================================================
*/
namespace juce::detail
{
void drawJustifiedText (const JustifiedText& text, const Graphics& g, AffineTransform);
//==============================================================================
static constexpr auto maxWidthTolerance = 0.005f;
static int64 getNumLeadingWhitespaces (Span<const ShapedGlyph> glyphs)
{
const auto it = std::find_if_not (glyphs.begin(),
glyphs.end(),
[&] (const auto& g) { return g.isWhitespace(); });
return (int64) std::distance (glyphs.begin(), it);
}
static int64 getNumTrailingWhitespaces (Span<const ShapedGlyph> glyphs)
{
if (glyphs.empty())
return 0;
int64 trailingWhitespaces = 0;
for (auto it = glyphs.end(); --it >= glyphs.begin() && it->isWhitespace();)
++trailingWhitespaces;
return trailingWhitespaces;
}
struct NumWhitespaces
{
int64 total{}, leading{}, trailing{};
};
static NumWhitespaces getNumWhitespaces (Span<const ShapedGlyph> glyphs)
{
const auto total = std::count_if (glyphs.begin(),
glyphs.end(),
[] (const auto& g) { return g.isWhitespace(); });
return { total, getNumLeadingWhitespaces (glyphs), getNumTrailingWhitespaces (glyphs) };
}
struct LineLength
{
float total{}, withoutTrailingWhitespaces{};
};
static LineLength getMainAxisLineLength (Span<const ShapedGlyph> glyphs)
{
const auto total = std::accumulate (glyphs.begin(),
glyphs.end(),
0.0f,
[] (auto acc, const auto& g) { return acc + g.advance.getX(); });
auto trailingWhitespacesLength = 0.0f;
if (glyphs.empty())
return {};
for (auto it = glyphs.end(); --it >= glyphs.begin() && it->isWhitespace();)
trailingWhitespacesLength += it->advance.getX();
return { total, total - trailingWhitespacesLength };
}
static float getMainAxisLineLength (Span<const ShapedGlyph> glyphs, bool trailingWhitespacesShouldFit)
{
const auto lengths = getMainAxisLineLength (glyphs);
return trailingWhitespacesShouldFit ? lengths.total : lengths.withoutTrailingWhitespaces;
}
struct MainAxisLineAlignment
{
float anchor{}, extraWhitespaceAdvance{}, effectiveLineLength{};
Range<int64> stretchableWhitespaces;
};
static MainAxisLineAlignment getMainAxisLineAlignment (Justification justification,
Span<const ShapedGlyph> glyphs,
LineLength lineLength,
std::optional<float> maxWidthOpt,
std::optional<float> alignmentWidthOpt,
bool trailingWhitespacesShouldFit)
{
const auto effectiveLineLength = (trailingWhitespacesShouldFit ? lineLength.total
: lineLength.withoutTrailingWhitespaces);
const auto alignmentWidth = alignmentWidthOpt.value_or (maxWidthOpt.value_or (0.0f));
const auto tooLong = alignmentWidth + maxWidthTolerance < effectiveLineLength;
MainAxisLineAlignment result;
result.effectiveLineLength = effectiveLineLength;
// The alignment width opt is supporting the TextEditor use-case where all text remains visible
// with scrolling, even if longer than the alignment width. We don't need to worry about the
// front of and RTL text being visually truncated, because nothing is truncated.
if (tooLong && alignmentWidthOpt.has_value())
return result;
const auto mainAxisLineOffset = [&]
{
if (tooLong)
{
const auto approximateIsLeftToRight = [&]
{
if (glyphs.empty())
return true;
return glyphs.front().cluster <= glyphs.back().cluster;
}();
// We don't have to align LTR text, but we need to ensure that it's the logical back of
// RTL text that falls outside the bounds.
if (approximateIsLeftToRight)
return 0.0f;
return alignmentWidth - effectiveLineLength;
}
if (justification.testFlags (Justification::horizontallyCentred))
{
return (alignmentWidth - lineLength.withoutTrailingWhitespaces) / 2.0f;
}
if (justification.testFlags (Justification::right))
return alignmentWidth - effectiveLineLength;
return 0.0f;
}();
const auto numWhitespaces = getNumWhitespaces (glyphs);
const auto stretchableWhitespaces = [&]() -> Range<int64>
{
if (! justification.testFlags (Justification::horizontallyJustified) || tooLong)
return {};
return { numWhitespaces.leading, (int64) glyphs.size() - numWhitespaces.trailing };
}();
const auto extraWhitespaceAdvance = [&]
{
if (! justification.testFlags (Justification::horizontallyJustified) || tooLong)
return 0.0f;
const auto numWhitespacesBetweenWords = numWhitespaces.total
- numWhitespaces.leading
- numWhitespaces.trailing;
return numWhitespacesBetweenWords > 0 ? (alignmentWidth - effectiveLineLength) / (float) numWhitespacesBetweenWords
: 0.0f;
}();
return { mainAxisLineOffset, extraWhitespaceAdvance, effectiveLineLength, stretchableWhitespaces };
}
struct LineInfo
{
float lineHeight{}, maxAscent{};
MainAxisLineAlignment mainAxisLineAlignment;
};
static float getCrossAxisStartingAnchor (Justification justification,
Span<const LineInfo> lineInfos,
std::optional<float> height,
float leading)
{
if (lineInfos.empty())
return 0.0f;
const auto minimumTop = lineInfos.front().maxAscent * leading;
if (! height.has_value())
return minimumTop;
const auto textHeight = std::accumulate (lineInfos.begin(),
lineInfos.end(),
0.0f,
[leading] (auto acc, const auto info) { return acc + info.lineHeight * leading; });
if (justification.testFlags (Justification::verticallyCentred))
return (*height - textHeight) / 2.0f + lineInfos.front().maxAscent;
if (justification.testFlags (Justification::bottom))
{
return *height - textHeight + lineInfos.front().maxAscent * leading;
}
return minimumTop;
}
JustifiedText::JustifiedText (const SimpleShapedText* t, const ShapedTextOptions& options)
: shapedText (*t)
{
std::vector<LineInfo> lineInfos;
for (const auto [range, lineNumber] : shapedText.getLineNumbersForGlyphRanges())
{
// This is guaranteed by the RangedValues implementation. You can't assign a value to an
// empty range.
jassert (! range.isEmpty());
const auto fonts = shapedText.getResolvedFonts().getIntersectionsWith (range);
const auto lineHeight = std::accumulate (fonts.begin(),
fonts.end(),
0.0f,
[] (auto acc, const auto& rangedFont)
{ return std::max (acc, rangedFont.value.getHeight()); });
const auto maxAscent = std::accumulate (fonts.begin(),
fonts.end(),
0.0f,
[] (auto acc, const auto& rangedFont)
{ return std::max (acc, rangedFont.value.getAscent()); });
const auto glyphs = shapedText.getGlyphs (range);
const auto lineLength = getMainAxisLineLength (glyphs);
auto m = [&]
{
return getMainAxisLineAlignment (options.getJustification(),
glyphs,
lineLength,
options.getWordWrapWidth(),
options.getAlignmentWidth(),
options.getTrailingWhitespacesShouldFit());
}();
const auto containsHardBreak = shapedText.getCodepoint (range.getEnd() - 1) == 0xa
|| shapedText.getCodepoint (range.getStart()) == 0xa;
if (containsHardBreak || lineNumber == shapedText.getLineNumbersForGlyphRanges().back().value)
{
m.extraWhitespaceAdvance = {};
m.stretchableWhitespaces = {};
}
lineInfos.push_back ({ lineHeight, maxAscent, std::move (m) });
minimumRequiredWidthsForLine.push_back (options.getTrailingWhitespacesShouldFit() ? lineLength.total
: lineLength.withoutTrailingWhitespaces);
}
auto baseline = options.isBaselineAtZero() ? 0.0f
: getCrossAxisStartingAnchor (options.getJustification(),
lineInfos,
options.getHeight(),
options.getLeading());
detail::Ranges::Operations ops;
std::optional<float> top;
for (const auto [lineIndex, lineInfo] : enumerate (lineInfos))
{
const auto lineNumber = shapedText.getLineNumbersForGlyphRanges().getItem ((size_t) lineIndex);
const auto range = lineNumber.range;
const auto maxDescent = lineInfo.lineHeight - lineInfo.maxAscent;
const auto nextLineTop = baseline + options.getLeading() * maxDescent + options.getAdditiveLineSpacing();
if (! top.has_value())
top = baseline - options.getLeading() * lineInfo.maxAscent;
lineMetricsForGlyphRange.set (range,
{ lineNumber.value,
{ lineInfo.mainAxisLineAlignment.anchor, baseline },
lineInfo.maxAscent * options.getLeading(),
(lineInfo.lineHeight - lineInfo.maxAscent) * options.getLeading(),
lineInfo.mainAxisLineAlignment.effectiveLineLength
+ lineInfo.mainAxisLineAlignment.extraWhitespaceAdvance,
*top,
nextLineTop },
ops,
MergeEqualItemsNo{});
whitespaceStretch.set (range, 0.0f, ops);
const auto stretchRange = lineInfo.mainAxisLineAlignment.stretchableWhitespaces + range.getStart();
whitespaceStretch.set (stretchRange,
lineInfo.mainAxisLineAlignment.extraWhitespaceAdvance,
ops);
ops.clear();
const auto nextLineMaxAscent = lineIndex < (int) lineInfos.size() - 1 ? lineInfos[(size_t) lineIndex + 1].maxAscent : 0.0f;
baseline = nextLineTop + options.getLeading() * nextLineMaxAscent;
top = nextLineTop;
}
rangesToDraw.set ({ 0, (int64) shapedText.getGlyphs().size() }, DrawType::normal, ops);
if (options.getDrawLinesInFull())
return;
//==============================================================================
// Everything above this line should work well given none of the lines were too
// long. When Options::getMaxNumLines() == 0 this is guaranteed by SimpleShapedText.
// The remaining logic below is for supporting
// GlyphArrangement::addFittedText() when the maximum number of lines is
// constrained.
if (lineMetricsForGlyphRange.isEmpty())
return;
const auto lastLineMetrics = lineMetricsForGlyphRange.back();
const auto lastLineGlyphRange = lastLineMetrics.range;
const auto lastLineGlyphs = shapedText.getGlyphs (lastLineGlyphRange);
const auto lastLineLengths = getMainAxisLineLength (lastLineGlyphs);
const auto effectiveLength = options.getTrailingWhitespacesShouldFit() ? lastLineLengths.total
: lastLineLengths.withoutTrailingWhitespaces;
if (! options.getWordWrapWidth().has_value()
|| effectiveLength <= *options.getWordWrapWidth() + maxWidthTolerance)
return;
const auto cutoffAtFront = lastLineMetrics.value.anchor.getX() < 0.0f - maxWidthTolerance;
const auto getLastLineVisibleRange = [&] (float ellipsisLength)
{
const auto r = [&]() -> Range<int64>
{
if (cutoffAtFront)
{
auto length = lastLineLengths.total;
for (auto it = lastLineGlyphs.begin(); it < lastLineGlyphs.end(); ++it)
{
length -= it->advance.getX();
if (! options.getWordWrapWidth().has_value()
|| *options.getWordWrapWidth() >= ellipsisLength + length)
{
return { (int64) std::distance (lastLineGlyphs.begin(), it) + 1,
(int64) lastLineGlyphs.size() };
}
}
}
else
{
auto length = lastLineLengths.total;
for (auto it = lastLineGlyphs.end() - 1; it >= lastLineGlyphs.begin(); --it)
{
length -= it->advance.getX();
if (! options.getWordWrapWidth().has_value()
|| *options.getWordWrapWidth() >= ellipsisLength + length)
{
return { 0, (int64) std::distance (lastLineGlyphs.begin(), it) };
}
}
}
return {};
}();
return r.movedToStartAt (r.getStart() + lastLineGlyphRange.getStart());
};
const auto lastLineVisibleRangeWithoutEllipsis = getLastLineVisibleRange (0.0f);
const auto eraseLastLineFromRangesToDraw = [&]
{
rangesToDraw.eraseFrom (lastLineGlyphRange.getStart(), ops);
ops.clear();
};
eraseLastLineFromRangesToDraw();
rangesToDraw.set (lastLineVisibleRangeWithoutEllipsis, DrawType::normal, ops);
ops.clear();
if (options.getEllipsis().isEmpty())
{
return;
}
//==============================================================================
// More logic supporting using ellipses
const auto fontForEllipsis = [&]
{
const auto lastLineFonts = shapedText.getResolvedFonts().getIntersectionsWith (lastLineGlyphRange);
if (cutoffAtFront)
return lastLineFonts.front().value;
return lastLineFonts.back().value;
}();
ellipsis.emplace (&options.getEllipsis(), ShapedTextOptions {}.withFont (fontForEllipsis));
const auto lastLineVisibleRange = getLastLineVisibleRange (getMainAxisLineLength (ellipsis->getGlyphs(),
options.getTrailingWhitespacesShouldFit()));
eraseLastLineFromRangesToDraw();
rangesToDraw.set (lastLineVisibleRange, DrawType::normal, ops);
ops.clear();
if (cutoffAtFront)
rangesToDraw.set (Range<int64>::withStartAndLength (lastLineVisibleRange.getStart() - 1, 1), DrawType::ellipsis, ops);
else
rangesToDraw.set (Range<int64>::withStartAndLength (lastLineVisibleRange.getEnd(), 1), DrawType::ellipsis, ops);
ops.clear();
const auto lineWithEllipsisGlyphs = [&]
{
std::vector<ShapedGlyph> result;
const auto pushEllipsisGlyphs = [&]
{
const auto& range = ellipsis->getGlyphs();
result.insert (result.begin(), range.begin(), range.end());
};
if (cutoffAtFront)
pushEllipsisGlyphs();
const auto& range = shapedText.getGlyphs (lastLineVisibleRange);
result.insert (result.end(), range.begin(), range.end());
if (! cutoffAtFront)
pushEllipsisGlyphs();
return result;
}();
const auto realign = [&]
{
return getMainAxisLineAlignment (options.getJustification(),
lineWithEllipsisGlyphs,
getMainAxisLineLength (lineWithEllipsisGlyphs),
options.getWordWrapWidth(),
options.getAlignmentWidth(),
options.getTrailingWhitespacesShouldFit());
}();
lastLineMetrics.value.anchor.setX (realign.anchor);
whitespaceStretch.set (lastLineGlyphRange, 0.0f, ops);
whitespaceStretch.set (realign.stretchableWhitespaces + lastLineVisibleRange.getStart(),
realign.extraWhitespaceAdvance, ops);
}
int64 JustifiedText::getGlyphIndexToTheRightOf (Point<float> p) const
{
auto lineIt = lineMetricsForGlyphRange.begin();
float lineTop = 0.0f;
while (lineIt != lineMetricsForGlyphRange.end())
{
const auto nextLineTop = lineIt->value.nextLineTop;
if (lineTop <= p.getY() && p.getY() < nextLineTop)
break;
lineTop = nextLineTop;
++lineIt;
}
if (lineIt == lineMetricsForGlyphRange.end())
return 0;
const auto glyphsInLine = shapedText.getGlyphs (lineIt->range);
auto glyphX = lineIt->value.anchor.getX();
for (const auto [glyphIndex, glyph] : enumerate (glyphsInLine, lineIt->range.getStart()))
{
if (p.getX() < glyphX + glyph.advance.getX() / 2.0f || glyph.isNewline())
return glyphIndex;
glyphX += glyph.advance.getX();
}
return lineIt->range.getEnd();
}
GlyphAnchorResult JustifiedText::getGlyphAnchor (int64 index) const
{
jassert (index >= 0);
if (lineMetricsForGlyphRange.isEmpty())
return {};
const auto lineItem = lineMetricsForGlyphRange.getItemWithEnclosingRange (index)
.value_or (lineMetricsForGlyphRange.back());
const auto indexInLine = index - lineItem.range.getStart();
GlyphAnchorResult anchor { lineItem.value.anchor, lineItem.value.maxAscent, lineItem.value.maxDescent };
for (auto [i, glyph] : enumerate (shapedText.getGlyphs (lineItem.range), int64{}))
{
if (i == indexInLine)
{
anchor.anchor += glyph.offset;
return anchor;
}
anchor.anchor += glyph.advance;
}
return anchor;
}
RectangleList<float> JustifiedText::getGlyphsBounds (Range<int64> glyphRange) const
{
RectangleList<float> bounds;
if (lineMetricsForGlyphRange.isEmpty())
return bounds;
const auto getBounds = [&] (const LineMetrics& line, int64 lineStart, int64 boundsStart, int64 boundsEnd) -> Rectangle<float>
{
const auto glyphsBefore = shapedText.getGlyphs ({ lineStart, boundsStart });
const auto xStart = std::accumulate (glyphsBefore.begin(),
glyphsBefore.end(),
line.anchor.getX(),
[] (auto sum, auto glyph)
{
return sum + glyph.advance.getX();
});
const auto glyphs = shapedText.getGlyphs ({ boundsStart, boundsEnd });
const auto xEnd = std::accumulate (glyphs.begin(),
glyphs.end(),
xStart,
[&] (auto sum, auto glyph)
{
return sum + glyph.advance.getX();
});
return { { xStart, line.top }, { xEnd, line.nextLineTop } };
};
for (auto consumeFrom = glyphRange.getStart(); consumeFrom < glyphRange.getEnd();)
{
const auto lineItem = lineMetricsForGlyphRange.getItemWithEnclosingRange (consumeFrom);
if (! lineItem.has_value())
break;
const auto consumeTo = std::min (glyphRange.getEnd(), lineItem->range.getEnd());
bounds.add (getBounds (lineItem->value, lineItem->range.getStart(), consumeFrom, consumeTo));
consumeFrom = consumeTo;
}
return bounds;
}
float JustifiedText::getHeight() const
{
if (lineMetricsForGlyphRange.isEmpty())
return 0.0f;
return lineMetricsForGlyphRange.back().value.nextLineTop;
}
void drawJustifiedText (const JustifiedText& text, const Graphics& g, AffineTransform transform)
{
auto& context = g.getInternalContext();
context.saveState();
const ScopeGuard restoreGraphicsContext { [&context] { context.restoreState(); } };
text.accessTogetherWith ([&] (auto glyphs, auto positions, auto font, auto, auto)
{
if (context.getFont() != font)
context.setFont (font);
std::vector<uint16_t> glyphIds (glyphs.size());
std::transform (glyphs.begin(),
glyphs.end(),
glyphIds.begin(),
[] (auto& glyph) { return (uint16_t) glyph.glyphId; });
context.drawGlyphs (glyphIds, positions, transform);
});
}
} // namespace juce::detail
@@ -0,0 +1,233 @@
/*
==============================================================================
This file is part of the JUCE framework.
Copyright (c) Raw Material Software Limited
JUCE is an open source framework subject to commercial or open source
licensing.
By downloading, installing, or using the JUCE framework, or combining the
JUCE framework with any other source code, object code, content or any other
copyrightable work, you agree to the terms of the JUCE End User Licence
Agreement, and all incorporated terms including the JUCE Privacy Policy and
the JUCE Website Terms of Service, as applicable, which will bind you. If you
do not agree to the terms of these agreements, we will not license the JUCE
framework to you, and you must discontinue the installation or download
process and cease use of the JUCE framework.
JUCE End User Licence Agreement: https://juce.com/legal/juce-9-licence/
JUCE Privacy Policy: https://juce.com/juce-privacy-policy
JUCE Website Terms of Service: https://juce.com/juce-website-terms-of-service/
Or:
You may also use this code under the terms of the AGPLv3:
https://www.gnu.org/licenses/agpl-3.0.en.html
THE JUCE FRAMEWORK IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL
WARRANTIES, WHETHER EXPRESSED OR IMPLIED, INCLUDING WARRANTY OF
MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, ARE DISCLAIMED.
==============================================================================
*/
namespace juce::detail
{
template <size_t StartingAt, typename Tuple, size_t... Is>
constexpr auto partiallyUnpackImpl (Tuple&& tuple, std::index_sequence<Is...>)
{
return std::tie (std::get<StartingAt + Is> (tuple)...);
}
template <size_t StartingAt, size_t NumElems, typename Tuple>
constexpr auto partiallyUnpack (Tuple&& tuple)
{
return partiallyUnpackImpl<StartingAt> (std::forward<Tuple> (tuple), std::make_index_sequence<NumElems>{});
}
//==============================================================================
struct LineMetrics
{
int64 lineNumber;
Point<float> anchor;
float maxAscent;
float maxDescent;
/* Effective suggests the length of trailing whitespaces will be included or not depending on
ShapedTextOptions::getTrailingWhitespacesShouldFit().
*/
float effectiveLineLength;
/* These values seem redundant given the relation between the baseline, ascent and top, but
we want to ensure exactlyEquals (top, nextLineTop) for subsequent lines.
*/
float top;
/* This will be below the current line's visual bottom if non-default leading or additive
line spacing is used.
*/
float nextLineTop;
};
struct GlyphAnchorResult
{
Point<float> anchor;
float maxAscent{};
float maxDescent{};
};
//==============================================================================
class JustifiedText
{
private:
enum class DrawType
{
normal,
ellipsis
};
public:
JustifiedText (const SimpleShapedText* t, const ShapedTextOptions& options);
/* Provides access to the data stored in the ShapedText.
The provided callable will be called multiple times for "uniform glyph runs", for which all
callback parameters are the same.
Between each subsequent callback at least one of the provided parameters will be different.
The callbacks happen in visual order i.e. left to right, which is irrespective of the
underlying text's writing direction.
The callback parameters in order are:
- the glyphs
- the positions for each glyph in the previous parameter
- the Font with which these glyphs should be rendered
- the range in all glyphs this ShapedText object holds, that correspond to the current glyphs
- a line number which increases by one for each new line
- followed by any number of ValueType parameters for the supplied RangedValues<ValueType> arguments
*/
template <typename Callable, typename... RangedValues>
void accessTogetherWith (Callable&& callback, RangedValues&&... rangedValues) const
{
std::optional<int64> lastLine;
int64 lastGlyph = 0;
Point<float> anchor {};
for (const auto item : makeIntersectingRangedValues (&shapedText.getResolvedFonts(),
&lineMetricsForGlyphRange,
&rangesToDraw,
&whitespaceStretch,
(&rangedValues)...))
{
const auto& [range, font, lineMetrics, drawType, stretch] = partiallyUnpack<0, 5> (item);
const auto& rest = partiallyUnpack<5, std::tuple_size_v<decltype (item)> - 5> (item);
if (std::exchange (lastLine, lineMetrics.lineNumber) != lineMetrics.lineNumber)
anchor = lineMetrics.anchor;
if (range.getStart() != lastGlyph && drawType != DrawType::ellipsis)
{
detail::RangedValues<int8_t> glyphMask;
Ranges::Operations ops;
const auto firstGlyphInCurrentLine = shapedText.getLineNumbersForGlyphRanges().getItem ((size_t) lineMetrics.lineNumber)
.range
.getStart();
glyphMask.set ({ std::max (lastGlyph, firstGlyphInCurrentLine), range.getStart() }, 1, ops);
for (const auto [skippedRange, skippedStretch, _] : makeIntersectingRangedValues (&whitespaceStretch,
&glyphMask))
{
ignoreUnused (_);
for (const auto& skippedGlyph : shapedText.getGlyphs (skippedRange))
{
anchor += skippedGlyph.advance;
if (skippedGlyph.isWhitespace())
anchor.addXY (skippedStretch, 0.0f);
}
}
}
lastGlyph = range.getEnd();
const auto glyphs = [this, r = range, dt = drawType]() -> Span<const ShapedGlyph>
{
if (dt == DrawType::ellipsis)
return ellipsis->getGlyphs();
return shapedText.getGlyphs (r);
}();
std::vector<Point<float>> positions (glyphs.size());
std::transform (glyphs.begin(),
glyphs.end(),
positions.begin(),
[&anchor, &s = stretch] (auto& glyph)
{
auto result = anchor + glyph.offset;
anchor += glyph.advance;
if (glyph.isWhitespace())
anchor.addXY (s, 0.0f);
return result;
});
const auto callbackFont =
drawType == DrawType::ellipsis ? ellipsis->getResolvedFonts().front().value : font;
const auto callbackParameters =
std::tuple_cat (std::tie (glyphs, positions, callbackFont, range, lineMetrics), rest);
const auto invokeNullChecked = [&] (auto&... params)
{ NullCheckedInvocation::invoke (callback, params...); };
std::apply (invokeNullChecked, callbackParameters);
}
}
/* This is how much cumulative widths glyphs take up in each line. Whether the trailing
whitespace is included depends on the ShapedTextOptions::getWhitespaceShouldFitInLine()
setting.
*/
auto& getMinimumRequiredWidthForLines() const { return minimumRequiredWidthsForLine; }
int64 getGlyphIndexToTheRightOf (Point<float> p) const;
/* If the passed in index parameter is greater than the index of the last contained glyph,
then the returned anchor specifies the location where the next glyph would have to be
placed i.e. lastGlyphAnchor + lastGlyphAdvance.
*/
GlyphAnchorResult getGlyphAnchor (int64 glyphIndex) const;
RectangleList<float> getGlyphsBounds (Range<int64> glyphRange) const;
/* Returns the vertical distance from the baseline of the first line to the bottom of the last
plus any additional line spacing that follows from the leading and additiveLineSpacing
members of the ShapedTextOptions object.
This guarantees that if ShapedText object1 is drawn at y = 0 and object2 is drawn at
y = object1.getHeight(), then the two texts will be spaced exactly as if they were a single
ShapedText object containing both texts.
*/
float getHeight() const;
const auto& getLineMetricsForGlyphRange() const { return lineMetricsForGlyphRange; }
private:
const SimpleShapedText& shapedText;
detail::RangedValues<LineMetrics> lineMetricsForGlyphRange;
std::optional<SimpleShapedText> ellipsis;
detail::RangedValues<DrawType> rangesToDraw;
detail::RangedValues<float> whitespaceStretch;
std::vector<float> minimumRequiredWidthsForLine;
};
} // namespace juce::detail
@@ -0,0 +1,175 @@
/*
==============================================================================
This file is part of the JUCE framework.
Copyright (c) Raw Material Software Limited
JUCE is an open source framework subject to commercial or open source
licensing.
By downloading, installing, or using the JUCE framework, or combining the
JUCE framework with any other source code, object code, content or any other
copyrightable work, you agree to the terms of the JUCE End User Licence
Agreement, and all incorporated terms including the JUCE Privacy Policy and
the JUCE Website Terms of Service, as applicable, which will bind you. If you
do not agree to the terms of these agreements, we will not license the JUCE
framework to you, and you must discontinue the installation or download
process and cease use of the JUCE framework.
JUCE End User Licence Agreement: https://juce.com/legal/juce-9-licence/
JUCE Privacy Policy: https://juce.com/juce-privacy-policy
JUCE Website Terms of Service: https://juce.com/juce-website-terms-of-service/
Or:
You may also use this code under the terms of the AGPLv3:
https://www.gnu.org/licenses/agpl-3.0.en.html
THE JUCE FRAMEWORK IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL
WARRANTIES, WHETHER EXPRESSED OR IMPLIED, INCLUDING WARRANTY OF
MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, ARE DISCLAIMED.
==============================================================================
*/
namespace juce::detail
{
/* Very nearly a drop in replacement for lunasvg::Font. This allows us to bypass lunasvg's Font
rendering and plug in JUCE's Font related functionality.
*/
class LunaSvgFontReplacement
{
public:
LunaSvgFontReplacement() = default;
LunaSvgFontReplacement (float size, const std::string& family, bool bold, bool italic)
{
const auto getStyleFlags = [] (const bool b, const bool i) noexcept
{
int flags{};
if (b) flags |= Font::bold;
if (i) flags |= Font::italic;
return flags;
};
font = std::invoke (
[&]
{
juce::StringArray tokens;
tokens.addTokens (family, ",", "");
std::vector<String> fallbacks ((size_t) tokens.size());
std::transform (tokens.begin(),
tokens.end(),
fallbacks.begin(),
[] (const String& s) { return s.trim(); });
auto options = FontOptions{}.withPointHeight (size)
.withFallbacks (fallbacks)
.withStyleFlags (getStyleFlags (bold, italic));
if (! fallbacks.empty())
options = options.withName (fallbacks[0]);
return Font { options };
});
GlyphArrangement arr;
arr.addLineOfText (*font, "x", 0.0f, 0.0f);
fontXHeight = std::invoke ([&]
{
if (arr.getNumGlyphs() == 0)
return font->getHeight();
auto typefacePtr = font->getTypefacePtr();
if (typefacePtr == nullptr)
return 0.0f;
const auto xBoundsNormalised = typefacePtr->getGlyphBounds (arr.getGlyph (0).getGlyphIndex());
return xBoundsNormalised.getHeight() * font->getHeightInPoints();
});
}
float ascent() const
{
if (! font.has_value())
return 0.0f;
return font->getAscentInPoints();
}
float descent() const
{
if (! font.has_value())
return 0.0f;
return font->getDescentInPoints();
}
float height() const
{
if (! font.has_value())
return 0.0f;
// This is a little strange. Checking the numerical values inside lunasvg, we need to return
// the font height, NOT the point height. But fontXHeight needs to be calculated using the
// point height. This way we get the same text layout as in lunasvg. But the mix of the two
// values is perplexing.
return font->getHeight();
}
float lineGap() const
{
if (! font.has_value())
return 0.0f;
return font->getLineGapInPoints();
}
float xHeight() const
{
return fontXHeight;
}
float measureText (const std::u32string_view& text) const
{
if (! font.has_value())
return 0.0f;
const auto s = juce::String { juce::CharPointer_UTF32 (reinterpret_cast<const CharPointer_UTF32::CharType*> (text.data())),
text.length() };
return GlyphArrangement::getStringWidth (*font, s);
}
float size() const
{
if (! font.has_value())
return 0.0f;
return font->getHeightInPoints();
}
bool isNull() const
{
if (! font.has_value())
return 0.0f;
return ! font.has_value();
}
const Font& getFont() const
{
return *font;
}
private:
std::optional<Font> font;
float fontXHeight = 0.0f;
};
} // namespace juce::detail
@@ -0,0 +1,871 @@
/*
==============================================================================
This file is part of the JUCE framework.
Copyright (c) Raw Material Software Limited
JUCE is an open source framework subject to commercial or open source
licensing.
By downloading, installing, or using the JUCE framework, or combining the
JUCE framework with any other source code, object code, content or any other
copyrightable work, you agree to the terms of the JUCE End User Licence
Agreement, and all incorporated terms including the JUCE Privacy Policy and
the JUCE Website Terms of Service, as applicable, which will bind you. If you
do not agree to the terms of these agreements, we will not license the JUCE
framework to you, and you must discontinue the installation or download
process and cease use of the JUCE framework.
JUCE End User Licence Agreement: https://juce.com/legal/juce-9-licence/
JUCE Privacy Policy: https://juce.com/juce-privacy-policy
JUCE Website Terms of Service: https://juce.com/juce-website-terms-of-service/
Or:
You may also use this code under the terms of the AGPLv3:
https://www.gnu.org/licenses/agpl-3.0.en.html
THE JUCE FRAMEWORK IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL
WARRANTIES, WHETHER EXPRESSED OR IMPLIED, INCLUDING WARRANTY OF
MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, ARE DISCLAIMED.
==============================================================================
*/
namespace juce::detail
{
#if JUCE_UNIT_TESTS
template <typename T, typename = void>
constexpr auto hasGetStartFunction = false;
template <typename T>
constexpr auto hasGetStartFunction<T, std::void_t<decltype (std::declval<T>().getStart())>> = true;
template <typename RangeType, typename std::enable_if<hasGetStartFunction<RangeType>, int>::type = 0>
std::ostream& operator<< (std::ostream& os, const RangeType& range)
{
os << "[" << range.getStart() << ", " << range.getEnd() << ")";
return os;
}
static String& operator<< (String& s, Range<int64> r)
{
return s += "[" + String { r.getStart() } + ", " + String { r.getEnd() } + ")";
}
template <typename ValueType>
static auto getCumulativeRangeLengths (const RangedValues<ValueType>& rv)
{
int64 totalLength{};
for (size_t i = 0; i < rv.size(); ++i)
totalLength += rv.getItem (i).range.getLength();
return totalLength;
}
template <typename ValueType>
static auto toString (const RangedValues<ValueType>& rv)
{
String s {};
for (size_t i = 0; i < rv.size(); ++i)
{
auto item = rv.getItem (i);
s << item.range << ": " << item.value << "\n";
}
return s;
}
class RangesTestsBase : public UnitTest
{
public:
using UnitTest::UnitTest;
void expectRange (Range<int64> actual, Range<int64> expected)
{
String failureMessage { "range " };
failureMessage << actual << " did not equal expected range " << expected;
expect (actual == expected, failureMessage);
}
};
class RangesTests : public RangesTestsBase
{
public:
RangesTests() : RangesTestsBase ("Ranges", UnitTestCategories::containers) {}
void runTest() override
{
Ranges::Operations ops;
beginTest ("Ranges::set() - basics");
{
Ranges ranges;
ranges.set ({ -3, 14 }, ops);
expectRange (ranges.get (0), { -3, 14 });
ranges.set ({ 7, 20 }, ops);
expectRange (ranges.get (0), { -3, 7 });
expectRange (ranges.get (1), { 7, 20 });
}
beginTest ("Ranges::set() - neighbouring ranges extents are modified");
{
Ranges ranges;
ranges.set ({ -3, 14 }, ops);
ranges.set ({ 19, 30 }, ops);
ranges.set ({ 10, 25 }, ops);
// size_t doesn't always map to an existing overload for String::operator<< on all platforms
expectEquals ((int64) ranges.size(), (int64) 3);
expectRange (ranges.get (0), { -3, 10 });
expectRange (ranges.get (1), { 10, 25 });
expectRange (ranges.get (2), { 25, 30 });
}
beginTest ("Ranges::set() - setting a range inside another one splits that range");
{
Ranges ranges;
ranges.set ({ -3, 14 }, ops);
expectEquals ((int64) ranges.size(), (int64) 1);
//==============================================================================
ranges.set ({ 3, 7 }, ops);
expectEquals ((int64) ranges.size(), (int64) 3);
expectRange (ranges.get (0), { -3, 3 });
expectRange (ranges.get (1), { 3, 7 });
expectRange (ranges.get (2), { 7, 14 });
}
beginTest ("Ranges::set() - old ranges falling within the bounds of a newly set are erased");
{
Ranges ranges;
ranges.set ({ 0, 5 }, ops);
ranges.set ({ 5, 10 }, ops);
ranges.set ({ 15, 20 }, ops);
ranges.set ({ 25, 30 }, ops);
ranges.set ({ 35, 50 }, ops);
expectEquals ((int64) ranges.size(), (int64) 5);
//==============================================================================
ranges.set ({ 4, 36 }, ops);
expectEquals ((int64) ranges.size(), (int64) 3);
expectRange (ranges.get (0), { 0, 4 });
expectRange (ranges.get (1), { 4, 36 });
expectRange (ranges.get (2), { 36, 50 });
}
beginTest ("Ranges::set() - setting an empty range should be a no-op");
{
Ranges ranges;
ops.clear();
ranges.set ({ 0, 0 }, ops);
expect (ranges.isEmpty());
expect (ops.empty());
}
beginTest ("Ranges::set() - setting a range inside another range");
{
Ranges ranges;
ranges.set ({ 0, 48 }, ops);
ranges.set ({ 48, 127 }, ops);
ranges.set ({ 49, 94 }, ops);
expectEquals ((int64) ranges.size(), (int64) 4, "");
expectRange (ranges.get (0), { 0, 48 });
expectRange (ranges.get (1), { 48, 49 });
expectRange (ranges.get (2), { 49, 94 });
expectRange (ranges.get (3), { 94, 127 });
}
beginTest ("Ranges::split()");
{
Ranges ranges;
ranges.set ({ 0, 48 }, ops);
ranges.set ({ 48, 127 }, ops);
ops.clear();
ranges.split (47, ops);
expectEquals ((int64) ops.size(), (int64) 1, "");
const auto op0 = std::get_if<Ranges::Ops::Split> (&ops[0]);
expect (op0 != nullptr);
if (op0 != nullptr)
expectEquals ((int) op0->index, 0, "The 0th element should be split");
expectEquals ((int64) ranges.size(), (int64) 3, "");
expectRange (ranges.get (0), { 0, 47 });
expectRange (ranges.get (1), { 47, 48 });
expectRange (ranges.get (2), { 48, 127 });
}
beginTest ("Ranges::split() - splitting has no effect when no range begins before and ends after the location");
{
Ranges ranges;
ranges.set ({ 0, 48 }, ops);
ranges.set ({ 48, 127 }, ops);
ops.clear();
ranges.split (48, ops);
expectEquals ((int64) ops.size(), (int64) 0, "");
expectEquals ((int64) ranges.size(), (int64) 2, "");
expectRange (ranges.get (0), { 0, 48 });
expectRange (ranges.get (1), { 48, 127 });
}
beginTest ("Ranges::insert() - basics");
{
Ranges ranges;
ranges.insert ({ -3, 14 }, ops);
expectRange (ranges.get (0), { -3, 14 });
ranges.insert ({ 7, 20 }, ops);
expectRange (ranges.get (0), { -3, 7 });
expectRange (ranges.get (1), { 7, 20 });
expectRange (ranges.get (2), { 20, 27 });
}
beginTest ("Ranges::insert() - inserting shifts all following ranges");
{
Ranges ranges;
ranges.insert ({ 10, 11 }, ops);
ranges.insert ({ 0, 1 }, ops);
expectRange (ranges.get (0), { 0, 1 });
expectRange (ranges.get (1), { 11, 12 });
}
beginTest ("Ranges::insert() - inserting an empty range should be a no-op");
{
Ranges ranges;
ops.clear();
ranges.insert ({ 0, 0 }, ops);
expect (ranges.isEmpty());
expect (ops.empty());
}
const auto getTestRanges = [&ops]
{
Ranges ranges;
ranges.set ({ 0, 48 }, ops);
ranges.set ({ 48, 49 }, ops);
ranges.set ({ 55, 94 }, ops);
ranges.set ({ 94, 127 }, ops);
return ranges;
};
beginTest ("Ranges::eraseFrom() - erasing beyond all ranges has no effect");
{
auto ranges = getTestRanges();
ranges.eraseFrom (ranges.get (ranges.size() - 1).getEnd() + 5, ops);
expectEquals ((int64) ranges.size(), (int64) 4, "");
expectRange (ranges.get (0), { 0, 48 });
expectRange (ranges.get (1), { 48, 49 });
expectRange (ranges.get (2), { 55, 94 });
expectRange (ranges.get (3), { 94, 127 });
}
beginTest ("Ranges::eraseFrom() - erasing modifies the range that encloses the starting index");
{
auto ranges = getTestRanges();
ranges.eraseFrom (122, ops);
expectEquals ((int64) ranges.size(), (int64) 4, "");
expectRange (ranges.get (0), { 0, 48 });
expectRange (ranges.get (1), { 48, 49 });
expectRange (ranges.get (2), { 55, 94 });
expectRange (ranges.get (3), { 94, 122 });
}
beginTest ("Ranges::eraseFrom() - ranges starting after the erased index are deleted entirely");
{
auto ranges = getTestRanges();
ranges.eraseFrom (60, ops);
expectEquals ((int64) ranges.size(), (int64) 3, "");
expectRange (ranges.get (0), { 0, 48 });
expectRange (ranges.get (1), { 48, 49 });
expectRange (ranges.get (2), { 55, 60 });
}
beginTest ("Ranges::eraseFrom() - erasing from a location outside any ranges will still drop subsequent ranges");
{
auto ranges = getTestRanges();
ranges.eraseFrom (51, ops);
expectEquals ((int64) ranges.size(), (int64) 2, "");
expectRange (ranges.get (0), { 0, 48 });
expectRange (ranges.get (1), { 48, 49 });
}
beginTest ("Ranges::erase() - erasing a zero length range has no effect");
{
auto ranges = getTestRanges();
ranges.erase ({ 30, 30 }, ops);
expectEquals ((int64) ranges.size(), (int64) 4, "");
expectRange (ranges.get (0), { 0, 48 });
expectRange (ranges.get (1), { 48, 49 });
expectRange (ranges.get (2), { 55, 94 });
expectRange (ranges.get (3), { 94, 127 });
}
beginTest ("Ranges::erase() - erasing inside a range splits that range");
{
auto ranges = getTestRanges();
ranges.erase ({ 30, 31 }, ops);
expectEquals ((int64) ranges.size(), (int64) 5, "");
expectRange (ranges.get (0), { 0, 30 });
expectRange (ranges.get (1), { 31, 48 });
expectRange (ranges.get (2), { 48, 49 });
expectRange (ranges.get (3), { 55, 94 });
expectRange (ranges.get (4), { 94, 127 });
}
beginTest ("Ranges::erase() - erasing a range that completely overlaps existing ranges erases those");
{
auto ranges = getTestRanges();
ranges.erase ({ 30, 70 }, ops);
expectEquals ((int64) ranges.size(), (int64) 3, "");
expectRange (ranges.get (0), { 0, 30 });
expectRange (ranges.get (1), { 70, 94 });
expectRange (ranges.get (2), { 94, 127 });
}
beginTest ("Ranges::erase() - erasing a range that no previous ranges covered has no effect");
{
auto ranges = getTestRanges();
ranges.erase ({ 51, 53 }, ops);
expectEquals ((int64) ranges.size(), (int64) 4, "");
expectRange (ranges.get (0), { 0, 48 });
expectRange (ranges.get (1), { 48, 49 });
expectRange (ranges.get (2), { 55, 94 });
expectRange (ranges.get (3), { 94, 127 });
}
beginTest ("Ranges::erase() - erasing over a range beyond all limits clears all ranges");
{
auto ranges = getTestRanges();
ranges.erase ({ -1000, 1000 }, ops);
expect (ranges.isEmpty());
}
beginTest ("Ranges::drop() - dropping a range shifts all following ranges downward");
{
auto ranges = getTestRanges();
ranges.drop ({ 48, 49 }, ops);
expectEquals ((int64) ranges.size(), (int64) 3, "");
expectRange (ranges.get (0), { 0, 48 });
expectRange (ranges.get (1), { 54, 93 });
expectRange (ranges.get (2), { 93, 126 });
}
beginTest ("Ranges::drop() - dropping a range shifts all following ranges downward even if no range covered the dropped range previously");
{
auto ranges = getTestRanges();
ranges.drop ({ 51, 53 }, ops);
expectEquals ((int64) ranges.size(), (int64) 4, "");
expectRange (ranges.get (0), { 0, 48 });
expectRange (ranges.get (1), { 48, 49 });
expectRange (ranges.get (2), { 53, 92 });
expectRange (ranges.get (3), { 92, 125 });
}
beginTest ("Ranges::drop() - dropping a range covering all other ranges empties the collection");
{
auto ranges = getTestRanges();
ranges.drop ({ -1000, 1000 }, ops);
expect (ranges.isEmpty());
}
beginTest ("Ranges::covers()");
{
Ranges ranges;
ranges.set ({ 0, 48 }, ops);
ranges.set ({ 48, 49 }, ops);
ranges.set ({ 55, 94 }, ops);
ranges.set ({ 94, 127 }, ops);
ranges.set ({ 127, 150 }, ops);
expect (ranges.covers ({ 0, 48 }));
expect (ranges.covers ({ 0, 20 }));
expect (ranges.covers ({ 10, 30 }));
expect (ranges.covers ({ 30, 48 }));
expect (ranges.covers ({ 30, 49 }));
expect (ranges.covers ({ 55, 150 }));
expect (ranges.covers ({ 60, 145 }));
expect (! ranges.covers ({ -1, 10 }));
expect (! ranges.covers ({ 1, 50 }));
expect (! ranges.covers ({ 50, 140 }));
expect (! ranges.covers ({ 149, 151 }));
expect (ranges.covers ({ 10, 10 }));
expect (! ranges.covers ({ 151, 151 }));
}
}
};
class RangedValuesTests : public UnitTest
{
public:
RangedValuesTests() : UnitTest ("RangedValues", UnitTestCategories::containers) {}
template <typename ItemType>
void expectRangedValuesItem (ItemType item, Range<int64> range, char value)
{
{
String failureMessage { "range " };
failureMessage << item.range << " did not equal expected range " << range;
expect (item.range == range, failureMessage);
}
{
String failureMessage { "value '" };
failureMessage << item.value << "' in range " << range << " did not equal expected value '" << value << "'";
expect (item.value == value, failureMessage);
}
}
void runTest() override
{
auto random = getRandom();
Ranges::Operations ops;
const auto createRangedValuesObject = [&]
{
RangedValues<char> rangedValues;
rangedValues.set ({ 0, 10 }, 'a', ops);
rangedValues.set ({ 11, 20 }, 'b', ops);
rangedValues.set ({ 23, 30 }, 'c', ops);
return rangedValues;
};
beginTest ("RangedValues::set() with distinct value overlapping other ranges");
{
auto rangedValues = createRangedValuesObject();
rangedValues.set ({ 5, 15 }, 'd', ops);
expect (! rangedValues.isEmpty());
expectRangedValuesItem (rangedValues.getItem (0), { 0, 5 }, 'a');
expectRangedValuesItem (rangedValues.getItem (1), { 5, 15 }, 'd');
expectRangedValuesItem (rangedValues.getItem (2), { 15, 20 }, 'b');
expectRangedValuesItem (rangedValues.getItem (3), { 23, 30 }, 'c');
rangedValues.set ({ 19, 24 }, 'e', ops);
expectRangedValuesItem (rangedValues.getItem (2), { 15, 19 }, 'b');
expectRangedValuesItem (rangedValues.getItem (3), { 19, 24 }, 'e');
expectRangedValuesItem (rangedValues.getItem (4), { 24, 30 }, 'c');
}
beginTest ("RangedValues::set() with distinct value in corner cases");
{
auto rangedValues = createRangedValuesObject();
rangedValues.set ({ -1, 0 }, 'd', ops);
expectRangedValuesItem (rangedValues.getItem (0), { -1, 0 }, 'd');
expectRangedValuesItem (rangedValues.getItem (1), { 0, 10 }, 'a');
}
beginTest ("RangedValues::set() with same value with merging disallowed");
{
auto rangedValues = createRangedValuesObject();
rangedValues.set ({ 5, 15 }, 'b', ops, MergeEqualItemsNo{});
expectRangedValuesItem (rangedValues.getItem (0), { 0, 5 }, 'a');
expectRangedValuesItem (rangedValues.getItem (1), { 5, 15 }, 'b');
expectRangedValuesItem (rangedValues.getItem (2), { 15, 20 }, 'b');
expectRangedValuesItem (rangedValues.getItem (3), { 23, 30 }, 'c');
}
beginTest ("RangedValues::set() with same value with merging allowed");
{
auto rangedValues = createRangedValuesObject();
rangedValues.set ({ 5, 15 }, 'b', ops, MergeEqualItemsYes{});
expectRangedValuesItem (rangedValues.getItem (0), { 0, 5 }, 'a');
expectRangedValuesItem (rangedValues.getItem (1), { 5, 20 }, 'b');
expectRangedValuesItem (rangedValues.getItem (2), { 23, 30 }, 'c');
}
beginTest ("RangedValues::set() - setting an empty Range should be a no-op");
{
RangedValues<char> rangedValues;
ops.clear();
rangedValues.set ({ 0, 0 }, 'a', ops);
expect (rangedValues.isEmpty());
expect (ops.empty());
}
beginTest ("RangedValues::set() - setting a range inside another range");
{
RangedValues<char> rangedValues;
rangedValues.set ({ 0, 48 }, 'a', ops);
rangedValues.set ({ 48, 127 }, 'b', ops);
rangedValues.set ({ 49, 94 }, 'c', ops);
expectEquals ((int64) rangedValues.size(), (int64) 4, "");
expectRangedValuesItem (rangedValues.getItem (0), { 0, 48 }, 'a');
expectRangedValuesItem (rangedValues.getItem (1), { 48, 49 }, 'b');
expectRangedValuesItem (rangedValues.getItem (2), { 49, 94 }, 'c');
expectRangedValuesItem (rangedValues.getItem (3), { 94, 127 }, 'b');
}
beginTest ("RangedValues::getIntersectionsWith()");
{
auto rangedValues = createRangedValuesObject();
{
const auto intersections = rangedValues.getIntersectionsWith ({ 5, 43 });
expectRangedValuesItem (intersections.getItem (0), { 5, 10 }, 'a');
expectRangedValuesItem (intersections.getItem (1), { 11, 20 }, 'b');
expectRangedValuesItem (intersections.getItem (2), { 23, 30 }, 'c');
}
{
const auto intersections = rangedValues.getIntersectionsWith ({ -10, 3 });
expectRangedValuesItem (intersections.getItem (0), { 0, 3 }, 'a');
}
}
beginTest ("RangedValues::insert() fuzzing - insert always increases the total covered range");
{
for (auto i = 0; i != 100; ++i)
{
auto rangedValuesNotMerged = createRangedValuesObject();
auto rangedValuesMerged = createRangedValuesObject();
const auto totalLengthBeforeInsert = getCumulativeRangeLengths (rangedValuesNotMerged);
const auto beginInsertionAt = (int64) random.nextInt (100) - 50;
const auto numElemsToInsert = (int64) random.nextInt (1000);
rangedValuesNotMerged.insert ({ Range<int64>::withStartAndLength (beginInsertionAt, numElemsToInsert) },
'a' + (char) random.nextInt (25),
ops,
MergeEqualItemsNo{});
expectEquals (getCumulativeRangeLengths (rangedValuesNotMerged) - totalLengthBeforeInsert, numElemsToInsert);
rangedValuesMerged.insert ({ Range<int64>::withStartAndLength (beginInsertionAt, numElemsToInsert) },
'a' + (char) random.nextInt (25),
ops,
MergeEqualItemsYes{});
expectEquals (getCumulativeRangeLengths (rangedValuesMerged) - totalLengthBeforeInsert, numElemsToInsert);
}
}
beginTest ("RangedValues::insert() with distinct value inside another range");
{
auto rangedValues = createRangedValuesObject();
expectEquals ((int64) rangedValues.size(), (int64) 3);
rangedValues.insert ({ 2, 4 }, 'd', ops);
expectEquals ((int64) rangedValues.size(), (int64) 5);
expectRangedValuesItem (rangedValues.getItem (0), { 0, 2 }, 'a');
expectRangedValuesItem (rangedValues.getItem (1), { 2, 4 }, 'd');
expectRangedValuesItem (rangedValues.getItem (2), { 4, 12 }, 'a');
expectRangedValuesItem (rangedValues.getItem (3), { 13, 22 }, 'b');
expectRangedValuesItem (rangedValues.getItem (4), { 25, 32 }, 'c');
}
beginTest ("RangedValues::insert() with same value inside another range");
{
{
auto rangedValues = createRangedValuesObject();
expectEquals ((int64) rangedValues.size(), (int64) 3);
rangedValues.insert ({ 2, 4 }, 'a', ops, MergeEqualItemsYes{});
expectEquals ((int64) rangedValues.size(), (int64) 3);
expectRangedValuesItem (rangedValues.getItem (0), { 0, 12 }, 'a');
expectRangedValuesItem (rangedValues.getItem (1), { 13, 22 }, 'b');
expectRangedValuesItem (rangedValues.getItem (2), { 25, 32 }, 'c');
}
{
auto rangedValues = createRangedValuesObject();
expectEquals ((int64) rangedValues.size(), (int64) 3);
rangedValues.insert ({ 2, 4 }, 'a', ops, MergeEqualItemsNo{});
expectEquals ((int64) rangedValues.size(), (int64) 5);
expectRangedValuesItem (rangedValues.getItem (0), { 0, 2 }, 'a');
expectRangedValuesItem (rangedValues.getItem (1), { 2, 4 }, 'a');
expectRangedValuesItem (rangedValues.getItem (2), { 4, 12 }, 'a');
expectRangedValuesItem (rangedValues.getItem (3), { 13, 22 }, 'b');
expectRangedValuesItem (rangedValues.getItem (4), { 25, 32 }, 'c');
}
}
beginTest ("RangedValues::insert() - inserting an empty Range should be a no-op");
{
{
RangedValues<char> emptyRangedValues;
ops.clear();
emptyRangedValues.insert ({ 0, 0 }, 'a', ops);
expect (emptyRangedValues.isEmpty());
expect (ops.empty());
}
{
RangedValues<char> rangedValues;
rangedValues.set ({ 0, 10 }, 'a', ops);
ops.clear();
rangedValues.insert ({ 0, 0 }, 'a', ops);
expect (ops.empty());
expectEquals ((int64) rangedValues.size(), (int64) 1);
expectRangedValuesItem (rangedValues.getItem (0), { 0, 10 }, 'a');
}
}
const auto createRangedValuesObjectForErase = [&]
{
RangedValues<char> rangedValues;
rangedValues.set ({ 0, 10 }, 'a', ops);
rangedValues.set ({ 11, 20 }, 'b', ops);
rangedValues.set ({ 23, 30 }, 'c', ops);
rangedValues.set ({ 35, 45 }, 'c', ops);
rangedValues.set ({ 45, 60 }, 'd', ops);
return rangedValues;
};
beginTest ("RangedValues::erase() - erase will not shift subsequent ranges downward");
{
auto rangedValues = createRangedValuesObjectForErase();
rangedValues.erase ({ 15, 16 }, ops);
expectRangedValuesItem (rangedValues.getItem (0), { 0, 10 }, 'a');
expectRangedValuesItem (rangedValues.getItem (1), { 11, 15 }, 'b');
expectRangedValuesItem (rangedValues.getItem (2), { 16, 20 }, 'b');
expectRangedValuesItem (rangedValues.getItem (3), { 23, 30 }, 'c');
expectRangedValuesItem (rangedValues.getItem (4), { 35, 45 }, 'c');
expectRangedValuesItem (rangedValues.getItem (5), { 45, 60 }, 'd');
}
beginTest ("RangedValues::eraseUpTo() - erasing before all ranges has no effect");
{
auto rangedValues = createRangedValuesObjectForErase();
rangedValues.eraseUpTo (rangedValues.getRanges().get (0).getStart(), ops);
expectRangedValuesItem (rangedValues.getItem (0), { 0, 10 }, 'a');
expectRangedValuesItem (rangedValues.getItem (1), { 11, 20 }, 'b');
expectRangedValuesItem (rangedValues.getItem (2), { 23, 30 }, 'c');
expectRangedValuesItem (rangedValues.getItem (3), { 35, 45 }, 'c');
expectRangedValuesItem (rangedValues.getItem (4), { 45, 60 }, 'd');
}
beginTest ("RangedValues::eraseUpTo() - erasing values up to, not including 15");
{
auto rangedValues = createRangedValuesObjectForErase();
rangedValues.eraseUpTo (15, ops);
expectRangedValuesItem (rangedValues.getItem (0), { 15, 20 }, 'b');
expectRangedValuesItem (rangedValues.getItem (1), { 23, 30 }, 'c');
expectRangedValuesItem (rangedValues.getItem (2), { 35, 45 }, 'c');
expectRangedValuesItem (rangedValues.getItem (3), { 45, 60 }, 'd');
}
beginTest ("RangedValues::eraseUpTo() - erasing up to the end of all ranges clears the container");
{
auto rangedValues = createRangedValuesObjectForErase();
const auto ranges = rangedValues.getRanges();
rangedValues.eraseUpTo (ranges.get (ranges.size() - 1).getEnd(), ops);
expect (rangedValues.isEmpty());
}
beginTest ("RangedValues::drop() - drop shifts ranges downward on the right side");
{
auto rangedValues = createRangedValuesObjectForErase();
rangedValues.drop ({ 15, 16 }, ops, MergeEqualItemsNo{});
expectRangedValuesItem (rangedValues.getItem (0), { 0, 10 }, 'a');
expectRangedValuesItem (rangedValues.getItem (1), { 11, 15 }, 'b');
expectRangedValuesItem (rangedValues.getItem (2), { 15, 19 }, 'b');
expectRangedValuesItem (rangedValues.getItem (3), { 22, 29 }, 'c');
expectRangedValuesItem (rangedValues.getItem (4), { 34, 44 }, 'c');
expectRangedValuesItem (rangedValues.getItem (5), { 44, 59 }, 'd');
}
beginTest ("RangedValues::drop() - drop can be used to merge equal values");
{
auto rangedValues = createRangedValuesObjectForErase();
rangedValues.drop ({ 15, 16 }, ops, MergeEqualItemsYes{});
expectRangedValuesItem (rangedValues.getItem (0), { 0, 10 }, 'a');
expectRangedValuesItem (rangedValues.getItem (1), { 11, 19 }, 'b');
expectRangedValuesItem (rangedValues.getItem (2), { 22, 29 }, 'c');
expectRangedValuesItem (rangedValues.getItem (3), { 34, 44 }, 'c');
expectRangedValuesItem (rangedValues.getItem (4), { 44, 59 }, 'd');
}
beginTest ("RangedValues::drop() - the merge happens at the seam caused by the drop and does not extend beyond");
{
auto rangedValues = createRangedValuesObjectForErase();
rangedValues.set ({ 20, 30 }, 'b', ops, MergeEqualItemsNo{});
rangedValues.drop ({ 15, 16 }, ops, MergeEqualItemsYes{});
expectRangedValuesItem (rangedValues.getItem (0), { 0, 10 }, 'a');
// These two items are not merged, even though they form a contiguous range, because
// they were disjoint before the drop and they don't touch each other at the drop
// seam of 15.
expectRangedValuesItem (rangedValues.getItem (1), { 11, 19 }, 'b');
expectRangedValuesItem (rangedValues.getItem (2), { 19, 29 }, 'b');
expectRangedValuesItem (rangedValues.getItem (3), { 34, 44 }, 'c');
expectRangedValuesItem (rangedValues.getItem (4), { 44, 59 }, 'd');
}
}
};
class IntersectingRangedValuesTests : public RangesTestsBase
{
public:
IntersectingRangedValuesTests() : RangesTestsBase ("IntersectingRangedValues", UnitTestCategories::containers) {}
void runTest() override
{
Ranges::Operations ops;
beginTest ("IntersectingRangedValuesTests - iterating over multiple RangedValues");
{
RangedValues<int> rv1;
rv1.set ({ 3, 8}, 1, ops);
rv1.set ({ 9, 16}, 2, ops);
rv1.set ({ 30, 40}, 3, ops);
RangedValues<int> rv2;
rv2.set ({ 0, 4}, 7, ops);
rv2.set ({ 4, 6}, 11, ops);
rv2.set ({ 6, 25}, 13, ops);
rv2.set ({ 27, 55}, 17, ops);
RangedValues<int> rv3;
rv3.set ({ -2, 10}, -1, ops);
rv3.set ({ 15, 19}, -2, ops);
rv3.set ({ 22, 36}, -3, ops);
int iteration = 0;
for (const auto [range, v1, v2, v3] : makeIntersectingRangedValues (&rv1, &rv2, &rv3))
{
if (iteration == 0)
{
expectRange (range, Range<int64> { 3, 4 });
expect (v1 == 1 && v2 == 7 && v3 == -1);
}
if (iteration == 1)
{
expectRange (range, Range<int64> { 4, 6 });
expect (v1 == 1 && v2 == 11 && v3 == -1);
}
if (iteration == 2)
{
expectRange (range, Range<int64> { 6, 8 });
expect (v1 == 1 && v2 == 13 && v3 == -1);
}
if (iteration == 3)
{
expectRange (range, Range<int64> { 9, 10 });
expect (v1 == 2 && v2 == 13 && v3 == -1);
}
if (iteration == 4)
{
expectRange (range, Range<int64> { 15, 16 });
expect (v1 == 2 && v2 == 13 && v3 == -2);
}
if (iteration == 5)
{
expectRange (range, Range<int64> { 30, 36 });
expect (v1 == 3 && v2 == 17 && v3 == -3);
}
++iteration;
}
expectEquals (iteration, 6);
}
}
};
static RangesTests rangesTests;
static RangedValuesTests rangedValuesTests;
static IntersectingRangedValuesTests intersectingRangedValuesTests;
#endif
} // namespace juce::detail
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,232 @@
/*
==============================================================================
This file is part of the JUCE framework.
Copyright (c) Raw Material Software Limited
JUCE is an open source framework subject to commercial or open source
licensing.
By downloading, installing, or using the JUCE framework, or combining the
JUCE framework with any other source code, object code, content or any other
copyrightable work, you agree to the terms of the JUCE End User Licence
Agreement, and all incorporated terms including the JUCE Privacy Policy and
the JUCE Website Terms of Service, as applicable, which will bind you. If you
do not agree to the terms of these agreements, we will not license the JUCE
framework to you, and you must discontinue the installation or download
process and cease use of the JUCE framework.
JUCE End User Licence Agreement: https://juce.com/legal/juce-9-licence/
JUCE Privacy Policy: https://juce.com/juce-privacy-policy
JUCE Website Terms of Service: https://juce.com/juce-website-terms-of-service/
Or:
You may also use this code under the terms of the AGPLv3:
https://www.gnu.org/licenses/agpl-3.0.en.html
THE JUCE FRAMEWORK IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL
WARRANTIES, WHETHER EXPRESSED OR IMPLIED, INCLUDING WARRANTY OF
MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, ARE DISCLAIMED.
==============================================================================
*/
namespace juce::detail
{
class ShapedText::Impl
{
public:
Impl (String textIn, Options optionsIn)
: options { std::move (optionsIn) },
text { std::move (textIn) }
{
}
void draw (const Graphics& g, AffineTransform transform) const
{
drawJustifiedText (justifiedText, g, transform);
}
float getHeight() const
{
return justifiedText.getHeight();
}
int64 getNumGlyphs() const
{
return simpleShapedText.getNumGlyphs();
}
const detail::RangedValues<LineMetrics>& getLineMetricsForGlyphRange() const
{
return justifiedText.getLineMetricsForGlyphRange();
}
const detail::Ranges& getLineTextRanges() const
{
return simpleShapedText.getLineTextRanges();
}
auto& getText() const
{
return text;
}
auto getTextRange (int64 glyphIndex) const
{
return simpleShapedText.getTextRange (glyphIndex);
}
auto isLtr (int64 glyphIndex) const
{
return simpleShapedText.isLtr (glyphIndex);
}
int64 getTextIndexForCaret (Point<float> p) const
{
const auto getGlyph = [&] (int64 i)
{
return simpleShapedText.getGlyphs()[(size_t) i];
};
if (getNumGlyphs() == 0)
return 0;
const auto glyphOnTheRight = justifiedText.getGlyphIndexToTheRightOf (p);
if (glyphOnTheRight >= getNumGlyphs())
{
const auto glyphOnTheLeft = glyphOnTheRight - 1;
const auto ltr = simpleShapedText.getGlyphLookup().find (getGlyph (glyphOnTheLeft).cluster)->value.ltr;
if (ltr)
return simpleShapedText.getTextIndexAfterGlyph (glyphOnTheLeft);
return simpleShapedText.getGlyphs()[(size_t) glyphOnTheLeft].cluster;
}
const auto ltr = simpleShapedText.getGlyphLookup().find (getGlyph (glyphOnTheRight).cluster)->value.ltr;
if (ltr)
return simpleShapedText.getGlyphs()[(size_t) glyphOnTheRight].cluster;
return simpleShapedText.getTextIndexAfterGlyph (glyphOnTheRight);
}
void getGlyphRanges (Range<int64> textRange, std::vector<Range<int64>>& outRanges) const
{
simpleShapedText.getGlyphRanges (textRange, outRanges);
}
RectangleList<float> getGlyphsBounds (Range<int64> glyphRange) const
{
return justifiedText.getGlyphsBounds (glyphRange);
}
auto getGlyphAnchor (int64 index) const
{
return justifiedText.getGlyphAnchor (index);
}
Span<const float> getMinimumRequiredWidthForLines() const
{
return justifiedText.getMinimumRequiredWidthForLines();
}
//==============================================================================
auto& getSimpleShapedText() const { return simpleShapedText; }
auto& getJustifiedText() const { return justifiedText; }
private:
ShapedTextOptions options;
String text;
SimpleShapedText simpleShapedText { &text, options };
JustifiedText justifiedText { &simpleShapedText, options };
};
ShapedText::ShapedText() : ShapedText ("", {})
{
}
ShapedText::ShapedText (String text) : ShapedText (std::move (text), {})
{
}
ShapedText::ShapedText (String text, Options options)
{
impl = std::make_shared<Impl> (std::move (text), std::move (options));
}
void ShapedText::draw (const Graphics& g, AffineTransform transform) const
{
impl->draw (g, transform);
}
float ShapedText::getHeight() const
{
return impl->getHeight();
}
int64 ShapedText::getNumGlyphs() const
{
return impl->getNumGlyphs();
}
const detail::RangedValues<LineMetrics>& ShapedText::getLineMetricsForGlyphRange() const
{
return impl->getLineMetricsForGlyphRange();
}
const detail::Ranges& ShapedText::getLineTextRanges() const
{
return impl->getLineTextRanges();
}
const String& ShapedText::getText() const
{
return impl->getText();
}
Range<int64> ShapedText::getTextRange (int64 glyphIndex) const
{
return impl->getTextRange (glyphIndex);
}
bool ShapedText::isLtr (int64 glyphIndex) const
{
return impl->isLtr (glyphIndex);
}
int64 ShapedText::getTextIndexForCaret (Point<float> p) const
{
return impl->getTextIndexForCaret (p);
}
void ShapedText::getGlyphRanges (Range<int64> textRange, std::vector<Range<int64>>& outRanges) const
{
return impl->getGlyphRanges (textRange, outRanges);
}
RectangleList<float> ShapedText::getGlyphsBounds (Range<int64> glyphRange) const
{
return impl->getGlyphsBounds (glyphRange);
}
GlyphAnchorResult ShapedText::getGlyphAnchor (int64 index) const
{
return impl->getGlyphAnchor (index);
}
Span<const float> ShapedText::getMinimumRequiredWidthForLines() const
{
return impl->getMinimumRequiredWidthForLines();
}
const JustifiedText& ShapedText::getJustifiedText() const { return impl->getJustifiedText(); }
const SimpleShapedText& ShapedText::getSimpleShapedText() const { return impl->getSimpleShapedText(); }
} // namespace juce::detail
@@ -0,0 +1,116 @@
/*
==============================================================================
This file is part of the JUCE framework.
Copyright (c) Raw Material Software Limited
JUCE is an open source framework subject to commercial or open source
licensing.
By downloading, installing, or using the JUCE framework, or combining the
JUCE framework with any other source code, object code, content or any other
copyrightable work, you agree to the terms of the JUCE End User Licence
Agreement, and all incorporated terms including the JUCE Privacy Policy and
the JUCE Website Terms of Service, as applicable, which will bind you. If you
do not agree to the terms of these agreements, we will not license the JUCE
framework to you, and you must discontinue the installation or download
process and cease use of the JUCE framework.
JUCE End User Licence Agreement: https://juce.com/legal/juce-9-licence/
JUCE Privacy Policy: https://juce.com/juce-privacy-policy
JUCE Website Terms of Service: https://juce.com/juce-website-terms-of-service/
Or:
You may also use this code under the terms of the AGPLv3:
https://www.gnu.org/licenses/agpl-3.0.en.html
THE JUCE FRAMEWORK IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL
WARRANTIES, WHETHER EXPRESSED OR IMPLIED, INCLUDING WARRANTY OF
MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, ARE DISCLAIMED.
==============================================================================
*/
namespace juce::detail
{
/* Class that can visually shape a Unicode string provided a list of Fonts corresponding to
sub-ranges of the string.
*/
class JUCE_API ShapedText
{
public:
using Options = ShapedTextOptions;
ShapedText();
explicit ShapedText (String text);
ShapedText (String text, Options options);
/* Returns the text which was used to construct this object. */
const String& getText() const;
Span<const ShapedGlyph> getGlyphs() const;
/* Returns the text's codepoint range, to which the glyph under the provided index belongs.
This range will have a length of at least one, and potentially more than one if ligatures
are enabled.
*/
Range<int64> getTextRange (int64 glyphIndex) const;
bool isLtr (int64 glyphIndex) const;
int64 getTextIndexForCaret (Point<float> p) const;
void getGlyphRanges (Range<int64> textRange, std::vector<Range<int64>>& outRanges) const;
RectangleList<float> getGlyphsBounds (Range<int64> glyphRange) const;
/* @see JustifiedText::getGlyphAnchor() */
GlyphAnchorResult getGlyphAnchor (int64 index) const;
/* Returns the widths for each line, that the glyphs would require to be rendered without being
truncated. This will or will not include the space required by trailing whitespaces in the
line based on the ShapedTextOptions::withTrailingWhitespacesShouldFit() value.
This value isn't affected by the Justification parameter, it just reports the amount of
width that would be required to avoid truncation.
*/
Span<const float> getMinimumRequiredWidthForLines() const;
/* @see JustifiedText::accessTogetherWith */
template <typename Callable, typename... RangedValues>
void accessTogetherWith (Callable&& callback, RangedValues&&... rangedValues) const
{
getJustifiedText().accessTogetherWith (std::forward<Callable> (callback),
std::forward<RangedValues> (rangedValues)...);
}
/* Draws the text. */
void draw (const Graphics& g, AffineTransform transform) const;
/* @see JustifiedText::getHeight
*/
float getHeight() const;
int64 getNumGlyphs() const;
const detail::RangedValues<LineMetrics>& getLineMetricsForGlyphRange() const;
const detail::Ranges& getLineTextRanges() const;
/* @internal */
const JustifiedText& getJustifiedText() const;
/* @internal */
const SimpleShapedText& getSimpleShapedText() const;
private:
class Impl;
std::shared_ptr<Impl> impl;
};
} // namespace juce::detail
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,335 @@
/*
==============================================================================
This file is part of the JUCE framework.
Copyright (c) Raw Material Software Limited
JUCE is an open source framework subject to commercial or open source
licensing.
By downloading, installing, or using the JUCE framework, or combining the
JUCE framework with any other source code, object code, content or any other
copyrightable work, you agree to the terms of the JUCE End User Licence
Agreement, and all incorporated terms including the JUCE Privacy Policy and
the JUCE Website Terms of Service, as applicable, which will bind you. If you
do not agree to the terms of these agreements, we will not license the JUCE
framework to you, and you must discontinue the installation or download
process and cease use of the JUCE framework.
JUCE End User Licence Agreement: https://juce.com/legal/juce-9-licence/
JUCE Privacy Policy: https://juce.com/juce-privacy-policy
JUCE Website Terms of Service: https://juce.com/juce-website-terms-of-service/
Or:
You may also use this code under the terms of the AGPLv3:
https://www.gnu.org/licenses/agpl-3.0.en.html
THE JUCE FRAMEWORK IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL
WARRANTIES, WHETHER EXPRESSED OR IMPLIED, INCLUDING WARRANTY OF
MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, ARE DISCLAIMED.
==============================================================================
*/
namespace juce::detail
{
/** Types of text direction. This may also be applied to characters. */
enum class TextDirection
{
ltr, // This text reads left to right.
rtl // This text reads right to left.
};
class ShapedTextOptions
{
private:
auto tie() const;
public:
bool operator== (const ShapedTextOptions& other) const;
bool operator!= (const ShapedTextOptions& other) const;
//==============================================================================
[[nodiscard]] ShapedTextOptions withJustification (Justification x) const
{
return withMember (*this, &ShapedTextOptions::justification, x);
}
/* This option will use soft wrapping for lines that are longer than the specified value,
and it will also align each line to this width, using the Justification provided in
withJustification.
The alignment width can be overriden using withAlignmentWidth, but currently we only need
to do this for the TextEditor.
*/
[[nodiscard]] ShapedTextOptions withWordWrapWidth (float x) const
{
return withMember (*this, &ShapedTextOptions::wordWrapWidth, x);
}
/* With this option each line will be aligned only if it's shorter or equal to the alignment
width. Otherwise, the line's x anchor will be 0.0f. This is in contrast to using
withWordWrapWidth only, which will modify the x anchor of RTL lines that are too long, to ensure
that it's the logical end of the text that falls outside the visible bounds.
The alignment width is also a distinct value from the value used for soft wrapping which is
specified using withWordWrapWidth.
This option is specifically meant to support an existing TextEditor behaviour, where text
can be aligned even when word wrapping is off. You probably don't need to use this function,
unless you want to reproduce the particular behaviour seen in the TextEditor, and should
only use withWordWrapWidth, if alignment is required.
With this option off, text is either not aligned, or aligned to the width specified using
withWordWrapWidth.
When this option is in use, it overrides the width specified in withWordWrapWidth for alignment
purposes, but not for line wrapping purposes.
It also accommodates the fact that the TextEditor has a scrolling feature and text never
becomes unreachable, even if the lines are longer than the viewport's width.
*/
[[nodiscard]] ShapedTextOptions withAlignmentWidth (float x) const
{
return withMember (*this, &ShapedTextOptions::alignmentWidth, x);
}
[[nodiscard]] ShapedTextOptions withHeight (float x) const
{
return withMember (*this, &ShapedTextOptions::height, x);
}
[[nodiscard]] ShapedTextOptions withFont (Font x) const
{
RangedValues<Font> fonts;
detail::Ranges::Operations ops;
fonts.set ({ 0, std::numeric_limits<int64>::max() }, x, ops);
return withMember (*this, &ShapedTextOptions::fontsForRange, std::move (fonts));
}
[[nodiscard]] ShapedTextOptions withFonts (const detail::RangedValues<Font>& x) const
{
return withMember (*this, &ShapedTextOptions::fontsForRange, x);
}
[[nodiscard]] ShapedTextOptions withFirstLineIndent (float x) const
{
return withMember (*this, &ShapedTextOptions::firstLineIndent, x);
}
/* This controls the space between lines using a proportional value, with a default of 1.0,
meaning single line spacing i.e. the descender of the current line + ascender of the next
line. This value is multiplied by the leading provided here.
*/
[[nodiscard]] ShapedTextOptions withLeading (float x) const
{
return withMember (*this, &ShapedTextOptions::leading, x);
}
/* This controls the space between lines using an additive absolute value, with a default of 0.0.
This value is added to the spacing between each two lines.
*/
[[nodiscard]] ShapedTextOptions withAdditiveLineSpacing (float x) const
{
return withMember (*this, &ShapedTextOptions::additiveLineSpacing, x);
}
[[nodiscard]] ShapedTextOptions withBaselineAtZero (bool x = true) const
{
return withMember (*this, &ShapedTextOptions::baselineAtZero, x);
}
[[nodiscard]] ShapedTextOptions withTrailingWhitespacesShouldFit (bool x = true) const
{
return withMember (*this, &ShapedTextOptions::trailingWhitespacesShouldFit, x);
}
[[nodiscard]] ShapedTextOptions withMaxNumLines (int64 x) const
{
return withMember (*this, &ShapedTextOptions::maxNumLines, x);
}
[[nodiscard]] ShapedTextOptions withEllipsis (String x = String::charToString ((juce_wchar) 0x2026)) const
{
return withMember (*this, &ShapedTextOptions::ellipsis, std::move (x));
}
/* Draw each line in its entirety even if it goes beyond wordWrapWidth. This means that even
if configured, an ellipsis will never be inserted.
This is used by the TextEditor where the Viewport guarantees that all text will be viewable
even beyond the word wrap width.
*/
[[nodiscard]] ShapedTextOptions withDrawLinesInFull (bool x = true) const
{
return withMember (*this, &ShapedTextOptions::drawLinesInFull, std::move (x));
}
[[nodiscard]] ShapedTextOptions withReadingDirection (std::optional<TextDirection> x) const
{
return withMember (*this, &ShapedTextOptions::readingDir, x);
}
[[nodiscard]] ShapedTextOptions withAllowBreakingInsideWord (bool x = true) const
{
return withMember (*this, &ShapedTextOptions::allowBreakingInsideWord, x);
}
const auto& getReadingDirection() const { return readingDir; }
const auto& getJustification() const { return justification; }
const auto& getWordWrapWidth() const { return wordWrapWidth; }
const auto& getAlignmentWidth() const { return alignmentWidth; }
const auto& getHeight() const { return height; }
const auto& getFontsForRange() const { return fontsForRange; }
const auto& getFirstLineIndent() const { return firstLineIndent; }
const auto& getLeading() const { return leading; }
const auto& getAdditiveLineSpacing() const { return additiveLineSpacing; }
const auto& isBaselineAtZero() const { return baselineAtZero; }
const auto& getTrailingWhitespacesShouldFit() const { return trailingWhitespacesShouldFit; }
const auto& getMaxNumLines() const { return maxNumLines; }
const auto& getEllipsis() const { return ellipsis; }
const auto& getDrawLinesInFull() const { return drawLinesInFull; }
const auto& getAllowBreakingInsideWord() const { return allowBreakingInsideWord; }
private:
Justification justification { Justification::topLeft };
std::optional<TextDirection> readingDir;
std::optional<float> wordWrapWidth;
std::optional<float> alignmentWidth;
std::optional<float> height;
detail::RangedValues<Font> fontsForRange = std::invoke ([&]
{
detail::RangedValues<Font> result;
detail::Ranges::Operations ops;
result.set ({ 0, std::numeric_limits<int64>::max() }, FontOptions { 15.0f }, ops);
return result;
});
float firstLineIndent = 0.0f;
float leading = 1.0f;
float additiveLineSpacing = 0.0f;
bool baselineAtZero = false;
bool allowBreakingInsideWord = false;
bool trailingWhitespacesShouldFit = true;
bool drawLinesInFull = false;
int64 maxNumLines = std::numeric_limits<int64>::max();
String ellipsis;
};
struct ShapedGlyph
{
ShapedGlyph (uint32_t glyphIdIn,
int64 clusterIn,
bool unsafeToBreakIn,
bool whitespaceIn,
bool newlineIn,
int8_t distanceFromLigatureIn,
Point<float> advanceIn,
Point<float> offsetIn)
: advance (advanceIn),
offset (offsetIn),
cluster (clusterIn),
glyphId (glyphIdIn),
unsafeToBreak (unsafeToBreakIn),
whitespace (whitespaceIn),
newline (newlineIn),
distanceFromLigature (distanceFromLigatureIn) {}
bool isUnsafeToBreak() const { return unsafeToBreak; }
bool isWhitespace() const { return whitespace; }
bool isNewline() const { return newline; }
bool isNonLigature() const { return distanceFromLigature == 0; }
bool isLigature() const { return distanceFromLigature < 0; }
bool isPlaceholderForLigature() const { return distanceFromLigature > 0; }
int8_t getDistanceFromLigature() const { return distanceFromLigature; }
int8_t getNumTrailingLigaturePlaceholders() const { return (int8_t) -distanceFromLigature; }
Point<float> advance;
Point<float> offset;
int64 cluster;
uint32_t glyphId;
private:
// These are effectively bools, pack into a single int once we have more than four flags.
int8_t unsafeToBreak;
int8_t whitespace;
int8_t newline;
int8_t distanceFromLigature;
};
struct GlyphLookupEntry
{
Range<int64> glyphRange;
bool ltr = true;
};
class SimpleShapedText
{
public:
/* Shapes and lays out the first contiguous sequence of ranges specified in the fonts
parameter.
*/
SimpleShapedText (const String* data,
const ShapedTextOptions& options);
const auto& getLineNumbersForGlyphRanges() const { return lineNumbersForGlyphRanges; }
const auto& getLineTextRanges() const { return lineTextRanges; }
const auto& getResolvedFonts() const { return resolvedFonts; }
Range<int64> getTextRange (int64 glyphIndex) const;
/* Returns true if the specified glyph is inside to an LTR run.
*/
bool isLtr (int64 glyphIndex) const;
/* This function may fail to return an out range, even if the provided textRange falls inside
the string range used for the creation of the ShapedText object.
This is because the shaping process could fail due to insufficient glyph resolution to the
point, where it will produce zero glyphs for the provided string.
*/
void getGlyphRanges (Range<int64> textRange, std::vector<Range<int64>>& outRanges) const;
/* Returns the input codepoint index that follows the glyph in a logical sense. So for LTR text
this is the cluster number of the glyph to the right. For RTL text it's the one on the left.
If there is no subsequent glyph, the returned number is the first Unicode codepoint index
that isn't covered by the cluster to which the selected glyph belongs, so for the glyph 'o'
in "hello" this would be 5, given there are no ligatures in use.
*/
int64 getTextIndexAfterGlyph (int64 glyphIndex) const;
int64 getNumLines() const { return (int64) lineNumbersForGlyphRanges.getRanges().size(); }
int64 getNumGlyphs() const { return (int64) glyphsInVisualOrder.size(); }
juce_wchar getCodepoint (int64 glyphIndex) const;
Span<const ShapedGlyph> getGlyphs (Range<int64> glyphRange) const;
Span<const ShapedGlyph> getGlyphs() const;
const auto& getGlyphLookup() const { return glyphLookup; }
private:
void shape (const String& data,
const ShapedTextOptions& options);
const String& string;
std::vector<ShapedGlyph> glyphsInVisualOrder;
detail::RangedValues<int64> lineNumbersForGlyphRanges;
detail::Ranges lineTextRanges;
detail::RangedValues<Font> resolvedFonts;
detail::RangedValues<GlyphLookupEntry> glyphLookup;
JUCE_LEAK_DETECTOR (SimpleShapedText)
};
} // namespace juce::detail
@@ -0,0 +1,287 @@
/*
==============================================================================
This file is part of the JUCE framework.
Copyright (c) Raw Material Software Limited
JUCE is an open source framework subject to commercial or open source
licensing.
By downloading, installing, or using the JUCE framework, or combining the
JUCE framework with any other source code, object code, content or any other
copyrightable work, you agree to the terms of the JUCE End User Licence
Agreement, and all incorporated terms including the JUCE Privacy Policy and
the JUCE Website Terms of Service, as applicable, which will bind you. If you
do not agree to the terms of these agreements, we will not license the JUCE
framework to you, and you must discontinue the installation or download
process and cease use of the JUCE framework.
JUCE End User Licence Agreement: https://juce.com/legal/juce-9-licence/
JUCE Privacy Policy: https://juce.com/juce-privacy-policy
JUCE Website Terms of Service: https://juce.com/juce-website-terms-of-service/
Or:
You may also use this code under the terms of the AGPLv3:
https://www.gnu.org/licenses/agpl-3.0.en.html
THE JUCE FRAMEWORK IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL
WARRANTIES, WHETHER EXPRESSED OR IMPLIED, INCLUDING WARRANTY OF
MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, ARE DISCLAIMED.
==============================================================================
*/
namespace juce::detail
{
GradientCircle GradientCircle::transformedBy (const AffineTransform& t) const
{
// Necessary condition for maintaining a circular shape
jassert (exactlyEqual (t.mat00, t.mat11));
GradientCircle result;
result.c = c.transformedBy (t);
const auto scaleFactor = std::sqrt (std::abs (t.getDeterminant()));
result.r = r * scaleFactor;
return result;
}
//==============================================================================
GradientCircle RadialGradientView::getEndCircle() const
{
return GradientCircle { isLegacy() ? gradient.point1 : gradient.point2,
isLegacy() ? gradient.point1.getDistanceFrom (gradient.point2)
: gradient.endRadius };
}
GradientCircle RadialGradientView::getStartCircle() const
{
return GradientCircle { gradient.point1, gradient.startRadius };
}
bool RadialGradientView::isLegacy() const noexcept
{
return gradient.endRadius < 0.0f;
}
//==============================================================================
std::optional<TwoPointConicalGradient> TwoPointConicalGradient::create (const ColourGradient& gradient)
{
jassert (gradient.isRadial);
RadialGradientView rg { &gradient };
const auto s = rg.getStartCircle();
const auto e = rg.getEndCircle();
if (! isConicalGradientApplicable (s, e))
return std::nullopt;
return TwoPointConicalGradient { s, e };
}
TwoPointConicalGradient::TwoPointConicalGradient (GradientCircle startCircle, GradientCircle endCircle)
: swapped { approximatelyEqual (endCircle.r, 0.0f) },
c0 { swapped ? endCircle : startCircle },
c1 { swapped ? startCircle : endCircle }
{
jassert (! approximatelyEqual (c0.r, c1.r, inputTolerance));
f = c0.r / (c0.r - c1.r);
const auto focalPoint = (1.0f - f) * c0.c + f * c1.c;
const auto c1FocalSegment = c1.c - focalPoint;
// We need a transform that moves the focal point to (0, 0) and c1 to (1, 0), and scales
// uniformly on the two axes.
const auto angleWithAxisX = std::atan2 (c1FocalSegment.y, c1FocalSegment.x);
regularisationTransform = AffineTransform::translation (-focalPoint.x,
-focalPoint.y).rotated (-angleWithAxisX);
const auto distToFocalPoint = c1FocalSegment.getDistanceFromOrigin();
// Gradients where the start and end circles are concentric are dispatched to the old gradient
jassert (! approximatelyEqual (distToFocalPoint, 0.0f, inputTolerance));
regularisationTransform = regularisationTransform.scaled (1.0f / distToFocalPoint);
// The math only works if the circles aren't transformed into ellipses
jassert (exactlyEqual (regularisationTransform.mat00, regularisationTransform.mat11));
c0 = c0.transformedBy (regularisationTransform);
c1 = c1.transformedBy (regularisationTransform);
f = c0.r / (c0.r - c1.r);
}
std::optional<float> TwoPointConicalGradient::calculateWeight (Point<float> p) const
{
p = p.transformedBy (regularisationTransform);
// Geometric meaning: the focus point sits on r1's circumference. The start end and end
// circles are touching.
//
// As r1 approaches 1.0f the accuracy of the solutions visibly deteriorates. We want to
// switch over to the more stable formula, that assumes r = 1, as soon as possible.
// At the same time we want the centre positioning error caused by this switch to be << 1px.
const auto closeToSingular = approximatelyEqual (c1.r, 1.0f, regularisationTolerance);
static constexpr auto squared = [] (float x) noexcept { return x * x; };
const auto x_prime = std::invoke (
[&]
{
if (closeToSingular)
return p.x / 2.0f;
return c1.r / (squared (c1.r) - 1.0f) * p.x;
});
const auto y_prime = std::invoke (
[&]
{
if (closeToSingular)
return p.y / 2.0f;
return std::sqrt (std::abs (squared (c1.r) - 1.0f)) / (squared (c1.r) - 1.0f) * p.y;
});
const auto x_hat = std::abs (1.0f - f) * x_prime;
const auto y_hat = std::abs (1.0f - f) * y_prime;
bool invalid = false;
const auto x_hat_t = std::invoke (
[&]
{
if (closeToSingular)
return (squared (x_hat) + squared (y_hat)) / x_hat;
if (c1.r < 1.0f)
{
// Geometric meaning: the start circle is outside the end circle, and we're
// looking for a solution that's outside the cone defined by them.
if (squared (x_hat) - squared (y_hat) < 0.0f)
{
invalid = true;
return 0.0f;
};
if (swapped || (1.0f - f) < 0.0f)
return -std::sqrt (squared (x_hat) - squared (y_hat)) - x_hat / c1.r;
return std::sqrt (squared (x_hat) - squared (y_hat)) - x_hat / c1.r;
}
// c1.r > 1.0f
return std::sqrt (squared (x_hat) + squared (y_hat)) - x_hat / c1.r;
});
if (invalid)
return std::nullopt;
if (x_hat_t < 0.0f)
return std::nullopt;
constexpr auto signum = [] (float v) { return (v > 0.0f) ? 1.0f : ((v < 0.0f) ? -1.0f : 0.0f); };
const auto t = f + signum (1.0f - f) * x_hat_t;
if (swapped)
return 1.0f - t;
return t;
}
bool TwoPointConicalGradient::isConicalGradientApplicable (const GradientCircle& s,
const GradientCircle& e)
{
if (approximatelyEqual (s.c.getDistanceFrom (e.c), 0.0f, inputTolerance))
return false;
if (approximatelyEqual (s.r, e.r, inputTolerance))
return false;
return true;
}
//==============================================================================
//==============================================================================
#if JUCE_UNIT_TESTS
struct TwoPointConicalGradientTest final : public UnitTest
{
TwoPointConicalGradientTest() : UnitTest ("TwoPointConicalGradientTest", UnitTestCategories::graphics)
{
}
static constexpr auto magnitude = 200.0f;
static constexpr auto safetyFactor = 1.1f;
// TwoPointConicalGradient::regularisationTolerance is used by the
// TwoPointConicalGradient class in relation to the internal, normalised space,
// where the end circle's distance from the focal point is 1.0f.
inline static const auto tolerance = TwoPointConicalGradient::regularisationTolerance.getAbsolute()
* magnitude
* safetyFactor;
static Point<float> makeRandomPoint (Random& random)
{
return { -magnitude / 2.0f + random.nextFloat() * magnitude,
-magnitude / 2.0f + random.nextFloat() * magnitude };
}
void runTest() override
{
Random random = getRandom();
beginTest ("Start circle lies completely inside the end circle");
{
for (int i = 0; i < 1000; ++i)
{
GradientCircle end { makeRandomPoint (random),
std::max (3.0f * tolerance, random.nextFloat() * (magnitude / 2.0f)) };
const auto startDistanceFromEnd = tolerance + std::max (end.r - 2.0f * tolerance, 0.0f) * random.nextFloat();
const auto startRadius = (end.r - startDistanceFromEnd - tolerance) * random.nextFloat();
const auto startAngle = MathConstants<float>::twoPi * random.nextFloat();
const auto startCentre = Point<float> { end.c.x + std::cos (startAngle) * startDistanceFromEnd,
end.c.y + std::sin (startAngle) * startDistanceFromEnd };
GradientCircle start { startCentre, startRadius };
ColourGradient cg { Colours::red, start.c.x, start.c.y, Colours::blue, end.c.x, end.c.y, true };
cg.startRadius = start.r;
cg.endRadius = end.r;
const auto gradient = TwoPointConicalGradient::create (cg);
expect (gradient.has_value(),
"TwoPointConicalGradient should be appropriate for safely constructed arguments");
for (int j = 0; j < 100; ++j)
{
const auto p = makeRandomPoint (random);
const auto t = gradient->calculateWeight (p);
expect (t.has_value(),
"TwoPointConicalGradient with a start circle completely inside the end circle "
"should be able to calculate a weight for any point");
if (t.has_value())
{
const auto f = *t;
const auto pointToCenter = p.getDistanceFrom ((1.0f - f) * start.c + f * end.c);
const auto solutionRadius = std::abs ((1.0f - f) * start.r + f * end.r);
expect (approximatelyEqual (pointToCenter, solutionRadius, relativeTolerance (0.002f)),
"The solution should specify a circle that passes through the rendered pixel");
}
}
}
}
}
};
static TwoPointConicalGradientTest twoPointConicalGradientTest;
#endif
} // namespace juce::detail
@@ -0,0 +1,150 @@
/*
==============================================================================
This file is part of the JUCE framework.
Copyright (c) Raw Material Software Limited
JUCE is an open source framework subject to commercial or open source
licensing.
By downloading, installing, or using the JUCE framework, or combining the
JUCE framework with any other source code, object code, content or any other
copyrightable work, you agree to the terms of the JUCE End User Licence
Agreement, and all incorporated terms including the JUCE Privacy Policy and
the JUCE Website Terms of Service, as applicable, which will bind you. If you
do not agree to the terms of these agreements, we will not license the JUCE
framework to you, and you must discontinue the installation or download
process and cease use of the JUCE framework.
JUCE End User Licence Agreement: https://juce.com/legal/juce-9-licence/
JUCE Privacy Policy: https://juce.com/juce-privacy-policy
JUCE Website Terms of Service: https://juce.com/juce-website-terms-of-service/
Or:
You may also use this code under the terms of the AGPLv3:
https://www.gnu.org/licenses/agpl-3.0.en.html
THE JUCE FRAMEWORK IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL
WARRANTIES, WHETHER EXPRESSED OR IMPLIED, INCLUDING WARRANTY OF
MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, ARE DISCLAIMED.
==============================================================================
*/
namespace juce::detail
{
/* The two-point conical gradient is defined by two circles. */
struct GradientCircle
{
Point<float> c;
float r{};
GradientCircle transformedBy (const AffineTransform& t) const;
};
/* Helper class to correctly interpret the parameters of a radial gradient. */
struct RadialGradientView
{
RadialGradientView (const ColourGradient* gradientIn)
: gradient (*gradientIn)
{
jassert (gradientIn != nullptr);
jassert (gradient.isRadial);
}
/* The end circle. This defines the outline of the gradient.
This corresponds to the 'cx', 'cy' and 'r' SVG parameters.
*/
GradientCircle getEndCircle() const;
/* The start/focus circle.
This corresponds to the 'fx', 'fy' and 'fr' SVG parameters.
*/
GradientCircle getStartCircle() const;
private:
bool isLegacy() const noexcept;
const ColourGradient& gradient;
};
struct SpreadMethods
{
SpreadMethods() = delete;
static constexpr float pad (float t) noexcept
{
return std::clamp (t, 0.0f, 1.0f);
}
static float reflect (float t) noexcept
{
float integral{};
const auto fractional = std::modf (std::max (0.0f, t), &integral);
return (((int) integral) % 2 == 0) ? fractional : (1.0f - fractional);
}
static float repeat (float t) noexcept
{
float integral{};
return std::modf (std::max (0.0f, t), &integral);
}
static auto* getFunction (ColourGradient::SpreadMethod method) noexcept
{
switch (method)
{
case ColourGradient::SpreadMethod::pad: return &pad;
case ColourGradient::SpreadMethod::reflect: return &reflect;
case ColourGradient::SpreadMethod::repeat: return &repeat;
}
jassertfalse;
return &pad;
}
};
/* Helper class for implementing https://skia.org/docs/dev/design/conical/
Variable naming follows the notations used in the article whenever makes sense.
---
https://www.w3.org/TR/2015/WD-SVG2-20150915/pservers.html#RadialGradients
*/
class TwoPointConicalGradient
{
public:
static inline const auto regularisationTolerance = absoluteTolerance (0.001f);
static inline const auto inputTolerance = relativeTolerance (0.001f);
/* Returns an object if this class can compute the provided gradient object.
Returns std::nullopt, if the provided parameters would be a degenerate case for the
two-point conical equations.
*/
static std::optional<TwoPointConicalGradient> create (const ColourGradient& gradient);
/* Returns std::nullopt if the point is outside the calculable range.
This happens if the start circle touches, or falls outside the end circle, and the point is
outside the cone.
*/
std::optional<float> calculateWeight (Point<float> p) const;
private:
TwoPointConicalGradient (GradientCircle startCircle, GradientCircle endCircle);
static bool isConicalGradientApplicable (const GradientCircle& s, const GradientCircle& e);
bool swapped = false;
GradientCircle c0, c1;
float f {};
AffineTransform regularisationTransform;
};
} // namespace juce::detail
@@ -0,0 +1,45 @@
/*
==============================================================================
This file is part of the JUCE framework.
Copyright (c) Raw Material Software Limited
JUCE is an open source framework subject to commercial or open source
licensing.
By downloading, installing, or using the JUCE framework, or combining the
JUCE framework with any other source code, object code, content or any other
copyrightable work, you agree to the terms of the JUCE End User Licence
Agreement, and all incorporated terms including the JUCE Privacy Policy and
the JUCE Website Terms of Service, as applicable, which will bind you. If you
do not agree to the terms of these agreements, we will not license the JUCE
framework to you, and you must discontinue the installation or download
process and cease use of the JUCE framework.
JUCE End User Licence Agreement: https://juce.com/legal/juce-9-licence/
JUCE Privacy Policy: https://juce.com/juce-privacy-policy
JUCE Website Terms of Service: https://juce.com/juce-website-terms-of-service/
Or:
You may also use this code under the terms of the AGPLv3:
https://www.gnu.org/licenses/agpl-3.0.en.html
THE JUCE FRAMEWORK IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL
WARRANTIES, WHETHER EXPRESSED OR IMPLIED, INCLUDING WARRANTY OF
MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, ARE DISCLAIMED.
==============================================================================
*/
namespace juce::detail
{
struct UnicodeHelpers
{
UnicodeHelpers() = delete;
static std::vector<int> getLineBreaks (const String& data);
};
} // namespace juce::detail