Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restrict font locator configurability down to native and mock. #1538

Merged
merged 2 commits into from
Jun 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions docs/configuration/profiles.md
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ profiles:
```
:octicons-horizontal-rule-16: ==size== Specifies the initial font size in pixels. The default value is 12. <br/>
:octicons-horizontal-rule-16: ==dpi_scale== Allows applying a DPI scaling factor on top of the system's configured DPI. The default value is 1.0. <br/>
:octicons-horizontal-rule-16: ==locator== Determines the font locator engine to use for locating font files and font fallback. Possible values are native, fontconfig, CoreText, and DirectWrite.<br/>
:octicons-horizontal-rule-16: ==locator== Determines the font locator engine to use for locating font files and font fallback. Possible values are `native` and `mock`.<br/> `native` will use the operating-system native font location service (e.g. CoreText on macOS and DirectWrite on Windows), whereas `mock` is solely used for testing the software (not recommended by end-users)<br/>
:octicons-horizontal-rule-16: ==text_shaping.engine== Selects the text shaping and font rendering engine. Supported values are native, DirectWrite, CoreText, and OpenShaper. <br/>
:octicons-horizontal-rule-16: ==builtin_box_drawing== Specifies whether to use built-in textures for pixel-perfect box drawing. If disabled, the font's provided box drawing characters will be used. The default value is true.<br/>
:octicons-horizontal-rule-16: ==render_mode== Specifies the font render mode, which tells the font rasterizer engine what rendering technique to use. Available modes are lcd, light, gray, and monochrome. <br/>
Expand Down Expand Up @@ -434,8 +434,8 @@ profiles:

With this, the terminal will use the color scheme as specified in `dark` when OS dark mode is on,
and `light`'s color scheme otherwise.


### `hyperlink_decoration:`
section in the configuration file allows you to configure the styling and colorization of hyperlinks when they are displayed in the terminal and when they are hovered over by the cursor.

Expand All @@ -446,7 +446,7 @@ profiles:
profile_name:
hyperlink_decoration:
normal: dotted
hover: underline
hover: underline

```

