Enum cosmic_text::SubpixelBin
source · pub enum SubpixelBin {
Zero,
One,
Two,
Three,
}Expand description
Binning of subpixel position for cache optimization
Variants§
Implementations§
source§impl SubpixelBin
impl SubpixelBin
sourcepub fn new(pos: f32) -> (i32, Self)
pub fn new(pos: f32) -> (i32, Self)
Examples found in repository?
src/cache.rs (line 25)
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
pub fn new(
font_id: fontdb::ID,
glyph_id: u16,
font_size: i32,
pos: (f32, f32),
) -> (Self, i32, i32) {
let (x, x_bin) = SubpixelBin::new(pos.0);
let (y, y_bin) = SubpixelBin::new(pos.1);
(
Self {
font_id,
glyph_id,
font_size,
x_bin,
y_bin,
},
x,
y,
)
}sourcepub fn as_float(&self) -> f32
pub fn as_float(&self) -> f32
Examples found in repository?
src/swash.rs (line 37)
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
fn swash_image(font_system: &FontSystem, context: &mut ScaleContext, cache_key: CacheKey) -> Option<SwashImage> {
let font = match font_system.get_font(cache_key.font_id) {
Some(some) => some,
None => {
log::warn!("did not find font {:?}", cache_key.font_id);
return None;
},
};
// Build the scaler
let mut scaler = context
.builder(font.as_swash())
.size(cache_key.font_size as f32)
.hint(true)
.build();
// Compute the fractional offset-- you'll likely want to quantize this
// in a real renderer
let offset =
Vector::new(cache_key.x_bin.as_float(), cache_key.y_bin.as_float());
// Select our source order
Render::new(&[
// Color outline with the first palette
Source::ColorOutline(0),
// Color bitmap with best fit selection mode
Source::ColorBitmap(StrikeWith::BestFit),
// Standard scalable outline
Source::Outline,
])
// Select a subpixel format
.format(Format::Alpha)
// Apply the fractional offset
.offset(offset)
// Render the image
.render(&mut scaler, cache_key.glyph_id)
}Trait Implementations§
source§impl Clone for SubpixelBin
impl Clone for SubpixelBin
source§fn clone(&self) -> SubpixelBin
fn clone(&self) -> SubpixelBin
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moresource§impl Debug for SubpixelBin
impl Debug for SubpixelBin
source§impl Hash for SubpixelBin
impl Hash for SubpixelBin
source§impl Ord for SubpixelBin
impl Ord for SubpixelBin
source§fn cmp(&self, other: &SubpixelBin) -> Ordering
fn cmp(&self, other: &SubpixelBin) -> Ordering
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
source§impl PartialEq<SubpixelBin> for SubpixelBin
impl PartialEq<SubpixelBin> for SubpixelBin
source§fn eq(&self, other: &SubpixelBin) -> bool
fn eq(&self, other: &SubpixelBin) -> bool
This method tests for
self and other values to be equal, and is used
by ==.source§impl PartialOrd<SubpixelBin> for SubpixelBin
impl PartialOrd<SubpixelBin> for SubpixelBin
source§fn partial_cmp(&self, other: &SubpixelBin) -> Option<Ordering>
fn partial_cmp(&self, other: &SubpixelBin) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self and other) and is used by the <=
operator. Read more