fonts: allow setting harfbuzz and freetype options per-font
`wezterm.font` and `wezterm.font_with_fallback` can now specify harfbuzz_features and freetype load/render target and flags as options on a per-font basis. This allows you to do things such as adjust shaping (eg: ligatures) or rendering (eg: disable bitmaps, or adjust hinting) for a single font in a fallback rather than globally for all fonts.
This commit is contained in:
1 parent
1203dff277
commit
dd150131b7
12 files changed
+279
-29
No files matched your search
+58
-10
@@ -3,6 +3,7 @@ use bitflags::*;
|
||||
use enum_display_derive::Display;
|
||||
use luahelper::impl_lua_conversion;
|
||||
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
||||
use std::convert::TryFrom;
|
||||
use std::fmt::Display;
|
||||
use termwiz::color::RgbColor;
|
||||
|
||||
@@ -250,6 +251,7 @@ bitflags! {
|
||||
// but we can't directly reference that from here without making config
|
||||
// depend on freetype.
|
||||
#[derive(Default, Deserialize, Serialize)]
|
||||
#[serde(try_from="String", into="String")]
|
||||
pub struct FreeTypeLoadFlags: u32 {
|
||||
/// FT_LOAD_DEFAULT
|
||||
const DEFAULT = 0;
|
||||
@@ -267,12 +269,40 @@ bitflags! {
|
||||
}
|
||||
}
|
||||
|
||||
impl FreeTypeLoadFlags {
|
||||
pub fn de_string<'de, D>(deserializer: D) -> Result<Self, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
let s = String::deserialize(deserializer)?;
|
||||
impl Into<String> for FreeTypeLoadFlags {
|
||||
fn into(self) -> String {
|
||||
self.to_string()
|
||||
}
|
||||
}
|
||||
|
||||
impl ToString for FreeTypeLoadFlags {
|
||||
fn to_string(&self) -> String {
|
||||
let mut s = vec![];
|
||||
if *self == Self::DEFAULT {
|
||||
s.push("DEFAULT");
|
||||
}
|
||||
if self.contains(Self::NO_HINTING) {
|
||||
s.push("NO_HINTING");
|
||||
}
|
||||
if self.contains(Self::NO_BITMAP) {
|
||||
s.push("NO_BITMAP");
|
||||
}
|
||||
if self.contains(Self::FORCE_AUTOHINT) {
|
||||
s.push("FORCE_AUTOHINT");
|
||||
}
|
||||
if self.contains(Self::MONOCHROME) {
|
||||
s.push("MONOCHROME");
|
||||
}
|
||||
if self.contains(Self::NO_AUTOHINT) {
|
||||
s.push("NO_AUTOHINT");
|
||||
}
|
||||
s.join("|")
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<String> for FreeTypeLoadFlags {
|
||||
type Error = String;
|
||||
fn try_from(s: String) -> Result<Self, String> {
|
||||
let mut flags = FreeTypeLoadFlags::default();
|
||||
|
||||
for ele in s.split('|') {
|
||||
@@ -285,10 +315,7 @@ impl FreeTypeLoadFlags {
|
||||
"MONOCHROME" => flags |= Self::MONOCHROME,
|
||||
"NO_AUTOHINT" => flags |= Self::NO_AUTOHINT,
|
||||
_ => {
|
||||
return Err(serde::de::Error::custom(format!(
|
||||
"invalid FreeTypeLoadFlags {} in {}",
|
||||
ele, s
|
||||
)));
|
||||
return Err(format!("invalid FreeTypeLoadFlags `{}` in `{}`", ele, s));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -311,6 +338,15 @@ pub struct FontAttributes {
|
||||
pub italic: bool,
|
||||
pub is_fallback: bool,
|
||||
pub is_synthetic: bool,
|
||||
|
||||
#[serde(default)]
|
||||
pub harfbuzz_features: Option<Vec<String>>,
|
||||
#[serde(default)]
|
||||
pub freetype_load_target: Option<FreeTypeLoadTarget>,
|
||||
#[serde(default)]
|
||||
pub freetype_render_target: Option<FreeTypeLoadTarget>,
|
||||
#[serde(default)]
|
||||
pub freetype_load_flags: Option<FreeTypeLoadFlags>,
|
||||
}
|
||||
impl_lua_conversion!(FontAttributes);
|
||||
|
||||
@@ -333,6 +369,10 @@ impl FontAttributes {
|
||||
italic: false,
|
||||
is_fallback: false,
|
||||
is_synthetic: false,
|
||||
harfbuzz_features: None,
|
||||
freetype_load_target: None,
|
||||
freetype_render_target: None,
|
||||
freetype_load_flags: None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -344,6 +384,10 @@ impl FontAttributes {
|
||||
italic: false,
|
||||
is_fallback: true,
|
||||
is_synthetic: false,
|
||||
harfbuzz_features: None,
|
||||
freetype_load_target: None,
|
||||
freetype_render_target: None,
|
||||
freetype_load_flags: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -357,6 +401,10 @@ impl Default for FontAttributes {
|
||||
italic: false,
|
||||
is_fallback: false,
|
||||
is_synthetic: false,
|
||||
harfbuzz_features: None,
|
||||
freetype_load_target: None,
|
||||
freetype_render_target: None,
|
||||
freetype_load_flags: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -845,7 +845,7 @@ pub struct Config {
|
||||
pub freetype_load_target: FreeTypeLoadTarget,
|
||||
#[serde(default)]
|
||||
pub freetype_render_target: Option<FreeTypeLoadTarget>,
|
||||
#[serde(default, deserialize_with = "FreeTypeLoadFlags::de_string")]
|
||||
#[serde(default)]
|
||||
pub freetype_load_flags: FreeTypeLoadFlags,
|
||||
|
||||
/// Selects the freetype interpret version to use.
|
||||
|
||||
+27
-1
@@ -1,11 +1,12 @@
|
||||
use crate::Gradient;
|
||||
use crate::{FontAttributes, FontStretch, FontWeight, TextStyle};
|
||||
use crate::{FontAttributes, FontStretch, FontWeight, FreeTypeLoadTarget, TextStyle};
|
||||
use anyhow::anyhow;
|
||||
use bstr::BString;
|
||||
pub use luahelper::*;
|
||||
use mlua::{FromLua, Lua, Table, ToLua, ToLuaMulti, Value, Variadic};
|
||||
use serde::*;
|
||||
use smol::prelude::*;
|
||||
use std::convert::TryFrom;
|
||||
use std::path::Path;
|
||||
use termwiz::cell::{grapheme_column_width, unicode_column_width, AttributeChange, CellAttributes};
|
||||
use termwiz::color::{AnsiColor, ColorAttribute, ColorSpec, RgbColor};
|
||||
@@ -487,6 +488,15 @@ struct LuaFontAttributes {
|
||||
/// Whether the font should be an italic variant
|
||||
#[serde(default)]
|
||||
pub italic: bool,
|
||||
|
||||
#[serde(default)]
|
||||
pub harfbuzz_features: Option<Vec<String>>,
|
||||
#[serde(default)]
|
||||
pub freetype_load_target: Option<FreeTypeLoadTarget>,
|
||||
#[serde(default)]
|
||||
pub freetype_render_target: Option<FreeTypeLoadTarget>,
|
||||
#[serde(default)]
|
||||
pub freetype_load_flags: Option<String>,
|
||||
}
|
||||
impl<'lua> FromLua<'lua> for LuaFontAttributes {
|
||||
fn from_lua(value: Value<'lua>, _lua: &'lua Lua) -> Result<Self, mlua::Error> {
|
||||
@@ -535,6 +545,13 @@ fn font<'lua>(
|
||||
italic: attrs.italic,
|
||||
is_fallback: false,
|
||||
is_synthetic: false,
|
||||
harfbuzz_features: attrs.harfbuzz_features,
|
||||
freetype_load_target: attrs.freetype_load_target,
|
||||
freetype_render_target: attrs.freetype_render_target,
|
||||
freetype_load_flags: match attrs.freetype_load_flags {
|
||||
Some(flags) => Some(TryFrom::try_from(flags).map_err(|e| mlua::Error::external(e))?),
|
||||
None => None,
|
||||
},
|
||||
});
|
||||
|
||||
Ok(text_style)
|
||||
@@ -573,6 +590,15 @@ fn font_with_fallback<'lua>(
|
||||
italic: attrs.italic,
|
||||
is_fallback: idx != 0,
|
||||
is_synthetic: false,
|
||||
harfbuzz_features: attrs.harfbuzz_features,
|
||||
freetype_load_target: attrs.freetype_load_target,
|
||||
freetype_render_target: attrs.freetype_render_target,
|
||||
freetype_load_flags: match attrs.freetype_load_flags {
|
||||
Some(flags) => {
|
||||
Some(TryFrom::try_from(flags).map_err(|e| mlua::Error::external(e))?)
|
||||
}
|
||||
None => None,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
+2
-1
@@ -18,6 +18,7 @@ As features stabilize some brief notes about them will accumulate here.
|
||||
* [SSH Domains](config/lua/SshDomain.md) now support specifying `ssh_config` overrides. [#1149](https://github.com/wez/wezterm/issues/1149)
|
||||
* [default_gui_startup_args](config/lua/config/default_gui_startup_args.md) allows defaulting to starting the ssh client (for example). [#1030](https://github.com/wez/wezterm/issues/1030)
|
||||
* [mux-is-process-stateful](config/lua/mux-events/mux-is-process-stateful.md) event for finer control over prompting when closing panes. [#1412](https://github.com/wez/wezterm/issues/1412)
|
||||
* [harfbuzz_features](config/font-shaping.md), [freetype_load_target](config/lua/config/freetype_load_target.md), [freetype_render_target](config/lua/config/freetype_render_target.md) and [freetype_load_flags](config/lua/config/freetype_load_flags.md) can now be overridden on a per-font basis as described in [wezterm.font](config/lua/wezterm/font.md) and [wezterm.font_with_fallback](config/lua/wezterm/font_with_fallback.md).
|
||||
|
||||
#### Changed
|
||||
|
||||
@@ -755,7 +756,7 @@ font_hinting = "Full" # None, Vertical, VerticalSubpixel, Full
|
||||
* Early startup errors now generate a "toast" notification, giving you more of a clue about what went wrong
|
||||
* We now use the default configuration if the config file had errors, rather than refusing to start
|
||||
* Wayland compositors: Improved detection of display scaling on startup
|
||||
* Added `harfuzz_features` option to specify stylistic sets for fonts such as Fira Code, and to control various typographical options
|
||||
* Added `harfbuzz_features` option to specify stylistic sets for fonts such as Fira Code, and to control various typographical options
|
||||
* Added a `window_padding` config section to add padding to the window display
|
||||
* We now respect [DECSCUSR and DECTCEM](https://github.com/wez/wezterm/issues/7) escape sequence to select between hidden, block, underline and bar cursor types, as well as blinking cursors. New configuration options have been added to control the appearance and blink rate.
|
||||
* We now support an optional basic scroll bar. The scroll bar occupies the right window padding and has a configurable color. Scroll bars are not yet supported for multiplexer connections and remain disabled by default for the moment.
|
||||
|
||||
@@ -40,4 +40,36 @@ return {
|
||||
}
|
||||
```
|
||||
|
||||
*Since: nightly builds only*
|
||||
|
||||
You can specify `harfbuzz_features` on a per-font basis, rather than
|
||||
globally for all fonts:
|
||||
|
||||
```lua
|
||||
local wezterm = require 'wezterm'
|
||||
return {
|
||||
font = wezterm.font({
|
||||
family="JetBrains Mono",
|
||||
harfbuzz_features={"calt=0", "clig=0", "liga=0"}
|
||||
})
|
||||
}
|
||||
```
|
||||
|
||||
and this example disables ligatures for JetBrains Mono,
|
||||
but keeps the default for the other fonts in the fallback:
|
||||
|
||||
```
|
||||
local wezterm = require 'wezterm';
|
||||
|
||||
return {
|
||||
font = wezterm.font_with_fallback({
|
||||
{
|
||||
family="JetBrains Mono",
|
||||
weight="Medium"
|
||||
harfbuzz_features={"calt=0", "clig=0", "liga=0"}
|
||||
},
|
||||
{family="Terminus", weight="Bold"},
|
||||
"Noto Color Emoji"),
|
||||
}
|
||||
```
|
||||
|
||||
@@ -71,3 +71,27 @@ return {
|
||||
}
|
||||
```
|
||||
|
||||
*Since: nightly builds only*
|
||||
|
||||
You can use the expanded form mentioned above to override freetype and harfbuzz
|
||||
settings just for the specified font; this examples shows how to disable the
|
||||
default ligature feature just for this particular font:
|
||||
|
||||
```lua
|
||||
local wezterm = require 'wezterm'
|
||||
return {
|
||||
font = wezterm.font({
|
||||
family="JetBrains Mono",
|
||||
harfbuzz_features={"calt=0", "clig=0", "liga=0"},
|
||||
})
|
||||
}
|
||||
```
|
||||
|
||||
The following options can be specified in the same way:
|
||||
|
||||
* [harfbuzz_features](../../font-shaping.md)
|
||||
* [freetype_load_target](../config/freetype_load_target.md)
|
||||
* [freetype_render_target](../config/freetype_render_target.md)
|
||||
* [freetype_load_flags](../config/freetype_load_flags.md)
|
||||
|
||||
|
||||
@@ -36,3 +36,32 @@ return {
|
||||
}
|
||||
```
|
||||
|
||||
*Since: nightly builds only*
|
||||
|
||||
You can use the expanded form mentioned above to override freetype and harfbuzz
|
||||
settings just for the specified font; this examples shows how to disable the
|
||||
default ligature feature just for JetBrains Mono, but leave it on for the
|
||||
other fonts in the fallback:
|
||||
|
||||
```lua
|
||||
local wezterm = require 'wezterm';
|
||||
|
||||
return {
|
||||
font = wezterm.font_with_fallback({
|
||||
{
|
||||
family="JetBrains Mono",
|
||||
harfbuzz_features={"calt=0", "clig=0", "liga=0"},
|
||||
},
|
||||
{family="Terminus", weight="Bold"},
|
||||
"Noto Color Emoji"),
|
||||
}
|
||||
```
|
||||
|
||||
The following options can be specified in the same way:
|
||||
|
||||
* [harfbuzz_features](../../font-shaping.md)
|
||||
* [freetype_load_target](../config/freetype_load_target.md)
|
||||
* [freetype_render_target](../config/freetype_render_target.md)
|
||||
* [freetype_load_flags](../config/freetype_load_flags.md)
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
use crate::locator::{FontDataHandle, FontDataSource};
|
||||
use crate::parser::ParsedFont;
|
||||
use anyhow::{anyhow, Context};
|
||||
use config::{configuration, FreeTypeLoadTarget};
|
||||
use config::{configuration, FreeTypeLoadFlags, FreeTypeLoadTarget};
|
||||
pub use freetype::*;
|
||||
use memmap2::{Mmap, MmapOptions};
|
||||
use rangeset::RangeSet;
|
||||
@@ -51,10 +51,17 @@ fn render_mode_to_load_target(render_mode: FT_Render_Mode) -> u32 {
|
||||
(render_mode as u32) & 15 << 16
|
||||
}
|
||||
|
||||
pub fn compute_load_flags_from_config() -> (i32, FT_Render_Mode) {
|
||||
pub fn compute_load_flags_from_config(
|
||||
freetype_load_flags: Option<FreeTypeLoadFlags>,
|
||||
freetype_load_target: Option<FreeTypeLoadTarget>,
|
||||
freetype_render_target: Option<FreeTypeLoadTarget>,
|
||||
) -> (i32, FT_Render_Mode) {
|
||||
let config = configuration();
|
||||
|
||||
let load_flags = config.freetype_load_flags.bits() | FT_LOAD_COLOR;
|
||||
let load_flags = freetype_load_flags
|
||||
.unwrap_or(config.freetype_load_flags)
|
||||
.bits()
|
||||
| FT_LOAD_COLOR;
|
||||
|
||||
fn target_to_render(t: FreeTypeLoadTarget) -> FT_Render_Mode {
|
||||
match t {
|
||||
@@ -66,11 +73,13 @@ pub fn compute_load_flags_from_config() -> (i32, FT_Render_Mode) {
|
||||
}
|
||||
}
|
||||
|
||||
let load_target = target_to_render(config.freetype_load_target);
|
||||
let load_target = target_to_render(freetype_load_target.unwrap_or(config.freetype_load_target));
|
||||
let render = target_to_render(
|
||||
config
|
||||
.freetype_render_target
|
||||
.unwrap_or(config.freetype_load_target),
|
||||
freetype_render_target.unwrap_or(
|
||||
config
|
||||
.freetype_render_target
|
||||
.unwrap_or(config.freetype_load_target),
|
||||
),
|
||||
);
|
||||
|
||||
let load_flags = load_flags | render_mode_to_load_target(load_target);
|
||||
@@ -618,7 +627,7 @@ impl Face {
|
||||
if glyph_pos == 0 {
|
||||
anyhow::bail!("no I from which to compute cap height");
|
||||
}
|
||||
let (load_flags, render_mode) = compute_load_flags_from_config();
|
||||
let (load_flags, render_mode) = compute_load_flags_from_config(None, None, None);
|
||||
let ft_glyph = self.load_and_render_glyph(glyph_pos, load_flags, render_mode, false)?;
|
||||
|
||||
let mode: FT_Pixel_Mode =
|
||||
|
||||
@@ -175,6 +175,10 @@ fn build_fallback_list_impl() -> anyhow::Result<Vec<ParsedFont>> {
|
||||
italic: false,
|
||||
is_fallback: true,
|
||||
is_synthetic: true,
|
||||
harfbuzz_features: None,
|
||||
freetype_load_target: None,
|
||||
freetype_render_target: None,
|
||||
freetype_load_flags: None,
|
||||
};
|
||||
if let Ok(descriptors) = descriptor_from_attr(&symbols) {
|
||||
for descriptor in descriptors.iter() {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use crate::locator::{FontDataHandle, FontDataSource, FontOrigin};
|
||||
use crate::shaper::GlyphInfo;
|
||||
use config::FontAttributes;
|
||||
use config::{FontAttributes, FreeTypeLoadFlags, FreeTypeLoadTarget};
|
||||
pub use config::{FontStretch, FontWeight};
|
||||
use rangeset::RangeSet;
|
||||
use std::cmp::Ordering;
|
||||
@@ -26,6 +26,11 @@ pub struct ParsedFont {
|
||||
pub synthesize_dim: bool,
|
||||
pub assume_emoji_presentation: bool,
|
||||
pub pixel_sizes: Vec<u16>,
|
||||
|
||||
pub harfbuzz_features: Option<Vec<String>>,
|
||||
pub freetype_load_target: Option<FreeTypeLoadTarget>,
|
||||
pub freetype_render_target: Option<FreeTypeLoadTarget>,
|
||||
pub freetype_load_flags: Option<FreeTypeLoadFlags>,
|
||||
}
|
||||
|
||||
impl std::fmt::Debug for ParsedFont {
|
||||
@@ -61,6 +66,10 @@ impl Clone for ParsedFont {
|
||||
cap_height: self.cap_height.clone(),
|
||||
coverage: Mutex::new(self.coverage.lock().unwrap().clone()),
|
||||
pixel_sizes: self.pixel_sizes.clone(),
|
||||
harfbuzz_features: self.harfbuzz_features.clone(),
|
||||
freetype_load_target: self.freetype_load_target,
|
||||
freetype_render_target: self.freetype_render_target,
|
||||
freetype_load_flags: self.freetype_load_flags,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -167,7 +176,14 @@ impl ParsedFont {
|
||||
code.push_str(&format!(" -- Pixel sizes: {:?}\n", p.pixel_sizes));
|
||||
}
|
||||
|
||||
if p.weight == FontWeight::REGULAR && p.stretch == FontStretch::Normal && !p.italic {
|
||||
if p.weight == FontWeight::REGULAR
|
||||
&& p.stretch == FontStretch::Normal
|
||||
&& !p.italic
|
||||
&& p.freetype_render_target.is_none()
|
||||
&& p.freetype_load_target.is_none()
|
||||
&& p.freetype_load_flags.is_none()
|
||||
&& p.harfbuzz_features.is_none()
|
||||
{
|
||||
code.push_str(&format!(" \"{}\",\n", p.names.family));
|
||||
} else {
|
||||
code.push_str(&format!(" {{family=\"{}\"", p.names.family));
|
||||
@@ -180,6 +196,27 @@ impl ParsedFont {
|
||||
if p.italic {
|
||||
code.push_str(", italic=true");
|
||||
}
|
||||
if let Some(item) = p.freetype_load_flags {
|
||||
code.push_str(&format!(", freetype_load_flags=\"{}\"", item.to_string()));
|
||||
}
|
||||
if let Some(item) = p.freetype_load_target {
|
||||
code.push_str(&format!(", freetype_load_target=\"{:?}\"", item));
|
||||
}
|
||||
if let Some(item) = p.freetype_render_target {
|
||||
code.push_str(&format!(", freetype_render_target=\"{:?}\"", item));
|
||||
}
|
||||
if let Some(feat) = &p.harfbuzz_features {
|
||||
code.push_str(", harfbuzz_features={");
|
||||
for (idx, f) in feat.iter().enumerate() {
|
||||
if idx > 0 {
|
||||
code.push_str(", ");
|
||||
}
|
||||
code.push('"');
|
||||
code.push_str(f);
|
||||
code.push('"');
|
||||
}
|
||||
code.push('}');
|
||||
}
|
||||
code.push_str("},\n")
|
||||
}
|
||||
code.push_str("\n");
|
||||
@@ -222,6 +259,10 @@ impl ParsedFont {
|
||||
coverage: Mutex::new(RangeSet::new()),
|
||||
cap_height,
|
||||
pixel_sizes,
|
||||
harfbuzz_features: None,
|
||||
freetype_render_target: None,
|
||||
freetype_load_target: None,
|
||||
freetype_load_flags: None,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -454,6 +495,11 @@ impl ParsedFont {
|
||||
/// Update self to reflect whether the rasterizer might need to synthesize
|
||||
/// italic for this font.
|
||||
pub fn synthesize(mut self, attr: &FontAttributes) -> Self {
|
||||
self.harfbuzz_features = attr.harfbuzz_features.clone();
|
||||
self.freetype_render_target = attr.freetype_render_target;
|
||||
self.freetype_load_target = attr.freetype_load_target;
|
||||
self.freetype_load_flags = attr.freetype_load_flags;
|
||||
|
||||
self.synthesize_italic = !self.italic && attr.italic;
|
||||
self.synthesize_bold = attr.weight >= FontWeight::BOLD
|
||||
&& attr.weight > self.weight
|
||||
|
||||
@@ -5,6 +5,7 @@ use crate::{ftwrap, RasterizedGlyph};
|
||||
use ::freetype::{FT_GlyphSlotRec_, FT_Glyph_Format, FT_Matrix};
|
||||
use anyhow::bail;
|
||||
use color_types::linear_u8_to_srgb8;
|
||||
use config::{FreeTypeLoadFlags, FreeTypeLoadTarget};
|
||||
use std::cell::RefCell;
|
||||
use std::mem;
|
||||
use std::slice;
|
||||
@@ -15,6 +16,9 @@ pub struct FreeTypeRasterizer {
|
||||
_lib: ftwrap::Library,
|
||||
synthesize_bold: bool,
|
||||
synthesize_italic: bool,
|
||||
freetype_load_target: Option<FreeTypeLoadTarget>,
|
||||
freetype_render_target: Option<FreeTypeLoadTarget>,
|
||||
freetype_load_flags: Option<FreeTypeLoadFlags>,
|
||||
}
|
||||
|
||||
impl FontRasterizer for FreeTypeRasterizer {
|
||||
@@ -26,7 +30,11 @@ impl FontRasterizer for FreeTypeRasterizer {
|
||||
) -> anyhow::Result<RasterizedGlyph> {
|
||||
self.face.borrow_mut().set_font_size(size, dpi)?;
|
||||
|
||||
let (load_flags, render_mode) = ftwrap::compute_load_flags_from_config();
|
||||
let (load_flags, render_mode) = ftwrap::compute_load_flags_from_config(
|
||||
self.freetype_load_flags,
|
||||
self.freetype_load_target,
|
||||
self.freetype_render_target,
|
||||
);
|
||||
|
||||
let mut face = self.face.borrow_mut();
|
||||
let ft_glyph =
|
||||
@@ -306,6 +314,9 @@ impl FreeTypeRasterizer {
|
||||
has_color,
|
||||
synthesize_bold: parsed.synthesize_bold,
|
||||
synthesize_italic: parsed.synthesize_italic,
|
||||
freetype_load_flags: parsed.freetype_load_flags,
|
||||
freetype_load_target: parsed.freetype_load_target,
|
||||
freetype_render_target: parsed.freetype_render_target,
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -42,9 +42,10 @@ fn make_glyphinfo(text: &str, font_idx: usize, info: &Info) -> GlyphInfo {
|
||||
|
||||
struct FontPair {
|
||||
face: ftwrap::Face,
|
||||
font: harfbuzz::Font,
|
||||
font: RefCell<harfbuzz::Font>,
|
||||
shaped_any: bool,
|
||||
presentation: Presentation,
|
||||
features: Vec<harfbuzz::hb_feature_t>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Hash, PartialEq, Eq, Clone)]
|
||||
@@ -136,17 +137,31 @@ impl HarfbuzzShaper {
|
||||
log::trace!("shaper wants {} {:?}", font_idx, handle);
|
||||
let face = self.lib.face_from_locator(&handle.handle)?;
|
||||
let mut font = harfbuzz::Font::new(face.face);
|
||||
let (load_flags, _) = ftwrap::compute_load_flags_from_config();
|
||||
let (load_flags, _) = ftwrap::compute_load_flags_from_config(
|
||||
handle.freetype_load_flags,
|
||||
handle.freetype_load_target,
|
||||
handle.freetype_render_target,
|
||||
);
|
||||
font.set_load_flags(load_flags);
|
||||
|
||||
let features = match &handle.harfbuzz_features {
|
||||
Some(features) => features
|
||||
.iter()
|
||||
.filter_map(|s| harfbuzz::feature_from_string(s).ok())
|
||||
.collect(),
|
||||
None => self.features.clone(),
|
||||
};
|
||||
|
||||
*opt_pair = Some(FontPair {
|
||||
face,
|
||||
font,
|
||||
font: RefCell::new(font),
|
||||
shaped_any: false,
|
||||
presentation: if handle.assume_emoji_presentation {
|
||||
Presentation::Emoji
|
||||
} else {
|
||||
Presentation::Text
|
||||
},
|
||||
features,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -194,10 +209,11 @@ impl HarfbuzzShaper {
|
||||
}
|
||||
let size = pair.face.set_font_size(font_size, dpi)?;
|
||||
// Tell harfbuzz to recompute important font metrics!
|
||||
pair.font.font_changed();
|
||||
let mut font = pair.font.borrow_mut();
|
||||
font.font_changed();
|
||||
cell_width = size.width;
|
||||
shaped_any = pair.shaped_any;
|
||||
pair.font.shape(&mut buf, self.features.as_slice());
|
||||
font.shape(&mut buf, pair.features.as_slice());
|
||||
/*
|
||||
log::info!(
|
||||
"shaped font_idx={} as: {}",
|
||||
@@ -562,6 +578,10 @@ mod test {
|
||||
is_fallback: false,
|
||||
is_synthetic: false,
|
||||
italic: false,
|
||||
freetype_load_flags: None,
|
||||
freetype_load_target: None,
|
||||
freetype_render_target: None,
|
||||
harfbuzz_features: None,
|
||||
},
|
||||
14,
|
||||
)
|
||||
|
||||
Reference in new issue
Block a user