From 984fae3f1bf894b65cd8e4f7c384f8e673f354ca Mon Sep 17 00:00:00 2001 From: Reupen Shah Date: Sun, 15 Dec 2024 18:34:05 +0000 Subject: [PATCH] Use font_manager_v3 interface from Columns UI SDK This removes the font_manager_v3 interface from this repo and switches to using the font_manager_v3 interface that has been added to the Columns UI SDK. --- CHANGELOG.md | 4 +- columns_ui-sdk | 2 +- foo_ui_columns/filter.cpp | 1 - foo_ui_columns/font_manager_v3.cpp | 43 ++++++++------ foo_ui_columns/font_manager_v3.h | 59 ------------------- foo_ui_columns/font_utils.h | 1 - foo_ui_columns/foo_ui_columns.vcxproj | 1 - foo_ui_columns/foo_ui_columns.vcxproj.filters | 3 - foo_ui_columns/item_details_text.cpp | 1 - foo_ui_columns/item_properties.cpp | 1 - foo_ui_columns/ng_playlist/ng_playlist.cpp | 1 - foo_ui_columns/playlist_switcher_v2.cpp | 1 - foo_ui_columns/status_bar.cpp | 1 - foo_ui_columns/status_pane.cpp | 1 - 14 files changed, 30 insertions(+), 90 deletions(-) delete mode 100644 foo_ui_columns/font_manager_v3.h diff --git a/CHANGELOG.md b/CHANGELOG.md index adeb511bd..3ee8fbb52 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,7 +24,9 @@ [#974](https://github.com/reupen/columns_ui/pull/974), [#976](https://github.com/reupen/columns_ui/pull/976), [#981](https://github.com/reupen/columns_ui/pull/981), - [#981](https://github.com/reupen/columns_ui/pull/989)] + [#981](https://github.com/reupen/columns_ui/pull/989), + [#1030](https://github.com/reupen/columns_ui/pull/1030), + [#1031](https://github.com/reupen/columns_ui/pull/1031)] This includes colour font support on Windows 8.1 and newer (allowing the use of, for example, colour emojis). diff --git a/columns_ui-sdk b/columns_ui-sdk index 06b15416c..8ec5f0e1d 160000 --- a/columns_ui-sdk +++ b/columns_ui-sdk @@ -1 +1 @@ -Subproject commit 06b15416c966540a7c06a23fdb7ae03f3bd40152 +Subproject commit 8ec5f0e1db23459ba1f6bf039efea783b2ae8d14 diff --git a/foo_ui_columns/filter.cpp b/foo_ui_columns/filter.cpp index 0287b014a..e7f08a3a7 100644 --- a/foo_ui_columns/filter.cpp +++ b/foo_ui_columns/filter.cpp @@ -4,7 +4,6 @@ #include "filter_config_var.h" #include "filter_search_bar.h" #include "filter_utils.h" -#include "font_manager_v3.h" namespace cui::panels::filter { diff --git a/foo_ui_columns/font_manager_v3.cpp b/foo_ui_columns/font_manager_v3.cpp index c2067a824..8f87fc3f2 100644 --- a/foo_ui_columns/font_manager_v3.cpp +++ b/foo_ui_columns/font_manager_v3.cpp @@ -1,20 +1,15 @@ #include "pch.h" -#include "font_manager_v3.h" - #include "config_appearance.h" #include "font_utils.h" #include "system_appearance_manager.h" namespace cui::fonts { -const GUID font::class_guid{0x6e7708d5, 0x4799, 0x45e5, {0x8f, 0x41, 0x2d, 0x68, 0xf1, 0x5d, 0x08, 0x50}}; -const GUID manager_v3::class_guid{0x471a234d, 0xb81a, 0x4f6a, {0x84, 0x94, 0x5c, 0x9f, 0xff, 0x2c, 0xf6, 0x1f}}; - class Font : public font { public: Font(LOGFONT log_font, uih::direct_write::WeightStretchStyle wss, std::wstring typographic_family_name, - uih::direct_write::AxisValues axis_values, const float size, DWRITE_RENDERING_MODE rendering_mode, + std::vector axis_values, const float size, DWRITE_RENDERING_MODE rendering_mode, bool force_greyscale_antialiasing) : m_log_font(std::move(log_font)) , m_wss(std::move(wss)) @@ -26,12 +21,27 @@ class Font : public font { { } - const wchar_t* family_name() noexcept final { return m_wss.family_name.c_str(); } + const wchar_t* family_name(FontFamilyModel font_family_model = FontFamilyModel::Automatic) noexcept final + { + switch (font_family_model) { + default: + return m_typographic_family_name.empty() ? m_wss.family_name.c_str() : m_typographic_family_name.c_str(); + case FontFamilyModel::WeightStretchStyle: + return m_wss.family_name.c_str(); + case FontFamilyModel::Typographic: + return m_typographic_family_name.c_str(); + } + } + DWRITE_FONT_WEIGHT weight() noexcept final { return m_wss.weight; } DWRITE_FONT_STRETCH stretch() noexcept final { return m_wss.stretch; } DWRITE_FONT_STYLE style() noexcept final { return m_wss.style; } float size() noexcept final { return m_size > 0 ? m_size : 9.0f; } + size_t axis_count() const noexcept final { return m_axis_values.size(); } + + DWRITE_FONT_AXIS_VALUE axis_value(size_t index) const final { return m_axis_values.at(index); } + LOGFONT log_font() noexcept override { LOGFONT scaled_log_font{m_log_font}; @@ -51,15 +61,14 @@ class Font : public font { } const auto factory_7 = context->factory().try_query(); - const auto axis_values = uih::direct_write::axis_values_to_vector(m_axis_values); try { pfc::com_ptr_t text_format; - if (factory_7 && !axis_values.empty()) { + if (factory_7 && !m_axis_values.empty()) { wil::com_ptr_t text_format_3; THROW_IF_FAILED(factory_7->CreateTextFormat(m_typographic_family_name.c_str(), nullptr, - axis_values.data(), gsl::narrow(axis_values.size()), size(), L"", &text_format_3)); + m_axis_values.data(), gsl::narrow(m_axis_values.size()), size(), L"", &text_format_3)); text_format.attach(text_format_3.detach()); } else { THROW_IF_FAILED(context->factory()->CreateTextFormat(family_name(), nullptr, weight(), style(), @@ -73,10 +82,10 @@ class Font : public font { try { pfc::com_ptr_t text_format; - if (factory_7 && !axis_values.empty()) { + if (factory_7 && !m_axis_values.empty()) { wil::com_ptr_t text_format_3; - THROW_IF_FAILED(factory_7->CreateTextFormat(L"", nullptr, axis_values.data(), - gsl::narrow(axis_values.size()), size(), L"", &text_format_3)); + THROW_IF_FAILED(factory_7->CreateTextFormat(L"", nullptr, m_axis_values.data(), + gsl::narrow(m_axis_values.size()), size(), L"", &text_format_3)); text_format.attach(text_format_3.detach()); } else { THROW_IF_FAILED(context->factory()->CreateTextFormat( @@ -97,7 +106,7 @@ class Font : public font { LOGFONT m_log_font{}; uih::direct_write::WeightStretchStyle m_wss{}; std::wstring m_typographic_family_name; - uih::direct_write::AxisValues m_axis_values; + std::vector m_axis_values; float m_size{}; DWRITE_RENDERING_MODE m_rendering_mode{}; bool m_force_greyscale_antialiasing{}; @@ -114,10 +123,10 @@ class FontManager3 : public manager_v3 { const auto& log_font = font_description.log_font; auto size = font_description.dip_size; auto wss = font_description.get_wss_with_fallback(); - const auto& axis_values = font_description.axis_values; + auto axis_values = uih::direct_write::axis_values_to_vector(font_description.axis_values); - return fb2k::service_new(log_font, wss, font_description.typographic_family_name, axis_values, size, - static_cast(rendering_mode.get()), force_greyscale_antialiasing.get()); + return fb2k::service_new(log_font, wss, font_description.typographic_family_name, std::move(axis_values), + size, static_cast(rendering_mode.get()), force_greyscale_antialiasing.get()); } void set_client_font_size(GUID id, float size) override diff --git a/foo_ui_columns/font_manager_v3.h b/foo_ui_columns/font_manager_v3.h deleted file mode 100644 index 49c924c35..000000000 --- a/foo_ui_columns/font_manager_v3.h +++ /dev/null @@ -1,59 +0,0 @@ -#pragma once - -namespace cui::fonts { - -struct rendering_options { - DWRITE_RENDERING_MODE rendering_mode{DWRITE_RENDERING_MODE_DEFAULT}; - bool force_greyscale_antialiasing{}; -}; - -/** - * Part of the preliminary DirectWrite-friendly manager_v3 interface. - * - * Subject to change, only currently for internal use. - */ -class NOVTABLE font : public service_base { -public: - [[nodiscard]] virtual const wchar_t* family_name() noexcept = 0; - [[nodiscard]] virtual DWRITE_FONT_WEIGHT weight() noexcept = 0; - [[nodiscard]] virtual DWRITE_FONT_STRETCH stretch() noexcept = 0; - [[nodiscard]] virtual DWRITE_FONT_STYLE style() noexcept = 0; - [[nodiscard]] virtual float size() noexcept = 0; - - [[nodiscard]] virtual LOGFONT log_font() noexcept = 0; - - [[nodiscard]] virtual pfc::com_ptr_t create_text_format( - const wchar_t* locale_name = L"") noexcept - = 0; - - [[nodiscard]] virtual DWRITE_RENDERING_MODE rendering_mode() noexcept = 0; - [[nodiscard]] virtual bool force_greyscale_antialiasing() noexcept = 0; - - rendering_options get_rendering_options() { return {rendering_mode(), force_greyscale_antialiasing()}; } - -#ifdef __WIL_COM_INCLUDED - wil::com_ptr_t create_wil_text_format(const wchar_t* locale_name = L"") - { - wil::com_ptr_t text_format; - text_format.attach(create_text_format(locale_name).detach()); - return text_format; - } -#endif - - FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(font); -}; - -/** - * Preliminary DirectWrite-friendly manager_v3 interface. - * - * Subject to change, only currently for internal use. - */ -class NOVTABLE manager_v3 : public service_base { -public: - [[nodiscard]] virtual font::ptr get_client_font(GUID id) const = 0; - virtual void set_client_font_size(GUID id, float size) = 0; - - FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(manager_v3); -}; - -} // namespace cui::fonts diff --git a/foo_ui_columns/font_utils.h b/foo_ui_columns/font_utils.h index c4d8a3033..d2dfc626c 100644 --- a/foo_ui_columns/font_utils.h +++ b/foo_ui_columns/font_utils.h @@ -1,5 +1,4 @@ #pragma once -#include "font_manager_v3.h" namespace cui::fonts { diff --git a/foo_ui_columns/foo_ui_columns.vcxproj b/foo_ui_columns/foo_ui_columns.vcxproj index 35f829242..a015faa8d 100644 --- a/foo_ui_columns/foo_ui_columns.vcxproj +++ b/foo_ui_columns/foo_ui_columns.vcxproj @@ -447,7 +447,6 @@ - diff --git a/foo_ui_columns/foo_ui_columns.vcxproj.filters b/foo_ui_columns/foo_ui_columns.vcxproj.filters index 17c57384d..22013c645 100644 --- a/foo_ui_columns/foo_ui_columns.vcxproj.filters +++ b/foo_ui_columns/foo_ui_columns.vcxproj.filters @@ -911,9 +911,6 @@ Colours and fonts - - Colours and fonts - Item details diff --git a/foo_ui_columns/item_details_text.cpp b/foo_ui_columns/item_details_text.cpp index b8b88cad5..a245d80bd 100644 --- a/foo_ui_columns/item_details_text.cpp +++ b/foo_ui_columns/item_details_text.cpp @@ -3,7 +3,6 @@ #include "item_details.h" #include "item_details_text.h" -#include "font_manager_v3.h" #include "font_utils.h" #include "item_details_format_parser.h" #include "string.h" diff --git a/foo_ui_columns/item_properties.cpp b/foo_ui_columns/item_properties.cpp index ba639add9..18a9b3793 100644 --- a/foo_ui_columns/item_properties.cpp +++ b/foo_ui_columns/item_properties.cpp @@ -2,7 +2,6 @@ #include "item_properties.h" #include "file_info_utils.h" -#include "font_manager_v3.h" namespace cui::panels::item_properties { diff --git a/foo_ui_columns/ng_playlist/ng_playlist.cpp b/foo_ui_columns/ng_playlist/ng_playlist.cpp index 5dde2d258..d3b11980a 100644 --- a/foo_ui_columns/ng_playlist/ng_playlist.cpp +++ b/foo_ui_columns/ng_playlist/ng_playlist.cpp @@ -2,7 +2,6 @@ #include "ng_playlist.h" -#include "font_manager_v3.h" #include "ng_playlist_groups.h" #include "../config_columns_v2.h" #include "../playlist_item_helpers.h" diff --git a/foo_ui_columns/playlist_switcher_v2.cpp b/foo_ui_columns/playlist_switcher_v2.cpp index bf0acfa34..6d1093ef3 100644 --- a/foo_ui_columns/playlist_switcher_v2.cpp +++ b/foo_ui_columns/playlist_switcher_v2.cpp @@ -1,7 +1,6 @@ #include "pch.h" #include "playlist_switcher_v2.h" -#include "font_manager_v3.h" #include "playlist_switcher_title_formatting.h" namespace cui::panels::playlist_switcher { diff --git a/foo_ui_columns/status_bar.cpp b/foo_ui_columns/status_bar.cpp index 28521815a..57ad5fe6a 100644 --- a/foo_ui_columns/status_bar.cpp +++ b/foo_ui_columns/status_bar.cpp @@ -1,7 +1,6 @@ #include "pch.h" #include "status_bar.h" -#include "font_manager_v3.h" #include "font_utils.h" #include "main_window.h" #include "metadb_helpers.h" diff --git a/foo_ui_columns/status_pane.cpp b/foo_ui_columns/status_pane.cpp index 6ac86304b..f92a5a21e 100644 --- a/foo_ui_columns/status_pane.cpp +++ b/foo_ui_columns/status_pane.cpp @@ -4,7 +4,6 @@ #include "status_pane.h" #include "dark_mode.h" -#include "font_manager_v3.h" #include "font_utils.h" #include "menu_items.h" #include "metadb_helpers.h"