diff --git a/CMakeLists.txt b/CMakeLists.txt index 4c8841811..763e1e9a0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -256,7 +256,7 @@ if( MSVC ) # String pooling # Function-level linking # Disable run-time type information - set( ALL_C_FLAGS "/GF /Gy /permissive-" ) + set( ALL_C_FLAGS "/GF /Gy /permissive- /utf-8" ) if ( HAVE_VULKAN ) set( ALL_C_FLAGS "${ALL_C_FLAGS} /DHAVE_VULKAN" ) diff --git a/libraries/ZWidget/include/zwidget/core/resourcedata.h b/libraries/ZWidget/include/zwidget/core/resourcedata.h index 1aeb132fd..5eaedcfae 100644 --- a/libraries/ZWidget/include/zwidget/core/resourcedata.h +++ b/libraries/ZWidget/include/zwidget/core/resourcedata.h @@ -4,5 +4,12 @@ #include #include -std::vector LoadWidgetFontData(const std::string& name); +struct SingleFontData +{ + std::vector fontdata; + std::vector> ranges; + int language = -1; // mainly useful if we start supporting Chinese so that we can use another font there than for Japanese. +}; + +std::vector LoadWidgetFontData(const std::string& name); std::vector LoadWidgetImageData(const std::string& name); diff --git a/libraries/ZWidget/include/zwidget/widgets/textedit/textedit.h b/libraries/ZWidget/include/zwidget/widgets/textedit/textedit.h index c7dcbf5de..e2c6c760c 100644 --- a/libraries/ZWidget/include/zwidget/widgets/textedit/textedit.h +++ b/libraries/ZWidget/include/zwidget/widgets/textedit/textedit.h @@ -149,7 +149,7 @@ private: bool select_all_on_focus_gain = false; - std::shared_ptr font = Font::Create("Segoe UI", 12.0); + std::shared_ptr font = Font::Create("NotoSans", 12.0); template static T clamp(T val, T minval, T maxval) { return std::max(std::min(val, maxval), minval); } diff --git a/libraries/ZWidget/src/core/canvas.cpp b/libraries/ZWidget/src/core/canvas.cpp index c92101b26..7e7a6790c 100644 --- a/libraries/ZWidget/src/core/canvas.cpp +++ b/libraries/ZWidget/src/core/canvas.cpp @@ -36,9 +36,9 @@ public: class CanvasFont { public: - CanvasFont(const std::string& fontname, double height) : fontname(fontname), height(height) + CanvasFont(const std::string& fontname, double height, std::vector& _data) : fontname(fontname), height(height) { - data = LoadWidgetFontData(fontname); + data = std::move(_data); loadFont(data.data(), data.size()); try @@ -152,6 +152,65 @@ private: std::vector data; }; +class CanvasFontGroup +{ +public: + struct SingleFont + { + std::unique_ptr font; + std::vector> ranges; + int language; // mainly useful if we start supporting Chinese so that we can use another font there than for Japanese. + }; + CanvasFontGroup(const std::string& fontname, double height) : height(height) + { + auto fontdata = LoadWidgetFontData(fontname); + fonts.resize(fontdata.size()); + for (size_t i = 0; i < fonts.size(); i++) + { + fonts[i].font = std::make_unique(fontname, height, fontdata[i].fontdata); + fonts[i].ranges = std::move(fontdata[i].ranges); + fonts[i].language = fontdata[i].language; + } + } + + CanvasGlyph* getGlyph(uint32_t utfchar) + { + if (utfchar >= 0x530 && utfchar < 0x590) + { + int a = 0; + } + for (auto& fd : fonts) + { + bool get = false; + if (fd.ranges.size() == 0) get = true; + else for (auto r : fd.ranges) + { + if (utfchar >= r.first && utfchar <= r.second) + { + get = true; + break; + } + } + if (get) + { + auto g = fd.font->getGlyph(utfchar); + if (g) return g; + } + } + + return nullptr; + } + + SFT_LMetrics& GetTextMetrics() + { + return fonts[0].font->textmetrics; + } + + double height; + std::vector fonts; + +}; + class BitmapCanvas : public Canvas { public: @@ -211,7 +270,7 @@ public: DisplayWindow* window = nullptr; - std::unique_ptr font; + std::unique_ptr font; std::unique_ptr whiteTexture; Point origin; @@ -230,7 +289,7 @@ BitmapCanvas::BitmapCanvas(DisplayWindow* window) : window(window) uiscale = window->GetDpiScale(); uint32_t white = 0xffffffff; whiteTexture = createTexture(1, 1, &white); - font = std::make_unique("Segoe UI", 13.0*uiscale); + font = std::make_unique("NotoSans", 13.0*uiscale); } BitmapCanvas::~BitmapCanvas() @@ -411,7 +470,7 @@ void BitmapCanvas::drawText(const Point& pos, const Colorf& color, const std::st Rect BitmapCanvas::measureText(const std::string& text) { double x = 0.0; - double y = font->textmetrics.ascender - font->textmetrics.descender; + double y = font->GetTextMetrics().ascender - font->GetTextMetrics().descender; UTF8Reader reader(text.data(), text.size()); while (!reader.is_end()) @@ -433,8 +492,9 @@ VerticalTextPosition BitmapCanvas::verticalTextAlign() { VerticalTextPosition align; align.top = 0.0f; - align.baseline = font->textmetrics.ascender / uiscale; - align.bottom = (font->textmetrics.ascender - font->textmetrics.descender) / uiscale; + auto tm = font->GetTextMetrics(); + align.baseline = tm.ascender / uiscale; + align.bottom = (tm.ascender - tm.descender) / uiscale; return align; } diff --git a/src/common/widgets/launcherwindow.cpp b/src/common/widgets/launcherwindow.cpp index e37edd523..29fb30018 100644 --- a/src/common/widgets/launcherwindow.cpp +++ b/src/common/widgets/launcherwindow.cpp @@ -1,4 +1,3 @@ - #include "launcherwindow.h" #include "v_video.h" #include "version.h" diff --git a/src/common/widgets/widgetresourcedata.cpp b/src/common/widgets/widgetresourcedata.cpp index ad8bd747f..84822fc86 100644 --- a/src/common/widgets/widgetresourcedata.cpp +++ b/src/common/widgets/widgetresourcedata.cpp @@ -12,19 +12,7 @@ void InitWidgetResources(const char* filename) I_FatalError("Unable to open %s", filename); } -std::vector LoadWidgetFontData(const std::string& name) -{ - auto lump = WidgetResources->FindEntry("widgets/poppins/poppins-regular.ttf"); - if (lump == -1) - I_FatalError("Unable to find %s", name.c_str()); - - auto reader = WidgetResources->GetEntryReader(lump, FileSys::READER_SHARED); - std::vector buffer(reader.GetLength()); - reader.Read(buffer.data(), buffer.size()); - return buffer; -} - -std::vector LoadWidgetImageData(const std::string& name) +static std::vector LoadFile(const std::string& name) { auto lump = WidgetResources->FindEntry(name.c_str()); if (lump == -1) @@ -35,3 +23,32 @@ std::vector LoadWidgetImageData(const std::string& name) reader.Read(buffer.data(), buffer.size()); return buffer; } + +// This interface will later require some significant redesign. +std::vector LoadWidgetFontData(const std::string& name) +{ + std::vector returnv; + if (!stricmp(name.c_str(), "notosans")) + { + returnv.resize(3); + returnv[2].fontdata = LoadFile("widgets/noto/notosans-regular.ttf"); + returnv[0].fontdata = LoadFile("widgets/noto/notosansarmenian-regular.ttf"); + returnv[1].fontdata = LoadFile("widgets/noto/notosansgeorgian-regular.ttf"); + returnv[0].ranges.push_back(std::make_pair(0x531, 0x58f)); + returnv[1].ranges.push_back(std::make_pair(0x10a0, 0x10ff)); + returnv[1].ranges.push_back(std::make_pair(0x1c90, 0x1cbf)); + returnv[1].ranges.push_back(std::make_pair(0x2d00, 0x2d2f)); + // todo: load system CJK fonts here + return returnv; + + } + returnv.resize(1); + std::string fn = "widgets/font/" +name + ".ttf"; + returnv[0].fontdata = LoadFile(fn); + return returnv; +} + +std::vector LoadWidgetImageData(const std::string& name) +{ + return LoadFile(name); +} diff --git a/wadsrc/static/widgets/noto/NotoSans-Regular.ttf b/wadsrc/static/widgets/noto/NotoSans-Regular.ttf new file mode 100644 index 000000000..fa4cff505 Binary files /dev/null and b/wadsrc/static/widgets/noto/NotoSans-Regular.ttf differ diff --git a/wadsrc/static/widgets/noto/NotoSansArmenian-Regular.ttf b/wadsrc/static/widgets/noto/NotoSansArmenian-Regular.ttf new file mode 100644 index 000000000..097432059 Binary files /dev/null and b/wadsrc/static/widgets/noto/NotoSansArmenian-Regular.ttf differ diff --git a/wadsrc/static/widgets/noto/NotoSansGeorgian-Regular.ttf b/wadsrc/static/widgets/noto/NotoSansGeorgian-Regular.ttf new file mode 100644 index 000000000..49163cc37 Binary files /dev/null and b/wadsrc/static/widgets/noto/NotoSansGeorgian-Regular.ttf differ diff --git a/wadsrc/static/widgets/poppins/OFL.txt b/wadsrc/static/widgets/noto/OFL.txt similarity index 100% rename from wadsrc/static/widgets/poppins/OFL.txt rename to wadsrc/static/widgets/noto/OFL.txt diff --git a/wadsrc/static/widgets/poppins/poppins-regular.ttf b/wadsrc/static/widgets/poppins/poppins-regular.ttf deleted file mode 100644 index 9f0c71b70..000000000 Binary files a/wadsrc/static/widgets/poppins/poppins-regular.ttf and /dev/null differ