Expand Down
1 change: 1 addition & 0 deletions metainfo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@
<li>Add config entry to configure behaviour on exit from search mode</li>
<li>Add handling of different input commands (#629)</li>
<li>Update of contour.desktop file (#1423)</li>
<li>Changed configuration entry values for `font_locator` down to `native` and `mock` only (#1538).</li>
<li>Fixes forwarding of input while in normal mode (#1468)</li>
<li>Fixes OSC-8 link id collision (#1499)</li>
<li>Fixed overlap of glyphs for long codepoints (#1349)</li>
Expand Down
23 changes: 9 additions & 14 deletions src/contour/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1072,23 +1072,18 @@ void YAMLConfigReader::loadFromEntry(YAML::Node const& node,
std::string const& entry,
vtrasterizer::FontLocatorEngine& where)
{
auto constexpr NativeFontLocator =
#if defined(_WIN32)
vtrasterizer::FontLocatorEngine::DWrite;
#elif defined(__APPLE__)
vtrasterizer::FontLocatorEngine::CoreText;
#else
vtrasterizer::FontLocatorEngine::FontConfig;
#endif
auto constexpr NativeFontLocator = vtrasterizer::FontLocatorEngine::Native;
auto parseModifierKey = [&](std::string const& key) -> std::optional<vtrasterizer::FontLocatorEngine> {
auto const literal = crispy::toLower(key);
logger()("Loading entry: {}, value {}", entry, literal);
if (literal == "fontconfig")
return vtrasterizer::FontLocatorEngine::FontConfig;
if (literal == "coretext")
return vtrasterizer::FontLocatorEngine::CoreText;
if (literal == "dwrite" || literal == "directwrite")
return vtrasterizer::FontLocatorEngine::DWrite;
for (auto const& deprecated: { "fontconfig", "coretext", "dwrite", "directwrite" })
{
if (literal == deprecated)
{
errorLog()("Setting font locator to \"{}\" is deprecated. Use \"native\".", literal);
return NativeFontLocator;
}
}
if (literal == "native")
return NativeFontLocator;
if (literal == "mock")
Expand Down
2 changes: 1 addition & 1 deletion src/contour/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ const inline vtrasterizer::FontDescriptions defaultFont = vtrasterizer::FontDesc
.emoji = text::font_description { .familyName = { "emoji" } },
.renderMode = text::render_mode::gray,
.textShapingEngine = vtrasterizer::TextShapingEngine::OpenShaper,
.fontLocator = vtrasterizer::FontLocatorEngine::FontConfig,
.fontLocator = vtrasterizer::FontLocatorEngine::Native,
.builtinBoxDrawing = true,
};

Expand Down
4 changes: 1 addition & 3 deletions src/contour/ConfigDocumentation.h
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,7 @@ constexpr StringLiteral Fonts {
" {comment} This is implicitly also responsible for font fallback\n"
" {comment} Possible values are:\n"
" {comment} - native : automatically choose the best available on the current platform\n"
" {comment} - fontconfig : uses fontconfig to select fonts\n"
" {comment} - CoreText : uses OS/X CoreText to select fonts.\n"
" {comment} - DirectWrite : selects DirectWrite engine (Windows only)\n"
" {comment} - mock : mock font locator engine (not recommended for general use)\n"
" locator: {}\n"
"\n"
" {comment} Text shaping related settings\n"
Expand Down
4 changes: 1 addition & 3 deletions src/contour/contour.yml
Original file line number Diff line number Diff line change
Expand Up @@ -370,9 +370,7 @@ profiles:
# This is implicitly also responsible for font fallback
# Possible values are:
# - native : automatically choose the best available on the current platform
# - fontconfig : uses fontconfig to select fonts
# - CoreText : uses macOS CoreText to select fonts.
# - DirectWrite : selects DirectWrite engine (Windows only)
# - mock : a mock locator that does not actually locate any fonts (for development testing)
Yaraslaut marked this conversation as resolved.
Show resolved Hide resolved
locator: native

# Text shaping related settings
Expand Down
6 changes: 3 additions & 3 deletions src/text_shaper/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ set(text_shaper_SRC
font.cpp font.h
font_locator.h
font_locator_provider.cpp font_locator_provider.h
fontconfig_locator.cpp fontconfig_locator.h
mock_font_locator.cpp mock_font_locator.h
open_shaper.cpp open_shaper.h
shaper.cpp shaper.h
Expand All @@ -16,6 +15,9 @@ endif()
if(APPLE)
list(APPEND text_shaper_SRC coretext_locator.h coretext_locator.mm)
endif()
if("${CMAKE_SYSTEM}" MATCHES "Linux" OR "${CMAKE_SYSTEM}" MATCHES "FreeBSD")
list(APPEND text_shaper_SRC fontconfig_locator.cpp fontconfig_locator.h)
endif()

# TODO: coretext_shaper.cpp coretext_shaper.h
add_library(text_shaper STATIC ${text_shaper_SRC})
Expand Down Expand Up @@ -52,12 +54,10 @@ elseif("${CMAKE_SYSTEM}" MATCHES "Linux" OR "${CMAKE_SYSTEM}" MATCHES "FreeBSD")
list(APPEND TEXT_SHAPER_LIBS Fontconfig::Fontconfig)
elseif("${CMAKE_SYSTEM}" MATCHES "Windows")
# installed via vcpkg
find_package(Fontconfig REQUIRED)
find_package(harfbuzz CONFIG REQUIRED)
find_package(Freetype REQUIRED)
list(APPEND TEXT_SHAPER_LIBS harfbuzz harfbuzz::harfbuzz)
list(APPEND TEXT_SHAPER_LIBS Freetype::Freetype)
list(APPEND TEXT_SHAPER_LIBS Fontconfig::Fontconfig)
list(APPEND TEXT_SHAPER_LIBS dwrite)
endif()

Expand Down
34 changes: 11 additions & 23 deletions src/text_shaper/font_locator_provider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,20 @@ font_locator_provider& font_locator_provider::get()
return instance;
}

#if defined(__APPLE__)
font_locator& font_locator_provider::coretext()
{
if (!_coretext)
_coretext = make_unique<coretext_locator>();

return *_coretext;
}
#endif

#if defined(_WIN32)
font_locator& font_locator_provider::directwrite()
font_locator& font_locator_provider::native()
{
if (!_directwrite)
_directwrite = make_unique<directwrite_locator>();

return *_directwrite;
}
if (!_native)
{
#if defined(__APPLE__)
_native = make_unique<coretext_locator>();
#elif defined(_WIN32)
_native = make_unique<directwrite_locator>();
#else
_native = make_unique<fontconfig_locator>();
Yaraslaut marked this conversation as resolved.
Show resolved Hide resolved
#endif
}

font_locator& font_locator_provider::fontconfig()
{
if (!_fontconfig)
_fontconfig = make_unique<fontconfig_locator>();

return *_fontconfig;
return *_native;
}

font_locator& font_locator_provider::mock()
Expand Down
19 changes: 2 additions & 17 deletions src/text_shaper/font_locator_provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,12 @@ class font_locator_provider
public:
static font_locator_provider& get();

#if defined(__APPLE__)
font_locator& coretext();
#endif
font_locator& native();

#if defined(_WIN32)
font_locator& directwrite();
#endif

font_locator& fontconfig();
font_locator& mock();

private:
#if defined(__APPLE__)
std::unique_ptr<font_locator> _coretext {};
#endif

#if defined(_WIN32)
std::unique_ptr<font_locator> _directwrite {};
#endif

std::unique_ptr<font_locator> _fontconfig {};
std::unique_ptr<font_locator> _native {};
std::unique_ptr<font_locator> _mock {};
};

Expand Down
4 changes: 3 additions & 1 deletion src/text_shaper/open_shaper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
#include FT_LCD_FILTER_H
// clang-format on

#include <fontconfig/fontconfig.h>
#if __has_include(<fontconfig/fontconfig.h>)
#include <fontconfig/fontconfig.h>
#endif

#include <harfbuzz/hb-ft.h>
#include <harfbuzz/hb.h>
Expand Down
12 changes: 4 additions & 8 deletions src/vtrasterizer/FontDescriptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@ enum class TextShapingEngine : uint8_t

enum class FontLocatorEngine : uint8_t
{
Mock, //!< mock font locator API
FontConfig, //!< platform independant font locator API
DWrite, //!< native platform support: Windows
CoreText, //!< native font locator on macOS
Mock, //!< mock font locator API
Native, //!< native platform support
};

using DPI = text::DPI;
Expand All @@ -36,7 +34,7 @@ struct FontDescriptions
text::font_description emoji;
text::render_mode renderMode;
TextShapingEngine textShapingEngine = TextShapingEngine::OpenShaper;
FontLocatorEngine fontLocator = FontLocatorEngine::FontConfig;
FontLocatorEngine fontLocator = FontLocatorEngine::Native;
bool builtinBoxDrawing = true;
};

Expand Down Expand Up @@ -106,9 +104,7 @@ struct fmt::formatter<vtrasterizer::FontLocatorEngine>: fmt::formatter<std::stri
string_view name;
switch (value)
{
case vtrasterizer::FontLocatorEngine::CoreText: name = "CoreText"; break;
case vtrasterizer::FontLocatorEngine::DWrite: name = "DirectWrite"; break;
case vtrasterizer::FontLocatorEngine::FontConfig: name = "Fontconfig"; break;
case vtrasterizer::FontLocatorEngine::Native: name = "Native"; break;
case vtrasterizer::FontLocatorEngine::Mock: name = "Mock"; break;
}
return formatter<string_view>::format(name, ctx);
Expand Down
22 changes: 2 additions & 20 deletions src/vtrasterizer/TextRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,28 +258,10 @@ text::font_locator& createFontLocator(FontLocatorEngine engine)
switch (engine)
{
case FontLocatorEngine::Mock: return text::font_locator_provider::get().mock();
case FontLocatorEngine::DWrite:
#if defined(_WIN32)
return text::font_locator_provider::get().directwrite();
#else
locatorLog()("Font locator DirectWrite not supported on this platform.");
#endif
break;
case FontLocatorEngine::CoreText:
#if defined(__APPLE__)
return text::font_locator_provider::get().coretext();
#else
locatorLog()("Font locator CoreText not supported on this platform.");
#endif
break;

case FontLocatorEngine::FontConfig:
// default case below
break;
default: return text::font_locator_provider::get().native();
}

locatorLog()("Using font locator: fontconfig.");
return text::font_locator_provider::get().fontconfig();
crispy::unreachable();
}

// TODO: What's a good value here? Or do we want to make that configurable,
Expand Down
14 changes: 14 additions & 0 deletions vcpkg-configuration.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"default-registry": {
"kind": "git",
"baseline": "000d1bda1ffa95a73e0b40334fa4103d6f4d3d48",
"repository": "https://github.com/microsoft/vcpkg"
},
"registries": [
{
"kind": "artifact",
"location": "https://github.com/microsoft/vcpkg-ce-catalog/archive/refs/heads/main.zip",
"name": "microsoft"
}
]
}
1 change: 0 additions & 1 deletion vcpkg.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
{ "name": "ms-gsl"},
{ "name": "range-v3", "version>=": "0.12.0" },
{ "name": "yaml-cpp" },
"fontconfig",
"freetype",
"harfbuzz"
]
Expand Down
Loading