diff --git a/data/fonts/Inconsolata-VariableFont_wdth,wght.ttf b/data/fonts/Inconsolata-VariableFont_wdth,wght.ttf new file mode 100644 index 0000000..2739432 Binary files /dev/null and b/data/fonts/Inconsolata-VariableFont_wdth,wght.ttf differ diff --git a/data/fonts/IndieFlower-Regular.ttf b/data/fonts/IndieFlower-Regular.ttf new file mode 100644 index 0000000..3774ef5 Binary files /dev/null and b/data/fonts/IndieFlower-Regular.ttf differ diff --git a/data/fonts/NotoEmoji-VariableFont_wght.ttf b/data/fonts/NotoEmoji-VariableFont_wght.ttf new file mode 100644 index 0000000..1c20a23 Binary files /dev/null and b/data/fonts/NotoEmoji-VariableFont_wght.ttf differ diff --git a/data/fonts/NotoKufiArabic-VariableFont_wght.ttf b/data/fonts/NotoKufiArabic-VariableFont_wght.ttf new file mode 100644 index 0000000..9d71153 Binary files /dev/null and b/data/fonts/NotoKufiArabic-VariableFont_wght.ttf differ diff --git a/data/third_party_licenses/Inconsolata b/data/third_party_licenses/Inconsolata new file mode 100644 index 0000000..55533e1 --- /dev/null +++ b/data/third_party_licenses/Inconsolata @@ -0,0 +1,93 @@ +Copyright 2006 The Inconsolata Project Authors + +This Font Software is licensed under the SIL Open Font License, Version 1.1. +This license is copied below, and is also available with a FAQ at: +https://openfontlicense.org + + +----------------------------------------------------------- +SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 +----------------------------------------------------------- + +PREAMBLE +The goals of the Open Font License (OFL) are to stimulate worldwide +development of collaborative font projects, to support the font creation +efforts of academic and linguistic communities, and to provide a free and +open framework in which fonts may be shared and improved in partnership +with others. + +The OFL allows the licensed fonts to be used, studied, modified and +redistributed freely as long as they are not sold by themselves. The +fonts, including any derivative works, can be bundled, embedded, +redistributed and/or sold with any software provided that any reserved +names are not used by derivative works. The fonts and derivatives, +however, cannot be released under any other type of license. The +requirement for fonts to remain under this license does not apply +to any document created using the fonts or their derivatives. + +DEFINITIONS +"Font Software" refers to the set of files released by the Copyright +Holder(s) under this license and clearly marked as such. This may +include source files, build scripts and documentation. + +"Reserved Font Name" refers to any names specified as such after the +copyright statement(s). + +"Original Version" refers to the collection of Font Software components as +distributed by the Copyright Holder(s). + +"Modified Version" refers to any derivative made by adding to, deleting, +or substituting -- in part or in whole -- any of the components of the +Original Version, by changing formats or by porting the Font Software to a +new environment. + +"Author" refers to any designer, engineer, programmer, technical +writer or other person who contributed to the Font Software. + +PERMISSION & CONDITIONS +Permission is hereby granted, free of charge, to any person obtaining +a copy of the Font Software, to use, study, copy, merge, embed, modify, +redistribute, and sell modified and unmodified copies of the Font +Software, subject to the following conditions: + +1) Neither the Font Software nor any of its individual components, +in Original or Modified Versions, may be sold by itself. + +2) Original or Modified Versions of the Font Software may be bundled, +redistributed and/or sold with any software, provided that each copy +contains the above copyright notice and this license. These can be +included either as stand-alone text files, human-readable headers or +in the appropriate machine-readable metadata fields within text or +binary files as long as those fields can be easily viewed by the user. + +3) No Modified Version of the Font Software may use the Reserved Font +Name(s) unless explicit written permission is granted by the corresponding +Copyright Holder. This restriction only applies to the primary font name as +presented to the users. + +4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font +Software shall not be used to promote, endorse or advertise any +Modified Version, except to acknowledge the contribution(s) of the +Copyright Holder(s) and the Author(s) or with their explicit written +permission. + +5) The Font Software, modified or unmodified, in part or in whole, +must be distributed entirely under this license, and must not be +distributed under any other license. The requirement for fonts to +remain under this license does not apply to any document created +using the Font Software. + +TERMINATION +This license becomes null and void if any of the above conditions are +not met. + +DISCLAIMER +THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT +OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE +COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL +DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM +OTHER DEALINGS IN THE FONT SOFTWARE. diff --git a/data/third_party_licenses/Indie Flower b/data/third_party_licenses/Indie Flower new file mode 100644 index 0000000..2d9ac5d --- /dev/null +++ b/data/third_party_licenses/Indie Flower @@ -0,0 +1,93 @@ +Copyright (c) 2010, Kimberly Geswein (kimberlygeswein.com) + +This Font Software is licensed under the SIL Open Font License, Version 1.1. +This license is copied below, and is also available with a FAQ at: +https://openfontlicense.org + + +----------------------------------------------------------- +SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 +----------------------------------------------------------- + +PREAMBLE +The goals of the Open Font License (OFL) are to stimulate worldwide +development of collaborative font projects, to support the font creation +efforts of academic and linguistic communities, and to provide a free and +open framework in which fonts may be shared and improved in partnership +with others. + +The OFL allows the licensed fonts to be used, studied, modified and +redistributed freely as long as they are not sold by themselves. The +fonts, including any derivative works, can be bundled, embedded, +redistributed and/or sold with any software provided that any reserved +names are not used by derivative works. The fonts and derivatives, +however, cannot be released under any other type of license. The +requirement for fonts to remain under this license does not apply +to any document created using the fonts or their derivatives. + +DEFINITIONS +"Font Software" refers to the set of files released by the Copyright +Holder(s) under this license and clearly marked as such. This may +include source files, build scripts and documentation. + +"Reserved Font Name" refers to any names specified as such after the +copyright statement(s). + +"Original Version" refers to the collection of Font Software components as +distributed by the Copyright Holder(s). + +"Modified Version" refers to any derivative made by adding to, deleting, +or substituting -- in part or in whole -- any of the components of the +Original Version, by changing formats or by porting the Font Software to a +new environment. + +"Author" refers to any designer, engineer, programmer, technical +writer or other person who contributed to the Font Software. + +PERMISSION & CONDITIONS +Permission is hereby granted, free of charge, to any person obtaining +a copy of the Font Software, to use, study, copy, merge, embed, modify, +redistribute, and sell modified and unmodified copies of the Font +Software, subject to the following conditions: + +1) Neither the Font Software nor any of its individual components, +in Original or Modified Versions, may be sold by itself. + +2) Original or Modified Versions of the Font Software may be bundled, +redistributed and/or sold with any software, provided that each copy +contains the above copyright notice and this license. These can be +included either as stand-alone text files, human-readable headers or +in the appropriate machine-readable metadata fields within text or +binary files as long as those fields can be easily viewed by the user. + +3) No Modified Version of the Font Software may use the Reserved Font +Name(s) unless explicit written permission is granted by the corresponding +Copyright Holder. This restriction only applies to the primary font name as +presented to the users. + +4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font +Software shall not be used to promote, endorse or advertise any +Modified Version, except to acknowledge the contribution(s) of the +Copyright Holder(s) and the Author(s) or with their explicit written +permission. + +5) The Font Software, modified or unmodified, in part or in whole, +must be distributed entirely under this license, and must not be +distributed under any other license. The requirement for fonts to +remain under this license does not apply to any document created +using the Font Software. + +TERMINATION +This license becomes null and void if any of the above conditions are +not met. + +DISCLAIMER +THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT +OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE +COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL +DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM +OTHER DEALINGS IN THE FONT SOFTWARE. diff --git a/data/third_party_licenses/Noto Emoji b/data/third_party_licenses/Noto Emoji new file mode 100644 index 0000000..0f08295 --- /dev/null +++ b/data/third_party_licenses/Noto Emoji @@ -0,0 +1,93 @@ +Copyright 2013 Google LLC + +This Font Software is licensed under the SIL Open Font License, Version 1.1. +This license is copied below, and is also available with a FAQ at: +https://openfontlicense.org + + +----------------------------------------------------------- +SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 +----------------------------------------------------------- + +PREAMBLE +The goals of the Open Font License (OFL) are to stimulate worldwide +development of collaborative font projects, to support the font creation +efforts of academic and linguistic communities, and to provide a free and +open framework in which fonts may be shared and improved in partnership +with others. + +The OFL allows the licensed fonts to be used, studied, modified and +redistributed freely as long as they are not sold by themselves. The +fonts, including any derivative works, can be bundled, embedded, +redistributed and/or sold with any software provided that any reserved +names are not used by derivative works. The fonts and derivatives, +however, cannot be released under any other type of license. The +requirement for fonts to remain under this license does not apply +to any document created using the fonts or their derivatives. + +DEFINITIONS +"Font Software" refers to the set of files released by the Copyright +Holder(s) under this license and clearly marked as such. This may +include source files, build scripts and documentation. + +"Reserved Font Name" refers to any names specified as such after the +copyright statement(s). + +"Original Version" refers to the collection of Font Software components as +distributed by the Copyright Holder(s). + +"Modified Version" refers to any derivative made by adding to, deleting, +or substituting -- in part or in whole -- any of the components of the +Original Version, by changing formats or by porting the Font Software to a +new environment. + +"Author" refers to any designer, engineer, programmer, technical +writer or other person who contributed to the Font Software. + +PERMISSION & CONDITIONS +Permission is hereby granted, free of charge, to any person obtaining +a copy of the Font Software, to use, study, copy, merge, embed, modify, +redistribute, and sell modified and unmodified copies of the Font +Software, subject to the following conditions: + +1) Neither the Font Software nor any of its individual components, +in Original or Modified Versions, may be sold by itself. + +2) Original or Modified Versions of the Font Software may be bundled, +redistributed and/or sold with any software, provided that each copy +contains the above copyright notice and this license. These can be +included either as stand-alone text files, human-readable headers or +in the appropriate machine-readable metadata fields within text or +binary files as long as those fields can be easily viewed by the user. + +3) No Modified Version of the Font Software may use the Reserved Font +Name(s) unless explicit written permission is granted by the corresponding +Copyright Holder. This restriction only applies to the primary font name as +presented to the users. + +4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font +Software shall not be used to promote, endorse or advertise any +Modified Version, except to acknowledge the contribution(s) of the +Copyright Holder(s) and the Author(s) or with their explicit written +permission. + +5) The Font Software, modified or unmodified, in part or in whole, +must be distributed entirely under this license, and must not be +distributed under any other license. The requirement for fonts to +remain under this license does not apply to any document created +using the Font Software. + +TERMINATION +This license becomes null and void if any of the above conditions are +not met. + +DISCLAIMER +THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT +OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE +COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL +DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM +OTHER DEALINGS IN THE FONT SOFTWARE. diff --git a/data/third_party_licenses/Noto Kufi Arabic b/data/third_party_licenses/Noto Kufi Arabic new file mode 100644 index 0000000..8dd72cd --- /dev/null +++ b/data/third_party_licenses/Noto Kufi Arabic @@ -0,0 +1,93 @@ +Copyright 2022 The Noto Project Authors (https://github.com/notofonts/arabic) + +This Font Software is licensed under the SIL Open Font License, Version 1.1. +This license is copied below, and is also available with a FAQ at: +https://openfontlicense.org + + +----------------------------------------------------------- +SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 +----------------------------------------------------------- + +PREAMBLE +The goals of the Open Font License (OFL) are to stimulate worldwide +development of collaborative font projects, to support the font creation +efforts of academic and linguistic communities, and to provide a free and +open framework in which fonts may be shared and improved in partnership +with others. + +The OFL allows the licensed fonts to be used, studied, modified and +redistributed freely as long as they are not sold by themselves. The +fonts, including any derivative works, can be bundled, embedded, +redistributed and/or sold with any software provided that any reserved +names are not used by derivative works. The fonts and derivatives, +however, cannot be released under any other type of license. The +requirement for fonts to remain under this license does not apply +to any document created using the fonts or their derivatives. + +DEFINITIONS +"Font Software" refers to the set of files released by the Copyright +Holder(s) under this license and clearly marked as such. This may +include source files, build scripts and documentation. + +"Reserved Font Name" refers to any names specified as such after the +copyright statement(s). + +"Original Version" refers to the collection of Font Software components as +distributed by the Copyright Holder(s). + +"Modified Version" refers to any derivative made by adding to, deleting, +or substituting -- in part or in whole -- any of the components of the +Original Version, by changing formats or by porting the Font Software to a +new environment. + +"Author" refers to any designer, engineer, programmer, technical +writer or other person who contributed to the Font Software. + +PERMISSION & CONDITIONS +Permission is hereby granted, free of charge, to any person obtaining +a copy of the Font Software, to use, study, copy, merge, embed, modify, +redistribute, and sell modified and unmodified copies of the Font +Software, subject to the following conditions: + +1) Neither the Font Software nor any of its individual components, +in Original or Modified Versions, may be sold by itself. + +2) Original or Modified Versions of the Font Software may be bundled, +redistributed and/or sold with any software, provided that each copy +contains the above copyright notice and this license. These can be +included either as stand-alone text files, human-readable headers or +in the appropriate machine-readable metadata fields within text or +binary files as long as those fields can be easily viewed by the user. + +3) No Modified Version of the Font Software may use the Reserved Font +Name(s) unless explicit written permission is granted by the corresponding +Copyright Holder. This restriction only applies to the primary font name as +presented to the users. + +4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font +Software shall not be used to promote, endorse or advertise any +Modified Version, except to acknowledge the contribution(s) of the +Copyright Holder(s) and the Author(s) or with their explicit written +permission. + +5) The Font Software, modified or unmodified, in part or in whole, +must be distributed entirely under this license, and must not be +distributed under any other license. The requirement for fonts to +remain under this license does not apply to any document created +using the Font Software. + +TERMINATION +This license becomes null and void if any of the above conditions are +not met. + +DISCLAIMER +THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT +OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE +COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL +DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM +OTHER DEALINGS IN THE FONT SOFTWARE. diff --git a/src/FontData.cpp b/src/FontData.cpp index 99f4125..a310856 100644 --- a/src/FontData.cpp +++ b/src/FontData.cpp @@ -15,6 +15,10 @@ #include #endif +#include + +bool fallbackOnEmoji = false; + FontData::FontData() { #ifdef __EMSCRIPTEN__ @@ -34,8 +38,14 @@ FontData::FontData() map["Roboto"] = defaultFontMgr->makeFromFile("data/fonts/Roboto-variable.ttf"); collection = sk_make_sp(); - collection->setDefaultFontManager(defaultFontMgr, {SkString{"Roboto"}}); + collection->setDefaultFontManager(defaultFontMgr, std::vector{SkString{"Roboto"}, SkString{"Noto Emoji"}, SkString{"Noto Kufi Arabic"}}); collection->setDynamicFontManager(localFontMgr); + std::string s = "🙂"; + const char* sPtr = s.data(); + SkFontStyle defaultStyle; + SkString defaultLocale("en"); + auto defaultEmojiFallback = collection->defaultEmojiFallback(SkUTF::NextUTF8(&sPtr, s.c_str() + s.length()), defaultStyle, defaultLocale); + fallbackOnEmoji = !defaultEmojiFallback; } FontData::~FontData() { @@ -47,3 +57,21 @@ Vector2f get_str_font_bounds(const SkFont& font, const std::string& str) { float nextText = font.measureText(str.data(), str.length(), SkTextEncoding::kUTF8, nullptr); return Vector2f{nextText, - metrics.fAscent + metrics.fDescent}; } + +const std::vector& get_default_font_families() { + static std::vector defaultFontFamilies; + if(defaultFontFamilies.empty()) { + defaultFontFamilies.emplace_back("Roboto"); + if(fallbackOnEmoji) + defaultFontFamilies.emplace_back("Noto Emoji"); + defaultFontFamilies.emplace_back("Noto Kufi Arabic"); + } + return defaultFontFamilies; +} + +void push_default_font_families(std::vector& fontFamilies) { + fontFamilies.emplace_back("Roboto"); + if(fallbackOnEmoji) + fontFamilies.emplace_back("Noto Emoji"); + fontFamilies.emplace_back("Noto Kufi Arabic"); +} diff --git a/src/FontData.hpp b/src/FontData.hpp index 806fa49..82c9494 100644 --- a/src/FontData.hpp +++ b/src/FontData.hpp @@ -18,3 +18,5 @@ struct FontData { }; Vector2f get_str_font_bounds(const SkFont& font, const std::string& str); +const std::vector& get_default_font_families(); +void push_default_font_families(std::vector& fontFamilies); diff --git a/src/GUIStuff/Elements/FontPicker.cpp b/src/GUIStuff/Elements/FontPicker.cpp index afae1cc..783811d 100644 --- a/src/GUIStuff/Elements/FontPicker.cpp +++ b/src/GUIStuff/Elements/FontPicker.cpp @@ -140,13 +140,13 @@ bool GUIStuff::FontPicker::update(UpdateInputData& io, std::string* fontName, GU entryColor = io.theme->backColor1; CLAY({ .layout = { - .sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_GROW(0)}, + .sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_FIXED(25)}, .padding = {.left = 2, .right = 2}, .childAlignment = {.x = CLAY_ALIGN_X_LEFT, .y = CLAY_ALIGN_Y_CENTER} }, .backgroundColor = convert_vec4(entryColor) }) { - gui->text_paragraph("font name", std::move(p), std::numeric_limits::max()); + gui->text_paragraph("font name", std::move(p), 10000.0f); // Setting width to numeric_limits::max will lead to multiplying it by any number greater than 1 to = infinity, which will cause issues if(io.mouse.leftClick && Clay_Hovered()) { *fontName = sortedFontList[i]; diff --git a/src/GUIStuff/Elements/TextBox.hpp b/src/GUIStuff/Elements/TextBox.hpp index f7e3581..962e81c 100644 --- a/src/GUIStuff/Elements/TextBox.hpp +++ b/src/GUIStuff/Elements/TextBox.hpp @@ -3,6 +3,7 @@ #include "../../RichText/TextBox.hpp" #include #include +#include "../../FontData.hpp" namespace GUIStuff { @@ -17,14 +18,13 @@ template class TextBox : public Element { data = newData; fromStr = newFromStr; toStr = newToStr; - singleLine = newSingleLine; force_update_textbox(io, false); - textbox->set_width(singleLine ? std::numeric_limits::max() : bb.width()); + textbox->set_width(std::numeric_limits::max()); CLAY({ .layout = { - .sizing = {.width = CLAY_SIZING_GROW(static_cast(io.fontSize * 2)), .height = singleLine ? CLAY_SIZING_FIXED(static_cast(io.fontSize * 1.25f)) : CLAY_SIZING_GROW(static_cast(io.fontSize * 1.25f))} + .sizing = {.width = CLAY_SIZING_GROW(static_cast(io.fontSize * 2)), .height = CLAY_SIZING_FIXED(static_cast(io.fontSize * 1.25f))} }, .custom = { .customData = this } }) { @@ -71,7 +71,9 @@ template class TextBox : public Element { canvas->clipRect(SkRect::MakeXYWH(bb.min.x(), bb.min.y(), bb.width(), bb.height())); - canvas->translate(bb.min.x() + 2.0f, bb.min.y()); + float yOffset = bb.height() * 0.5f; + yOffset -= textbox->get_height() * 0.5f; + canvas->translate(bb.min.x() + 2.0f, bb.min.y() + yOffset); RichText::TextBox::PaintOpts paintOpts; if(selection.selected) @@ -79,9 +81,7 @@ template class TextBox : public Element { paintOpts.cursorColor = {io.theme->fillColor1.fR, io.theme->fillColor1.fG, io.theme->fillColor1.fB}; skia::textlayout::TextStyle tStyle; - std::vector families; - families.emplace_back("Roboto"); - tStyle.setFontFamilies(families); + tStyle.setFontFamilies(get_default_font_families()); tStyle.setFontSize(io.fontSize); tStyle.setForegroundPaint(SkPaint{io.theme->frontColor1}); textbox->set_initial_text_style(tStyle); @@ -99,7 +99,7 @@ template class TextBox : public Element { textbox = std::make_shared(); textbox->set_font_collection(io.fontCollection); - textbox->set_allow_newlines(!singleLine); + textbox->set_allow_newlines(false); cur = std::make_shared(); @@ -120,8 +120,6 @@ template class TextBox : public Element { T* data = nullptr; T oldData; - bool singleLine = true; - std::function(const std::string&)> fromStr; std::function toStr; diff --git a/src/GUIStuff/GUIManager.cpp b/src/GUIStuff/GUIManager.cpp index f66f551..8311e7c 100644 --- a/src/GUIStuff/GUIManager.cpp +++ b/src/GUIStuff/GUIManager.cpp @@ -24,6 +24,7 @@ #include #include #include +#include "../FontData.hpp" namespace GUIStuff { @@ -43,7 +44,7 @@ Clay_Dimensions GUIManager::clay_skia_measure_text(Clay_StringSlice str, Clay_Te pStyle.setTextAlign(skia::textlayout::TextAlign::kLeft); skia::textlayout::TextStyle tStyle; tStyle.setFontSize(config->fontSize); - tStyle.setFontFamilies({SkString{"Roboto"}}); + tStyle.setFontFamilies(get_default_font_families()); pStyle.setTextStyle(tStyle); skia::textlayout::ParagraphBuilderImpl a(pStyle, window->io->fontCollection, SkUnicodes::ICU::Make()); @@ -116,7 +117,7 @@ void GUIManager::draw(SkCanvas* canvas) { pStyle.setTextAlign(skia::textlayout::TextAlign::kLeft); skia::textlayout::TextStyle tStyle; tStyle.setFontSize(config->fontSize); - tStyle.setFontFamilies({SkString{"Roboto"}}); + tStyle.setFontFamilies(get_default_font_families()); tStyle.setColor(convert_vec4(config->textColor).toSkColor()); pStyle.setTextStyle(tStyle); diff --git a/src/GUIStuff/GUIManager.hpp b/src/GUIStuff/GUIManager.hpp index d874522..34730e2 100644 --- a/src/GUIStuff/GUIManager.hpp +++ b/src/GUIStuff/GUIManager.hpp @@ -19,7 +19,6 @@ using namespace Eigen; - namespace GUIStuff { class GUIManager { diff --git a/src/InputManager.cpp b/src/InputManager.cpp index 0708b6d..30b5e5c 100644 --- a/src/InputManager.cpp +++ b/src/InputManager.cpp @@ -52,8 +52,8 @@ InputManager::InputManager() { // Without this, SDL eats the CTRL-V event that initiates the paste event // https://github.com/pthom/hello_imgui/issues/3#issuecomment-1564536870 EM_ASM({ - window.addEventListener('keydown', function(event){ - if (event.ctrlKey && event.key == 'v') { + window.addEventListener('keydown', function(event) { + if((event.ctrlKey || event.metaKey) && (event.key == 'v' || event.code == 'KeyV')) { if(Module["ccall"]('is_text_input_happening', 'number', [], []) === 1) event.stopImmediatePropagation(); } diff --git a/src/RichText/TextBox.cpp b/src/RichText/TextBox.cpp index 6ef4242..33e5995 100644 --- a/src/RichText/TextBox.cpp +++ b/src/RichText/TextBox.cpp @@ -771,6 +771,11 @@ void TextBox::set_width(float newWidth) { } } +float TextBox::get_height() { + rebuild(); + return paragraphs.back().heightOffset + paragraphs.back().p->getHeight(); +} + void TextBox::set_allow_newlines(bool allow) { newlinesAllowed = allow; } @@ -795,6 +800,16 @@ void TextBox::rebuild() { ParagraphData& pData = paragraphs[pIndex]; skia::textlayout::ParagraphStyle pStyle = pData.pStyleData.get_paragraph_style(); pStyle.setTextStyle(tStyle); + + if(!newlinesAllowed) { + pStyle.setTextHeightBehavior(skia::textlayout::kDisableAll); + + skia::textlayout::StrutStyle strutStyle; + strutStyle.setStrutEnabled(true); + strutStyle.setForceStrutHeight(true); + pStyle.setStrutStyle(strutStyle); + } + size_t tIndex = 0; skia::textlayout::ParagraphBuilderImpl a(pStyle, fontCollection, SkUnicodes::ICU::Make()); diff --git a/src/RichText/TextBox.hpp b/src/RichText/TextBox.hpp index df91308..80405d8 100644 --- a/src/RichText/TextBox.hpp +++ b/src/RichText/TextBox.hpp @@ -99,6 +99,7 @@ class TextBox { void set_font_collection(const sk_sp& fC); void paint(SkCanvas* canvas, const PaintOpts& paintOpts); void set_allow_newlines(bool allow); + float get_height(); enum class InputKey { LEFT, diff --git a/src/RichText/TextStyleModifier.cpp b/src/RichText/TextStyleModifier.cpp index a0b2b03..ef1c2f7 100644 --- a/src/RichText/TextStyleModifier.cpp +++ b/src/RichText/TextStyleModifier.cpp @@ -3,6 +3,7 @@ #include #include #include +#include "../FontData.hpp" #define WEIGHT_VALUE_MODIFIER 100 @@ -190,7 +191,7 @@ void FontFamiliesTextStyleModifier::load(cereal::PortableBinaryInputArchive& a) void FontFamiliesTextStyleModifier::modify_text_style(skia::textlayout::TextStyle& style) const { auto familiesToPush = families; - familiesToPush.emplace_back("Roboto"); + push_default_font_families(familiesToPush); style.setFontFamilies(familiesToPush); } diff --git a/src/Toolbar.cpp b/src/Toolbar.cpp index 650809f..fddd181 100644 --- a/src/Toolbar.cpp +++ b/src/Toolbar.cpp @@ -1,6 +1,7 @@ #include "Toolbar.hpp" #include "DrawingProgram/DrawingProgramToolBase.hpp" #include "DrawingProgram/ScreenshotTool.hpp" +#include "FontData.hpp" #include "Helpers/ConvertVec.hpp" #include "Helpers/FileDownloader.hpp" #include "Helpers/Networking/NetLibrary.hpp" @@ -823,7 +824,7 @@ std::unique_ptr Toolbar::build_paragraph_from_chat_ pStyle.setTextAlign(skia::textlayout::TextAlign::kLeft); skia::textlayout::TextStyle tStyle; tStyle.setFontSize(io->fontSize); - tStyle.setFontFamilies({SkString{"Roboto"}}); + tStyle.setFontFamilies(get_default_font_families()); tStyle.setFontStyle(SkFontStyle::Bold()); tStyle.setForegroundColor(SkPaint{color_mul_alpha(message.type == ChatMessage::JOIN ? io->theme->warningColor : io->theme->frontColor1, alpha)}); pStyle.setTextStyle(tStyle); @@ -1400,7 +1401,6 @@ void Toolbar::options_menu() { gui.push_id("general settings"); gui.input_text_field("display name input", "Display Name", &main.displayName); main.update_display_names(); - gui.text_label_light("Note: Changes in display name dont affect canvases that are connected online"); SkColor4f newBackColor{main.defaultCanvasBackgroundColor.x(), main.defaultCanvasBackgroundColor.y(), main.defaultCanvasBackgroundColor.z(), 1.0f}; gui.color_picker_button_field("defaultCanvasBackgroundColor", "Default canvas background color", &newBackColor, false); main.defaultCanvasBackgroundColor = convert_vec3(newBackColor);