no_std support
This commit is contained in:
parent
e95671f68f
commit
268805ba0c
18 changed files with 190 additions and 38 deletions
25
Cargo.toml
25
Cargo.toml
|
|
@ -9,19 +9,34 @@ documentation = "https://docs.rs/cosmic-text/latest/cosmic_text/"
|
||||||
repository = "https://github.com/pop-os/cosmic-text"
|
repository = "https://github.com/pop-os/cosmic-text"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
fontdb = "0.9.3"
|
fontdb = { version = "0.10", default-features = false }
|
||||||
|
libm = "0.2"
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
ouroboros = "0.15.5"
|
ouroboros = "0.15.5"
|
||||||
rustybuzz = "0.5"
|
rustybuzz = { version = "0.5", default-features = false, features = ["libm"]}
|
||||||
swash = { version = "0.1", optional = true }
|
swash = { version = "0.1", optional = true }
|
||||||
sys-locale = "0.2"
|
sys-locale = { version = "0.2", optional = true }
|
||||||
unicode-bidi = "0.3"
|
|
||||||
unicode-linebreak = "0.1"
|
unicode-linebreak = "0.1"
|
||||||
unicode-script = "0.5"
|
unicode-script = "0.5"
|
||||||
unicode-segmentation = "1.7"
|
unicode-segmentation = "1.7"
|
||||||
|
|
||||||
|
[dependencies.unicode-bidi]
|
||||||
|
version = "0.3"
|
||||||
|
default-features = false
|
||||||
|
features = ["hardcoded-data"]
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["swash"]
|
default = ["std", "swash"]
|
||||||
|
no_std = [
|
||||||
|
"rustybuzz/libm",
|
||||||
|
]
|
||||||
|
std = [
|
||||||
|
"fontdb/memmap",
|
||||||
|
"fontdb/std",
|
||||||
|
"rustybuzz/std",
|
||||||
|
"sys-locale",
|
||||||
|
"unicode-bidi/std",
|
||||||
|
]
|
||||||
|
|
||||||
[workspace]
|
[workspace]
|
||||||
members = [
|
members = [
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
// SPDX-License-Identifier: MIT OR Apache-2.0
|
||||||
|
|
||||||
use cosmic_text::{Attrs, Color, FontSystem, SwashCache, Buffer, Metrics};
|
use cosmic_text::{Attrs, Color, FontSystem, SwashCache, Buffer, Metrics};
|
||||||
use std::cmp;
|
use std::cmp;
|
||||||
use termion::{
|
use termion::{
|
||||||
|
|
@ -92,9 +94,9 @@ fn main() {
|
||||||
print!(
|
print!(
|
||||||
"{} {}",
|
"{} {}",
|
||||||
color::Bg(color::Rgb(
|
color::Bg(color::Rgb(
|
||||||
scale(color.b()),
|
|
||||||
scale(color.g()),
|
|
||||||
scale(color.r()),
|
scale(color.r()),
|
||||||
|
scale(color.g()),
|
||||||
|
scale(color.b()),
|
||||||
)),
|
)),
|
||||||
color::Bg(color::Reset),
|
color::Bg(color::Reset),
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,11 @@
|
||||||
// SPDX-License-Identifier: MIT OR Apache-2.0
|
// SPDX-License-Identifier: MIT OR Apache-2.0
|
||||||
|
|
||||||
use std::ops::Range;
|
#[cfg(not(feature = "std"))]
|
||||||
|
use alloc::{
|
||||||
|
string::{String, ToString},
|
||||||
|
vec::Vec,
|
||||||
|
};
|
||||||
|
use core::ops::Range;
|
||||||
|
|
||||||
pub use fontdb::{Family, Stretch, Style, Weight};
|
pub use fontdb::{Family, Stretch, Style, Weight};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,19 @@
|
||||||
// SPDX-License-Identifier: MIT OR Apache-2.0
|
// SPDX-License-Identifier: MIT OR Apache-2.0
|
||||||
|
|
||||||
use std::{
|
#[cfg(not(feature = "std"))]
|
||||||
|
use alloc::{
|
||||||
|
string::{String, ToString},
|
||||||
|
vec::Vec,
|
||||||
|
};
|
||||||
|
use core::{
|
||||||
cmp,
|
cmp,
|
||||||
fmt,
|
fmt,
|
||||||
time::Instant,
|
|
||||||
};
|
};
|
||||||
use unicode_segmentation::UnicodeSegmentation;
|
use unicode_segmentation::UnicodeSegmentation;
|
||||||
|
|
||||||
use crate::{Attrs, AttrsList, BufferLine, Color, FontSystem, LayoutGlyph, LayoutLine, ShapeLine};
|
use crate::{Attrs, AttrsList, BufferLine, FontSystem, LayoutGlyph, LayoutLine, ShapeLine};
|
||||||
|
#[cfg(feature = "swash")]
|
||||||
|
use crate::Color;
|
||||||
|
|
||||||
/// Current cursor location
|
/// Current cursor location
|
||||||
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
|
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
|
||||||
|
|
@ -170,7 +176,8 @@ impl<'a> Buffer<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn relayout(&mut self) {
|
fn relayout(&mut self) {
|
||||||
let instant = Instant::now();
|
#[cfg(feature = "std")]
|
||||||
|
let instant = std::time::Instant::now();
|
||||||
|
|
||||||
for line in self.lines.iter_mut() {
|
for line in self.lines.iter_mut() {
|
||||||
if line.shape_opt().is_some() {
|
if line.shape_opt().is_some() {
|
||||||
|
|
@ -185,13 +192,14 @@ impl<'a> Buffer<'a> {
|
||||||
|
|
||||||
self.redraw = true;
|
self.redraw = true;
|
||||||
|
|
||||||
let duration = instant.elapsed();
|
#[cfg(feature = "std")]
|
||||||
log::debug!("relayout: {:?}", duration);
|
log::debug!("relayout: {:?}", instant.elapsed());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Pre-shape lines in the buffer, up to `lines`, return actual number of layout lines
|
/// Pre-shape lines in the buffer, up to `lines`, return actual number of layout lines
|
||||||
pub fn shape_until(&mut self, lines: i32) -> i32 {
|
pub fn shape_until(&mut self, lines: i32) -> i32 {
|
||||||
let instant = Instant::now();
|
#[cfg(feature = "std")]
|
||||||
|
let instant = std::time::Instant::now();
|
||||||
|
|
||||||
let mut reshaped = 0;
|
let mut reshaped = 0;
|
||||||
let mut total_layout = 0;
|
let mut total_layout = 0;
|
||||||
|
|
@ -211,9 +219,9 @@ impl<'a> Buffer<'a> {
|
||||||
total_layout += layout.len() as i32;
|
total_layout += layout.len() as i32;
|
||||||
}
|
}
|
||||||
|
|
||||||
let duration = instant.elapsed();
|
|
||||||
if reshaped > 0 {
|
if reshaped > 0 {
|
||||||
log::debug!("shape_until {}: {:?}", reshaped, duration);
|
#[cfg(feature = "std")]
|
||||||
|
log::debug!("shape_until {}: {:?}", reshaped, instant.elapsed());
|
||||||
self.redraw = true;
|
self.redraw = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -222,7 +230,8 @@ impl<'a> Buffer<'a> {
|
||||||
|
|
||||||
/// Shape lines until cursor, also scrolling to include cursor in view
|
/// Shape lines until cursor, also scrolling to include cursor in view
|
||||||
pub fn shape_until_cursor(&mut self, cursor: Cursor) {
|
pub fn shape_until_cursor(&mut self, cursor: Cursor) {
|
||||||
let instant = Instant::now();
|
#[cfg(feature = "std")]
|
||||||
|
let instant = std::time::Instant::now();
|
||||||
|
|
||||||
let mut reshaped = 0;
|
let mut reshaped = 0;
|
||||||
let mut layout_i = 0;
|
let mut layout_i = 0;
|
||||||
|
|
@ -248,9 +257,9 @@ impl<'a> Buffer<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let duration = instant.elapsed();
|
|
||||||
if reshaped > 0 {
|
if reshaped > 0 {
|
||||||
log::debug!("shape_until_cursor {}: {:?}", reshaped, duration);
|
#[cfg(feature = "std")]
|
||||||
|
log::debug!("shape_until_cursor {}: {:?}", reshaped, instant.elapsed());
|
||||||
self.redraw = true;
|
self.redraw = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -409,7 +418,8 @@ impl<'a> Buffer<'a> {
|
||||||
|
|
||||||
/// Convert x, y position to Cursor (hit detection)
|
/// Convert x, y position to Cursor (hit detection)
|
||||||
pub fn hit(&self, x: i32, y: i32) -> Option<Cursor> {
|
pub fn hit(&self, x: i32, y: i32) -> Option<Cursor> {
|
||||||
let instant = Instant::now();
|
#[cfg(feature = "std")]
|
||||||
|
let instant = std::time::Instant::now();
|
||||||
|
|
||||||
let font_size = self.metrics.font_size;
|
let font_size = self.metrics.font_size;
|
||||||
let line_height = self.metrics.line_height;
|
let line_height = self.metrics.line_height;
|
||||||
|
|
@ -485,8 +495,8 @@ impl<'a> Buffer<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let duration = instant.elapsed();
|
#[cfg(feature = "std")]
|
||||||
log::trace!("click({}, {}): {:?}", x, y, duration);
|
log::trace!("click({}, {}): {:?}", x, y, instant.elapsed());
|
||||||
|
|
||||||
new_cursor_opt
|
new_cursor_opt
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,9 @@
|
||||||
|
#[cfg(not(feature = "std"))]
|
||||||
|
use alloc::{
|
||||||
|
string::String,
|
||||||
|
vec::Vec,
|
||||||
|
};
|
||||||
|
|
||||||
use crate::{AttrsList, FontSystem, LayoutLine, ShapeLine};
|
use crate::{AttrsList, FontSystem, LayoutLine, ShapeLine};
|
||||||
|
|
||||||
/// A line (or paragraph) of text that is shaped and laid out
|
/// A line (or paragraph) of text that is shaped and laid out
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
// SPDX-License-Identifier: MIT OR Apache-2.0
|
// SPDX-License-Identifier: MIT OR Apache-2.0
|
||||||
|
|
||||||
/// Key for building a glyph cache
|
/// Key for building a glyph cache
|
||||||
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
|
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
|
||||||
pub struct CacheKey {
|
pub struct CacheKey {
|
||||||
/// Font ID
|
/// Font ID
|
||||||
pub font_id: fontdb::ID,
|
pub font_id: fontdb::ID,
|
||||||
|
|
@ -39,7 +39,7 @@ impl CacheKey {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Binning of subpixel position for cache optimization
|
/// Binning of subpixel position for cache optimization
|
||||||
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
|
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
|
||||||
pub enum SubpixelBin {
|
pub enum SubpixelBin {
|
||||||
Zero,
|
Zero,
|
||||||
One,
|
One,
|
||||||
|
|
@ -49,8 +49,8 @@ pub enum SubpixelBin {
|
||||||
|
|
||||||
impl SubpixelBin {
|
impl SubpixelBin {
|
||||||
pub fn new(pos: f32) -> (i32, Self) {
|
pub fn new(pos: f32) -> (i32, Self) {
|
||||||
let trunc = pos.trunc() as i32;
|
let (fract, truncf) = libm::modff(pos);
|
||||||
let fract = pos.fract();
|
let trunc = truncf as i32;
|
||||||
if pos.is_sign_negative() {
|
if pos.is_sign_negative() {
|
||||||
if fract > -0.125 {
|
if fract > -0.125 {
|
||||||
(trunc, Self::Zero)
|
(trunc, Self::Zero)
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,14 @@
|
||||||
// SPDX-License-Identifier: MIT OR Apache-2.0
|
// SPDX-License-Identifier: MIT OR Apache-2.0
|
||||||
|
|
||||||
use std::cmp;
|
#[cfg(not(feature = "std"))]
|
||||||
|
use alloc::string::ToString;
|
||||||
|
#[cfg(feature = "swash")]
|
||||||
|
use core::cmp;
|
||||||
use unicode_segmentation::UnicodeSegmentation;
|
use unicode_segmentation::UnicodeSegmentation;
|
||||||
|
|
||||||
use crate::{AttrsList, Buffer, BufferLine, Color, Cursor, LayoutCursor};
|
use crate::{AttrsList, Buffer, BufferLine, Cursor, LayoutCursor};
|
||||||
|
#[cfg(feature = "swash")]
|
||||||
|
use crate::Color;
|
||||||
|
|
||||||
/// An action to perform on an [Editor]
|
/// An action to perform on an [Editor]
|
||||||
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
// SPDX-License-Identifier: MIT OR Apache-2.0
|
// SPDX-License-Identifier: MIT OR Apache-2.0
|
||||||
|
|
||||||
use std::sync::Arc;
|
use alloc::sync::Arc;
|
||||||
|
#[cfg(not(feature = "std"))]
|
||||||
|
use alloc::vec::Vec;
|
||||||
use unicode_script::Script;
|
use unicode_script::Script;
|
||||||
|
|
||||||
use crate::Font;
|
use crate::Font;
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
// SPDX-License-Identifier: MIT OR Apache-2.0
|
// SPDX-License-Identifier: MIT OR Apache-2.0
|
||||||
|
|
||||||
use std::ops::Deref;
|
use core::ops::Deref;
|
||||||
|
|
||||||
pub struct Font<'a> {
|
pub struct Font<'a> {
|
||||||
pub info: &'a fontdb::FaceInfo,
|
pub info: &'a fontdb::FaceInfo,
|
||||||
|
|
@ -14,10 +14,12 @@ impl<'a> Font<'a> {
|
||||||
pub fn new(info: &'a fontdb::FaceInfo) -> Option<Self> {
|
pub fn new(info: &'a fontdb::FaceInfo) -> Option<Self> {
|
||||||
let data = match &info.source {
|
let data = match &info.source {
|
||||||
fontdb::Source::Binary(data) => data.deref().as_ref(),
|
fontdb::Source::Binary(data) => data.deref().as_ref(),
|
||||||
|
#[cfg(feature = "std")]
|
||||||
fontdb::Source::File(path) => {
|
fontdb::Source::File(path) => {
|
||||||
log::warn!("Unsupported fontdb Source::File('{}')", path.display());
|
log::warn!("Unsupported fontdb Source::File('{}')", path.display());
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
#[cfg(feature = "std")]
|
||||||
fontdb::Source::SharedFile(_path, data) => data.deref().as_ref(),
|
fontdb::Source::SharedFile(_path, data) => data.deref().as_ref(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,11 @@
|
||||||
// SPDX-License-Identifier: MIT OR Apache-2.0
|
// SPDX-License-Identifier: MIT OR Apache-2.0
|
||||||
|
|
||||||
use std::sync::Arc;
|
use alloc::sync::Arc;
|
||||||
|
#[cfg(not(feature = "std"))]
|
||||||
|
use alloc::{
|
||||||
|
string::String,
|
||||||
|
vec::Vec,
|
||||||
|
};
|
||||||
|
|
||||||
use crate::Font;
|
use crate::Font;
|
||||||
|
|
||||||
|
|
|
||||||
9
src/font/system/mod.rs
Normal file
9
src/font/system/mod.rs
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
#[cfg(not(feature = "std"))]
|
||||||
|
pub use self::no_std::*;
|
||||||
|
#[cfg(not(feature = "std"))]
|
||||||
|
mod no_std;
|
||||||
|
|
||||||
|
#[cfg(feature = "std")]
|
||||||
|
pub use self::std::*;
|
||||||
|
#[cfg(feature = "std")]
|
||||||
|
mod std;
|
||||||
75
src/font/system/no_std.rs
Normal file
75
src/font/system/no_std.rs
Normal file
|
|
@ -0,0 +1,75 @@
|
||||||
|
// SPDX-License-Identifier: MIT OR Apache-2.0
|
||||||
|
|
||||||
|
use alloc::{
|
||||||
|
string::{String, ToString},
|
||||||
|
sync::Arc,
|
||||||
|
vec::Vec,
|
||||||
|
};
|
||||||
|
|
||||||
|
use crate::{Attrs, Font, FontMatches};
|
||||||
|
|
||||||
|
/// Access system fonts
|
||||||
|
pub struct FontSystem{
|
||||||
|
locale: String,
|
||||||
|
db: fontdb::Database,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl FontSystem {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
//TODO: get locale from argument?
|
||||||
|
let locale = "en-US".to_string();
|
||||||
|
|
||||||
|
//TODO: allow loading fonts from memory
|
||||||
|
let mut db = fontdb::Database::new();
|
||||||
|
{
|
||||||
|
//TODO: configurable default fonts
|
||||||
|
db.set_monospace_family("Fira Mono");
|
||||||
|
db.set_sans_serif_family("Fira Sans");
|
||||||
|
db.set_serif_family("DejaVu Serif");
|
||||||
|
}
|
||||||
|
|
||||||
|
Self {
|
||||||
|
locale,
|
||||||
|
db,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn locale(&self) -> &str {
|
||||||
|
&self.locale
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn db(&self) -> &fontdb::Database {
|
||||||
|
&self.db
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_font<'a>(&'a self, id: fontdb::ID) -> Option<Arc<Font<'a>>> {
|
||||||
|
let face = self.db.face(id)?;
|
||||||
|
match Font::new(face) {
|
||||||
|
Some(font) => Some(Arc::new(font)),
|
||||||
|
None => {
|
||||||
|
log::warn!("failed to load font '{}'", face.post_script_name);
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_font_matches<'a>(&'a self, attrs: Attrs) -> Arc<FontMatches<'a>> {
|
||||||
|
let mut fonts = Vec::new();
|
||||||
|
for face in self.db.faces() {
|
||||||
|
if !attrs.matches(face) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
match self.get_font(face.id) {
|
||||||
|
Some(font) => fonts.push(font),
|
||||||
|
None => (),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Arc::new(FontMatches {
|
||||||
|
locale: &self.locale,
|
||||||
|
default_family: self.db.family_name(&attrs.family).to_string(),
|
||||||
|
fonts
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,5 +1,8 @@
|
||||||
// SPDX-License-Identifier: MIT OR Apache-2.0
|
// SPDX-License-Identifier: MIT OR Apache-2.0
|
||||||
|
|
||||||
|
#[cfg(not(feature = "std"))]
|
||||||
|
use alloc::vec::Vec;
|
||||||
|
|
||||||
use crate::{CacheKey, Color};
|
use crate::{CacheKey, Color};
|
||||||
|
|
||||||
/// A laid out glyph
|
/// A laid out glyph
|
||||||
|
|
|
||||||
|
|
@ -54,6 +54,10 @@
|
||||||
//! });
|
//! });
|
||||||
//! ```
|
//! ```
|
||||||
|
|
||||||
|
#![cfg_attr(not(feature = "std"), no_std)]
|
||||||
|
|
||||||
|
extern crate alloc;
|
||||||
|
|
||||||
pub use self::attrs::*;
|
pub use self::attrs::*;
|
||||||
mod attrs;
|
mod attrs;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,8 @@
|
||||||
// SPDX-License-Identifier: MIT OR Apache-2.0
|
// SPDX-License-Identifier: MIT OR Apache-2.0
|
||||||
|
|
||||||
|
#[cfg(not(feature = "std"))]
|
||||||
|
use alloc::vec::Vec;
|
||||||
|
use core::mem;
|
||||||
use unicode_script::{Script, UnicodeScript};
|
use unicode_script::{Script, UnicodeScript};
|
||||||
use unicode_segmentation::UnicodeSegmentation;
|
use unicode_segmentation::UnicodeSegmentation;
|
||||||
|
|
||||||
|
|
@ -592,7 +595,7 @@ impl ShapeLine {
|
||||||
};
|
};
|
||||||
if word_wrap && !wrap_simple && !glyphs.is_empty() {
|
if word_wrap && !wrap_simple && !glyphs.is_empty() {
|
||||||
let mut glyphs_swap = Vec::new();
|
let mut glyphs_swap = Vec::new();
|
||||||
std::mem::swap(&mut glyphs, &mut glyphs_swap);
|
mem::swap(&mut glyphs, &mut glyphs_swap);
|
||||||
layout_lines.push(
|
layout_lines.push(
|
||||||
LayoutLine {
|
LayoutLine {
|
||||||
glyphs: glyphs_swap,
|
glyphs: glyphs_swap,
|
||||||
|
|
@ -616,7 +619,7 @@ impl ShapeLine {
|
||||||
|
|
||||||
if glyph_wrap {
|
if glyph_wrap {
|
||||||
let mut glyphs_swap = Vec::new();
|
let mut glyphs_swap = Vec::new();
|
||||||
std::mem::swap(&mut glyphs, &mut glyphs_swap);
|
mem::swap(&mut glyphs, &mut glyphs_swap);
|
||||||
layout_lines.push(
|
layout_lines.push(
|
||||||
LayoutLine {
|
LayoutLine {
|
||||||
glyphs: glyphs_swap,
|
glyphs: glyphs_swap,
|
||||||
|
|
@ -643,7 +646,7 @@ impl ShapeLine {
|
||||||
|
|
||||||
if wrap {
|
if wrap {
|
||||||
let mut glyphs_swap = Vec::new();
|
let mut glyphs_swap = Vec::new();
|
||||||
std::mem::swap(&mut glyphs, &mut glyphs_swap);
|
mem::swap(&mut glyphs, &mut glyphs_swap);
|
||||||
layout_lines.push(
|
layout_lines.push(
|
||||||
LayoutLine {
|
LayoutLine {
|
||||||
glyphs: glyphs_swap,
|
glyphs: glyphs_swap,
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,9 @@
|
||||||
// SPDX-License-Identifier: MIT OR Apache-2.0
|
// SPDX-License-Identifier: MIT OR Apache-2.0
|
||||||
|
|
||||||
use std::collections::HashMap;
|
#[cfg(not(feature = "std"))]
|
||||||
|
use alloc::collections::BTreeMap as Map;
|
||||||
|
#[cfg(feature = "std")]
|
||||||
|
use std::collections::HashMap as Map;
|
||||||
use swash::scale::{ScaleContext, image::Content};
|
use swash::scale::{ScaleContext, image::Content};
|
||||||
use swash::scale::{Render, Source, StrikeWith};
|
use swash::scale::{Render, Source, StrikeWith};
|
||||||
use swash::zeno::{Format, Vector};
|
use swash::zeno::{Format, Vector};
|
||||||
|
|
@ -51,7 +54,7 @@ fn swash_image<'a>(font_system: &'a FontSystem, context: &mut ScaleContext, cach
|
||||||
pub struct SwashCache<'a> {
|
pub struct SwashCache<'a> {
|
||||||
font_system: &'a FontSystem,
|
font_system: &'a FontSystem,
|
||||||
context: ScaleContext,
|
context: ScaleContext,
|
||||||
pub image_cache: HashMap<CacheKey, Option<SwashImage>>,
|
pub image_cache: Map<CacheKey, Option<SwashImage>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> SwashCache<'a> {
|
impl<'a> SwashCache<'a> {
|
||||||
|
|
@ -60,7 +63,7 @@ impl<'a> SwashCache<'a> {
|
||||||
Self {
|
Self {
|
||||||
font_system: font_system,
|
font_system: font_system,
|
||||||
context: ScaleContext::new(),
|
context: ScaleContext::new(),
|
||||||
image_cache: HashMap::new()
|
image_cache: Map::new()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
3
test.sh
3
test.sh
|
|
@ -4,5 +4,8 @@ set -ex
|
||||||
|
|
||||||
cargo doc
|
cargo doc
|
||||||
cargo test
|
cargo test
|
||||||
|
cargo build --release --no-default-features
|
||||||
|
cargo build --release --no-default-features --features std
|
||||||
|
cargo build --release --no-default-features --features swash
|
||||||
cargo build --release --all
|
cargo build --release --all
|
||||||
env RUST_LOG=editor_test=info target/release/editor-test
|
env RUST_LOG=editor_test=info target/release/editor-test
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue