Skip to content

Commit 070187d

Browse files
committed
Fix [note] slowness
1 parent 7c98784 commit 070187d

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

Source/Objects/NoteObject.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,14 +429,21 @@ class NoteObject final : public ObjectBase {
429429
if (typefaceName.isEmpty() || typefaceName == "Inter") {
430430
return Fonts::getVariableFont().withStyle(style).withHeight(fontHeight);
431431
}
432+
433+
// Check if a system typeface exists, before we start searching for a font file
434+
// We do this because it's the most common case, and finding font files is slow
435+
if(Font::findAllTypefaceNames().contains(typefaceName))
436+
{
437+
return { typefaceName, static_cast<float>(fontHeight), style };
438+
}
432439

433440
auto currentFile = cnv->patch.getCurrentFile();
434441
if (currentFile.exists() && !currentFile.isRoot()) {
435442
// Check if there is a patch font loaded via the patch loading
436443
if (auto const patchFont = Fonts::findFont(currentFile, typefaceName); patchFont.has_value())
437444
return patchFont->withStyle(style).withHeight(fontHeight);
438445
}
439-
446+
440447
return { typefaceName, static_cast<float>(fontHeight), style };
441448
}
442449

Source/Utility/Fonts.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,7 @@ struct Fonts {
7070

7171
static std::optional<Font> findFont(File const& dirToSearch, String const& typefaceFileName)
7272
{
73-
Array<File> fontFiles = dirToSearch.getParentDirectory().findChildFiles(File::findFiles, true, "*.ttf;*.otf;");
74-
73+
Array<File> fontFiles = dirToSearch.getParentDirectory().findChildFiles(File::findFiles, false, "*.ttf;*.otf;");
7574
for (auto font : fontFiles) {
7675
if (font.getFileNameWithoutExtension() == typefaceFileName) {
7776
auto it = fontTable.find(font.getFullPathName());

0 commit comments

Comments
 (0)