Produce FontMatches inside of Buffer
This commit is contained in:
parent
085231c153
commit
59a4f8a4c1
5 changed files with 20 additions and 24 deletions
|
|
@ -7,7 +7,7 @@ use std::{
|
|||
};
|
||||
use unicode_segmentation::UnicodeSegmentation;
|
||||
|
||||
use crate::{LayoutGlyph, LayoutLine, FontMatches, FontShapeLine};
|
||||
use crate::{Attrs, LayoutGlyph, LayoutLine, FontMatches, FontShapeLine, FontSystem};
|
||||
|
||||
/// An action to perform on a [TextBuffer]
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||
|
|
@ -238,6 +238,7 @@ impl TextBufferLine {
|
|||
/// A buffer of text that is shaped and laid out
|
||||
pub struct TextBuffer<'a> {
|
||||
font_matches: FontMatches<'a>,
|
||||
attrs: Attrs<'a>,
|
||||
lines: Vec<TextBufferLine>,
|
||||
metrics: TextMetrics,
|
||||
width: i32,
|
||||
|
|
@ -250,11 +251,14 @@ pub struct TextBuffer<'a> {
|
|||
|
||||
impl<'a> TextBuffer<'a> {
|
||||
pub fn new(
|
||||
font_matches: FontMatches<'a>,
|
||||
font_system: &'a FontSystem<'a>,
|
||||
attrs: Attrs<'a>,
|
||||
metrics: TextMetrics,
|
||||
) -> Self {
|
||||
let font_matches = font_system.matches_attrs(&attrs);
|
||||
let mut buffer = Self {
|
||||
font_matches,
|
||||
attrs,
|
||||
lines: Vec::new(),
|
||||
metrics,
|
||||
width: 0,
|
||||
|
|
|
|||
|
|
@ -80,7 +80,7 @@ impl<'a> FontSystem<'a> {
|
|||
pub fn matches<F: Fn(&fontdb::FaceInfo) -> bool>(
|
||||
&'a self,
|
||||
f: F,
|
||||
) -> Option<FontMatches<'_>> {
|
||||
) -> FontMatches<'_> {
|
||||
let mut fonts = Vec::new();
|
||||
for face in self.db.faces() {
|
||||
if !f(face) {
|
||||
|
|
@ -93,17 +93,13 @@ impl<'a> FontSystem<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
if !fonts.is_empty() {
|
||||
Some(FontMatches {
|
||||
locale: &self.locale,
|
||||
fonts
|
||||
})
|
||||
} else {
|
||||
None
|
||||
FontMatches {
|
||||
locale: &self.locale,
|
||||
fonts
|
||||
}
|
||||
}
|
||||
|
||||
pub fn matches_attrs(&'a self, attrs: Attrs) -> Option<FontMatches<'_>> {
|
||||
pub fn matches_attrs(&'a self, attrs: &Attrs) -> FontMatches<'_> {
|
||||
self.matches(|face| {
|
||||
let matched = attrs.matches(face);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue