Make it possible to set and use default family
This commit is contained in:
parent
d04337075a
commit
ea18576032
4 changed files with 11 additions and 8 deletions
|
|
@ -7,7 +7,7 @@ edition = "2021"
|
||||||
license = "MIT OR Apache-2.0"
|
license = "MIT OR Apache-2.0"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
fontdb = "0.9"
|
fontdb = { version = "0.9", git = "https://github.com/jackpot51/fontdb" }
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
rustybuzz = "0.5"
|
rustybuzz = "0.5"
|
||||||
swash = { version = "0.1", optional = true }
|
swash = { version = "0.1", optional = true }
|
||||||
|
|
|
||||||
|
|
@ -550,7 +550,7 @@ impl<'a> TextBuffer<'a> {
|
||||||
|
|
||||||
/// Perform a [TextAction] on the buffer
|
/// Perform a [TextAction] on the buffer
|
||||||
pub fn action(&mut self, action: TextAction) {
|
pub fn action(&mut self, action: TextAction) {
|
||||||
let mut old_cursor = self.cursor;
|
let old_cursor = self.cursor;
|
||||||
|
|
||||||
match action {
|
match action {
|
||||||
TextAction::Previous => {
|
TextAction::Previous => {
|
||||||
|
|
|
||||||
|
|
@ -3,12 +3,13 @@
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use unicode_script::{Script, UnicodeScript};
|
use unicode_script::{Script, UnicodeScript};
|
||||||
|
|
||||||
use super::{Font, FontShapeGlyph, FontShapeLine, FontShapeSpan, FontShapeWord};
|
use crate::{Font, FontShapeGlyph, FontShapeLine, FontShapeSpan, FontShapeWord};
|
||||||
use super::fallback::{FontFallbackIter};
|
use crate::fallback::{FontFallbackIter};
|
||||||
|
|
||||||
/// Fonts that match a pattern
|
/// Fonts that match a pattern
|
||||||
pub struct FontMatches<'a> {
|
pub struct FontMatches<'a> {
|
||||||
pub locale: &'a str,
|
pub locale: &'a str,
|
||||||
|
pub default_family: String,
|
||||||
pub fonts: Vec<Arc<Font<'a>>>,
|
pub fonts: Vec<Arc<Font<'a>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -127,10 +128,10 @@ impl<'a> FontMatches<'a> {
|
||||||
&line[start_word..end_word],
|
&line[start_word..end_word],
|
||||||
);
|
);
|
||||||
|
|
||||||
//TODO: configure default family
|
let default_families = [self.default_family.as_str()];
|
||||||
let mut font_iter = FontFallbackIter::new(
|
let mut font_iter = FontFallbackIter::new(
|
||||||
&self.fonts,
|
&self.fonts,
|
||||||
&["Fira Sans", "Fira Mono"],
|
&default_families,
|
||||||
scripts,
|
scripts,
|
||||||
self.locale
|
self.locale
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ use std::{
|
||||||
sync::{Arc, Mutex},
|
sync::{Arc, Mutex},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{Attrs, Font, FontMatches};
|
use crate::{Attrs, Family, Font, FontMatches};
|
||||||
|
|
||||||
/// Access system fonts
|
/// Access system fonts
|
||||||
pub struct FontSystem<'a> {
|
pub struct FontSystem<'a> {
|
||||||
|
|
@ -79,6 +79,7 @@ impl<'a> FontSystem<'a> {
|
||||||
|
|
||||||
pub fn matches<F: Fn(&fontdb::FaceInfo) -> bool>(
|
pub fn matches<F: Fn(&fontdb::FaceInfo) -> bool>(
|
||||||
&'a self,
|
&'a self,
|
||||||
|
default_family: &Family,
|
||||||
f: F,
|
f: F,
|
||||||
) -> FontMatches<'_> {
|
) -> FontMatches<'_> {
|
||||||
let mut fonts = Vec::new();
|
let mut fonts = Vec::new();
|
||||||
|
|
@ -95,12 +96,13 @@ impl<'a> FontSystem<'a> {
|
||||||
|
|
||||||
FontMatches {
|
FontMatches {
|
||||||
locale: &self.locale,
|
locale: &self.locale,
|
||||||
|
default_family: self.db.family_name(default_family).to_string(),
|
||||||
fonts
|
fonts
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn matches_attrs(&'a self, attrs: &Attrs) -> FontMatches<'_> {
|
pub fn matches_attrs(&'a self, attrs: &Attrs) -> FontMatches<'_> {
|
||||||
self.matches(|face| {
|
self.matches(&attrs.family, |face| {
|
||||||
let matched = attrs.matches(face);
|
let matched = attrs.matches(face);
|
||||||
|
|
||||||
if matched {
|
if matched {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue