2023-02-05 20:36:51 +00:00
|
|
|
#include "TextParser.h"
|
2023-07-30 13:01:56 +00:00
|
|
|
#include "../svg/SvgParser.h"
|
2025-01-26 16:28:35 +00:00
|
|
|
#include "../PluginProcessor.h"
|
2023-02-05 20:36:51 +00:00
|
|
|
|
|
|
|
|
2025-01-26 16:28:35 +00:00
|
|
|
TextParser::TextParser(OscirenderAudioProcessor &p, juce::String text, juce::Font font) : audioProcessor(p), text(text) {
|
|
|
|
parse(text, font);
|
2023-02-05 20:36:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TextParser::~TextParser() {
|
|
|
|
}
|
|
|
|
|
2025-01-26 16:28:35 +00:00
|
|
|
void TextParser::parse(juce::String text, juce::Font font) {
|
|
|
|
lastFont = font;
|
|
|
|
juce::Path textPath;
|
|
|
|
juce::GlyphArrangement glyphs;
|
|
|
|
glyphs.addFittedText(font, text, -2, -2, 4, 4, juce::Justification::centred, 2);
|
|
|
|
glyphs.createPath(textPath);
|
|
|
|
|
|
|
|
shapes = std::vector<std::unique_ptr<Shape>>();
|
|
|
|
SvgParser::pathToShapes(textPath, shapes);
|
|
|
|
}
|
|
|
|
|
2023-02-05 20:36:51 +00:00
|
|
|
std::vector<std::unique_ptr<Shape>> TextParser::draw() {
|
2025-01-26 16:28:35 +00:00
|
|
|
// reparse text if font changes
|
|
|
|
if (audioProcessor.font != lastFont) {
|
|
|
|
parse(text, audioProcessor.font);
|
|
|
|
}
|
|
|
|
|
2023-02-05 20:36:51 +00:00
|
|
|
// clone with deep copy
|
|
|
|
std::vector<std::unique_ptr<Shape>> tempShapes;
|
|
|
|
|
|
|
|
for (auto& shape : shapes) {
|
|
|
|
tempShapes.push_back(shape->clone());
|
|
|
|
}
|
|
|
|
return tempShapes;
|
|
|
|
}
|