Skip to content

Commit

Permalink
Use font_manager_v3 interface from Columns UI SDK
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
reupen committed Dec 16, 2024
1 parent 4374650 commit 98c050e
Show file tree
Hide file tree
Showing 14 changed files with 30 additions and 90 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
1 change: 0 additions & 1 deletion foo_ui_columns/filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
43 changes: 26 additions & 17 deletions foo_ui_columns/font_manager_v3.cpp
Original file line number Diff line number Diff line change
@@ -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<DWRITE_FONT_AXIS_VALUE> 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))
Expand All @@ -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};
Expand All @@ -51,15 +61,14 @@ class Font : public font {
}

const auto factory_7 = context->factory().try_query<IDWriteFactory7>();
const auto axis_values = uih::direct_write::axis_values_to_vector(m_axis_values);

try {
pfc::com_ptr_t<IDWriteTextFormat> text_format;

if (factory_7 && !axis_values.empty()) {
if (factory_7 && !m_axis_values.empty()) {
wil::com_ptr_t<IDWriteTextFormat3> text_format_3;
THROW_IF_FAILED(factory_7->CreateTextFormat(m_typographic_family_name.c_str(), nullptr,
axis_values.data(), gsl::narrow<uint32_t>(axis_values.size()), size(), L"", &text_format_3));
m_axis_values.data(), gsl::narrow<uint32_t>(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(),
Expand All @@ -73,10 +82,10 @@ class Font : public font {
try {
pfc::com_ptr_t<IDWriteTextFormat> text_format;

if (factory_7 && !axis_values.empty()) {
if (factory_7 && !m_axis_values.empty()) {
wil::com_ptr_t<IDWriteTextFormat3> text_format_3;
THROW_IF_FAILED(factory_7->CreateTextFormat(L"", nullptr, axis_values.data(),
gsl::narrow<uint32_t>(axis_values.size()), size(), L"", &text_format_3));
THROW_IF_FAILED(factory_7->CreateTextFormat(L"", nullptr, m_axis_values.data(),
gsl::narrow<uint32_t>(m_axis_values.size()), size(), L"", &text_format_3));
text_format.attach(text_format_3.detach());
} else {
THROW_IF_FAILED(context->factory()->CreateTextFormat(
Expand All @@ -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<DWRITE_FONT_AXIS_VALUE> m_axis_values;
float m_size{};
DWRITE_RENDERING_MODE m_rendering_mode{};
bool m_force_greyscale_antialiasing{};
Expand All @@ -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<Font>(log_font, wss, font_description.typographic_family_name, axis_values, size,
static_cast<DWRITE_RENDERING_MODE>(rendering_mode.get()), force_greyscale_antialiasing.get());
return fb2k::service_new<Font>(log_font, wss, font_description.typographic_family_name, std::move(axis_values),
size, static_cast<DWRITE_RENDERING_MODE>(rendering_mode.get()), force_greyscale_antialiasing.get());
}

void set_client_font_size(GUID id, float size) override
Expand Down
59 changes: 0 additions & 59 deletions foo_ui_columns/font_manager_v3.h

This file was deleted.

1 change: 0 additions & 1 deletion foo_ui_columns/font_utils.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#pragma once
#include "font_manager_v3.h"

namespace cui::fonts {

Expand Down
1 change: 0 additions & 1 deletion foo_ui_columns/foo_ui_columns.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,6 @@
<ClInclude Include="dark_mode_spin.h" />
<ClInclude Include="event_token.h" />
<ClInclude Include="file_info_utils.h" />
<ClInclude Include="font_manager_v3.h" />
<ClInclude Include="font_manager_data.h" />
<ClInclude Include="font_picker.h" />
<ClInclude Include="gdi.h" />
Expand Down
3 changes: 0 additions & 3 deletions foo_ui_columns/foo_ui_columns.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -911,9 +911,6 @@
<ClInclude Include="font_utils.h">
<Filter>Colours and fonts</Filter>
</ClInclude>
<ClInclude Include="font_manager_v3.h">
<Filter>Colours and fonts</Filter>
</ClInclude>
<ClInclude Include="item_details_text.h">
<Filter>Item details</Filter>
</ClInclude>
Expand Down
1 change: 0 additions & 1 deletion foo_ui_columns/item_details_text.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 0 additions & 1 deletion foo_ui_columns/item_properties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#include "item_properties.h"

#include "file_info_utils.h"
#include "font_manager_v3.h"

namespace cui::panels::item_properties {

Expand Down
1 change: 0 additions & 1 deletion foo_ui_columns/ng_playlist/ng_playlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 0 additions & 1 deletion foo_ui_columns/playlist_switcher_v2.cpp
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
1 change: 0 additions & 1 deletion foo_ui_columns/status_bar.cpp
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
1 change: 0 additions & 1 deletion foo_ui_columns/status_pane.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 98c050e

Please sign in to comment.