Fix no_std build
This fixes the `no_std` build and also makes sure it's tested properly in the CI workflow.
This commit is contained in:
parent
0cb6eba6e7
commit
8582173128
8 changed files with 31 additions and 10 deletions
|
|
@ -2,8 +2,6 @@
|
|||
|
||||
use alloc::collections::BTreeSet;
|
||||
use alloc::sync::Arc;
|
||||
#[cfg(not(feature = "std"))]
|
||||
use alloc::vec::Vec;
|
||||
use fontdb::Family;
|
||||
use unicode_script::Script;
|
||||
|
||||
|
|
|
|||
|
|
@ -63,8 +63,9 @@ pub enum SubpixelBin {
|
|||
|
||||
impl SubpixelBin {
|
||||
pub fn new(pos: f32) -> (i32, Self) {
|
||||
let (fract, truncf) = libm::modff(pos);
|
||||
let trunc = truncf as i32;
|
||||
let trunc = pos as i32;
|
||||
let fract = pos - trunc as f32;
|
||||
|
||||
if pos.is_sign_negative() {
|
||||
if fract > -0.125 {
|
||||
(trunc, Self::Zero)
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ use core::fmt::Display;
|
|||
#[cfg(not(feature = "std"))]
|
||||
use alloc::vec::Vec;
|
||||
|
||||
use crate::{CacheKey, CacheKeyFlags, Color};
|
||||
use crate::{math, CacheKey, CacheKeyFlags, Color};
|
||||
|
||||
/// A laid out glyph
|
||||
#[derive(Clone, Debug)]
|
||||
|
|
@ -75,7 +75,7 @@ impl LayoutGlyph {
|
|||
self.font_size * scale,
|
||||
(
|
||||
(self.x + x_offset) * scale + offset.0,
|
||||
libm::truncf((self.y - y_offset) * scale + offset.1), // Hinting in Y axis
|
||||
math::truncf((self.y - y_offset) * scale + offset.1), // Hinting in Y axis
|
||||
),
|
||||
self.cache_key_flags,
|
||||
);
|
||||
|
|
|
|||
|
|
@ -137,6 +137,8 @@ pub use self::swash::*;
|
|||
#[cfg(feature = "swash")]
|
||||
mod swash;
|
||||
|
||||
mod math;
|
||||
|
||||
type BuildHasher = core::hash::BuildHasherDefault<rustc_hash::FxHasher>;
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
|
|
|
|||
14
src/math.rs
Normal file
14
src/math.rs
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
#[cfg(not(feature = "std"))]
|
||||
pub use libm::{roundf, truncf};
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
#[inline]
|
||||
pub fn roundf(x: f32) -> f32 {
|
||||
x.round()
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
#[inline]
|
||||
pub fn truncf(x: f32) -> f32 {
|
||||
x.trunc()
|
||||
}
|
||||
|
|
@ -13,7 +13,7 @@ use unicode_segmentation::UnicodeSegmentation;
|
|||
|
||||
use crate::fallback::FontFallbackIter;
|
||||
use crate::{
|
||||
Align, AttrsList, CacheKeyFlags, Color, Font, FontSystem, LayoutGlyph, LayoutLine,
|
||||
math, Align, AttrsList, CacheKeyFlags, Color, Font, FontSystem, LayoutGlyph, LayoutLine,
|
||||
ShapePlanCache, Wrap,
|
||||
};
|
||||
|
||||
|
|
@ -1394,7 +1394,8 @@ impl ShapeLine {
|
|||
if glyph_em_width != match_em_width =>
|
||||
{
|
||||
let glyph_to_match_factor = glyph_em_width / match_em_width;
|
||||
let glyph_font_size = glyph_to_match_factor.round().max(1.0)
|
||||
let glyph_font_size = math::roundf(glyph_to_match_factor)
|
||||
.max(1.0)
|
||||
/ glyph_to_match_factor
|
||||
* font_size;
|
||||
log::trace!("Adjusted glyph font size ({font_size} => {glyph_font_size})");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue