aboutsummaryrefslogtreecommitdiff
path: root/font/src/ft
diff options
context:
space:
mode:
Diffstat (limited to 'font/src/ft')
-rw-r--r--font/src/ft/fc/char_set.rs2
-rw-r--r--font/src/ft/fc/config.rs2
-rw-r--r--font/src/ft/fc/font_set.rs4
-rw-r--r--font/src/ft/fc/mod.rs12
-rw-r--r--font/src/ft/fc/pattern.rs34
-rw-r--r--font/src/ft/mod.rs79
6 files changed, 67 insertions, 66 deletions
diff --git a/font/src/ft/fc/char_set.rs b/font/src/ft/fc/char_set.rs
index 4bba4818..a60513c2 100644
--- a/font/src/ft/fc/char_set.rs
+++ b/font/src/ft/fc/char_set.rs
@@ -70,7 +70,7 @@ impl CharSetRef {
pub fn merge(&self, other: &CharSetRef) -> Result<bool, ()> {
unsafe {
- // Value is just an indicator whether something was added or not
+ // Value is just an indicator whether something was added or not.
let mut value: FcBool = 0;
let res = FcCharSetMerge(self.as_ptr() as _, other.as_ptr() as _, &mut value);
if res == 0 {
diff --git a/font/src/ft/fc/config.rs b/font/src/ft/fc/config.rs
index 44bb9986..868d2c42 100644
--- a/font/src/ft/fc/config.rs
+++ b/font/src/ft/fc/config.rs
@@ -24,7 +24,7 @@ foreign_type! {
}
impl Config {
- /// Get the current configuration
+ /// Get the current configuration.
pub fn get_current() -> &'static ConfigRef {
unsafe { ConfigRef::from_ptr(FcConfigGetCurrent()) }
}
diff --git a/font/src/ft/fc/font_set.rs b/font/src/ft/fc/font_set.rs
index ae746f45..241ee344 100644
--- a/font/src/ft/fc/font_set.rs
+++ b/font/src/ft/fc/font_set.rs
@@ -39,7 +39,7 @@ impl FontSet {
FcFontSetList(
config.as_ptr(),
&mut source.as_ptr(),
- 1, // nsets
+ 1, // nsets.
pattern.as_ptr(),
objects.as_ptr(),
)
@@ -48,7 +48,7 @@ impl FontSet {
}
}
-/// Iterator over a font set
+/// Iterator over a font set.
pub struct Iter<'a> {
font_set: &'a FontSetRef,
num_fonts: usize,
diff --git a/font/src/ft/fc/mod.rs b/font/src/ft/fc/mod.rs
index ecb056f7..b1b66be6 100644
--- a/font/src/ft/fc/mod.rs
+++ b/font/src/ft/fc/mod.rs
@@ -72,7 +72,7 @@ pub fn font_sort(config: &ConfigRef, pattern: &PatternRef) -> Option<FontSet> {
let ptr = FcFontSort(
config.as_ptr(),
pattern.as_ptr(),
- 1, // Trim font list
+ 1, // Trim font list.
&mut charsets,
&mut result,
);
@@ -102,14 +102,14 @@ pub fn font_list(
}
}
-/// Available font sets
+/// Available font sets.
#[derive(Debug, Copy, Clone)]
pub enum SetName {
System = FcSetSystem as isize,
Application = FcSetApplication as isize,
}
-/// When matching, how to match
+/// When matching, how to match.
#[derive(Debug, Copy, Clone)]
pub enum MatchKind {
Font = FcMatchFont as isize,
@@ -187,7 +187,7 @@ impl From<isize> for Width {
}
}
-/// Subpixel geometry
+/// Subpixel geometry.
#[derive(Debug)]
pub enum Rgba {
Unknown,
@@ -237,7 +237,7 @@ impl From<isize> for Rgba {
}
}
-/// Hinting Style
+/// Hinting Style.
#[derive(Debug, Copy, Clone)]
pub enum HintStyle {
None,
@@ -257,7 +257,7 @@ impl fmt::Display for HintStyle {
}
}
-/// Lcd filter, used to reduce color fringing with subpixel rendering
+/// Lcd filter, used to reduce color fringing with subpixel rendering.
pub enum LcdFilter {
None,
Default,
diff --git a/font/src/ft/fc/pattern.rs b/font/src/ft/fc/pattern.rs
index 53641f67..f40cc9c9 100644
--- a/font/src/ft/fc/pattern.rs
+++ b/font/src/ft/fc/pattern.rs
@@ -54,7 +54,7 @@ impl<'a> StringPropertyIter<'a> {
};
if result == FcResultMatch {
- // Transmute here is to extend lifetime of the str to that of the iterator
+ // Transmute here is to extend lifetime of the str to that of the iterator.
//
// Potential unsafety? What happens if the pattern is modified while this ptr is
// borrowed out?
@@ -67,7 +67,7 @@ impl<'a> StringPropertyIter<'a> {
}
}
-/// Iterator over integer properties
+/// Iterator over integer properties.
pub struct BooleanPropertyIter<'a> {
pattern: &'a PatternRef,
object: &'a [u8],
@@ -99,7 +99,7 @@ impl<'a> BooleanPropertyIter<'a> {
}
}
-/// Iterator over integer properties
+/// Iterator over integer properties.
pub struct IntPropertyIter<'a> {
pattern: &'a PatternRef,
object: &'a [u8],
@@ -204,7 +204,7 @@ impl<'a> LcdFilterPropertyIter<'a> {
}
}
-/// Iterator over integer properties
+/// Iterator over integer properties.
pub struct DoublePropertyIter<'a> {
pattern: &'a PatternRef,
object: &'a [u8],
@@ -236,7 +236,7 @@ impl<'a> DoublePropertyIter<'a> {
}
}
-/// Implement debug for a property iterator
+/// Implement debug for a property iterator.
macro_rules! impl_property_iter_debug {
($iter:ty => $item:ty) => {
impl<'a> fmt::Debug for $iter {
@@ -260,7 +260,7 @@ macro_rules! impl_property_iter_debug {
};
}
-/// Implement Iterator and Debug for a property iterator
+/// Implement Iterator and Debug for a property iterator.
macro_rules! impl_property_iter {
($($iter:ty => $item:ty),*) => {
$(
@@ -310,7 +310,7 @@ macro_rules! impl_derived_property_iter {
}
}
-// Basic Iterators
+// Basic Iterators.
impl_property_iter! {
StringPropertyIter<'a> => &'a str,
IntPropertyIter<'a> => isize,
@@ -318,7 +318,7 @@ impl_property_iter! {
BooleanPropertyIter<'a> => bool
}
-// Derived Iterators
+// Derived Iterators.
impl_derived_property_iter! {
RgbaPropertyIter<'a> => Rgba,
HintStylePropertyIter<'a> => HintStyle,
@@ -460,23 +460,23 @@ impl PatternRef {
index() => b"index\0"
}
- // Prints the pattern to stdout
- //
- // FontConfig doesn't expose a way to iterate over all members of a pattern;
- // instead, we just defer to FcPatternPrint. Otherwise, this could have been
- // a `fmt::Debug` impl.
+ /// Prints the pattern to stdout.
+ ///
+ /// FontConfig doesn't expose a way to iterate over all members of a pattern;
+ /// instead, we just defer to FcPatternPrint. Otherwise, this could have been
+ /// a `fmt::Debug` impl.
pub fn print(&self) {
unsafe { FcPatternPrint(self.as_ptr()) }
}
- /// Add a string value to the pattern
+ /// Add a string value to the pattern.
///
/// If the returned value is `true`, the value is added at the end of
/// any existing list, otherwise it is inserted at the beginning.
///
/// # Unsafety
///
- /// `object` is not checked to be a valid null-terminated string
+ /// `object` is not checked to be a valid null-terminated string.
unsafe fn add_string(&mut self, object: &[u8], value: &str) -> bool {
let value = CString::new(&value[..]).unwrap();
let value = value.as_ptr();
@@ -556,9 +556,9 @@ impl PatternRef {
unsafe { PatternHash(FcPatternHash(self.as_ptr())) }
}
- /// Add charset to the pattern
+ /// Add charset to the pattern.
///
- /// The referenced charset is copied by fontconfig internally using
+ /// The referenced charset is copied by Fontconfig internally using
/// FcValueSave so that no references to application provided memory are
/// retained. That is, the CharSet can be safely dropped immediately
/// after being added to the pattern.
diff --git a/font/src/ft/mod.rs b/font/src/ft/mod.rs
index d393b63f..ef1afb5f 100644
--- a/font/src/ft/mod.rs
+++ b/font/src/ft/mod.rs
@@ -46,7 +46,7 @@ impl FallbackFont {
impl FontKey {
fn from_pattern_hashes(lhs: PatternHash, rhs: PatternHash) -> Self {
- // XOR two hashes to get a font ID
+ // XOR two hashes to get a font ID.
Self { token: lhs.0.rotate_left(1) ^ rhs.0 }
}
}
@@ -121,18 +121,18 @@ impl Rasterize for FreeTypeRasterizer {
let height = (full.size_metrics.height / 64) as f64;
let descent = (full.size_metrics.descender / 64) as f32;
- // Get underline position and thickness in device pixels
+ // Get underline position and thickness in device pixels.
let x_scale = full.size_metrics.x_scale as f32 / 65536.0;
let mut underline_position = f32::from(face.ft_face.underline_position()) * x_scale / 64.;
let mut underline_thickness = f32::from(face.ft_face.underline_thickness()) * x_scale / 64.;
- // Fallback for bitmap fonts which do not provide underline metrics
+ // Fallback for bitmap fonts which do not provide underline metrics.
if underline_position == 0. {
underline_thickness = (descent.abs() / 5.).round();
underline_position = descent / 2.;
}
- // Get strikeout position and thickness in device pixels
+ // Get strikeout position and thickness in device pixels.
let (strikeout_position, strikeout_thickness) =
match TrueTypeOS2Table::from_face(&mut (*face.ft_face).clone()) {
Some(os2) => {
@@ -141,7 +141,7 @@ impl Rasterize for FreeTypeRasterizer {
(strikeout_position, strikeout_thickness)
},
_ => {
- // Fallback if font doesn't provide info about strikeout
+ // Fallback if font doesn't provide info about strikeout.
trace!("Using fallback strikeout metrics");
let strikeout_position = height as f32 / 2. + descent;
(strikeout_position, underline_thickness)
@@ -206,9 +206,9 @@ struct FullMetrics {
}
impl FreeTypeRasterizer {
- /// Load a font face according to `FontDesc`
+ /// Load a font face according to `FontDesc`.
fn get_face(&mut self, desc: &FontDesc, size: Size) -> Result<FontKey, Error> {
- // Adjust for DPI
+ // Adjust for DPR.
let size = f64::from(size.as_f32_pts() * self.device_pixel_ratio * 96. / 72.);
let config = fc::Config::get_current();
@@ -216,26 +216,26 @@ impl FreeTypeRasterizer {
pattern.add_family(&desc.name);
pattern.add_pixelsize(size);
- // Add style to a pattern
+ // Add style to a pattern.
match desc.style {
Style::Description { slant, weight } => {
- // Match nearest font
+ // Match nearest font.
pattern.set_weight(weight.into_fontconfig_type());
pattern.set_slant(slant.into_fontconfig_type());
},
Style::Specific(ref style) => {
- // If a name was specified, try and load specifically that font
+ // If a name was specified, try and load specifically that font.
pattern.add_style(style);
},
}
- // Hash requested pattern
+ // Hash requested pattern.
let hash = pattern.hash();
pattern.config_substitute(config, fc::MatchKind::Pattern);
pattern.default_substitute();
- // Get font list using pattern. First font is the primary one while the rest are fallbacks
+ // Get font list using pattern. First font is the primary one while the rest are fallbacks.
let matched_fonts =
fc::font_sort(&config, &pattern).ok_or_else(|| Error::MissingFont(desc.to_owned()))?;
let mut matched_fonts = matched_fonts.into_iter();
@@ -243,24 +243,24 @@ impl FreeTypeRasterizer {
let primary_font =
matched_fonts.next().ok_or_else(|| Error::MissingFont(desc.to_owned()))?;
- // We should render patterns to get values like `pixelsizefixupfactor`
+ // We should render patterns to get values like `pixelsizefixupfactor`.
let primary_font = pattern.render_prepare(config, primary_font);
- // Hash pattern together with request pattern to include requested font size in the hash
+ // Hash pattern together with request pattern to include requested font size in the hash.
let primary_font_key = FontKey::from_pattern_hashes(hash, primary_font.hash());
- // Return if we already have the same primary font
+ // Return if we already have the same primary font.
if self.fallback_lists.contains_key(&primary_font_key) {
return Ok(primary_font_key);
}
- // Load font if we haven't loaded it yet
+ // Load font if we haven't loaded it yet.
if !self.faces.contains_key(&primary_font_key) {
self.face_from_pattern(&primary_font, primary_font_key)
.and_then(|pattern| pattern.ok_or_else(|| Error::MissingFont(desc.to_owned())))?;
}
- // Coverage for fallback fonts
+ // Coverage for fallback fonts.
let coverage = CharSet::new();
let empty_charset = CharSet::new();
@@ -268,7 +268,7 @@ impl FreeTypeRasterizer {
.map(|fallback_font| {
let charset = fallback_font.get_charset().unwrap_or(&empty_charset);
- // Use original pattern to preserve loading flags
+ // Use original pattern to preserve loading flags.
let fallback_font = pattern.render_prepare(config, fallback_font);
let fallback_font_key = FontKey::from_pattern_hashes(hash, fallback_font.hash());
@@ -299,7 +299,7 @@ impl FreeTypeRasterizer {
let mut ft_face = self.library.new_face(&ft_face_location.path, ft_face_location.index)?;
if ft_face.has_color() {
unsafe {
- // Select the colored bitmap size to use from the array of available sizes
+ // Select the colored bitmap size to use from the array of available sizes.
freetype_sys::FT_Select_Size(ft_face.raw_mut(), 0);
}
}
@@ -370,7 +370,7 @@ impl FreeTypeRasterizer {
fn load_face_with_glyph(&mut self, glyph: GlyphKey) -> Result<FontKey, Error> {
let fallback_list = self.fallback_lists.get(&glyph.font_key).unwrap();
- // Check whether glyph is presented in any fallback font
+ // Check whether glyph is presented in any fallback font.
if !fallback_list.coverage.has_char(glyph.c) {
return Ok(glyph.font_key);
}
@@ -382,7 +382,7 @@ impl FreeTypeRasterizer {
Some(face) => {
let index = face.ft_face.get_char_index(glyph.c as usize);
- // We found something in a current face, so let's use it
+ // We found something in a current face, so let's use it.
if index != 0 {
return Ok(font_key);
}
@@ -400,12 +400,12 @@ impl FreeTypeRasterizer {
}
}
- // You can hit this return, if you're failing to get charset from a pattern
+ // You can hit this return, if you're failing to get charset from a pattern.
Ok(glyph.font_key)
}
fn get_rendered_glyph(&mut self, glyph_key: GlyphKey) -> Result<RasterizedGlyph, Error> {
- // Render a normal character if it's not a cursor
+ // Render a normal character if it's not a cursor.
let font_key = self.face_for_glyph(glyph_key)?;
let face = &self.faces[&font_key];
let index = face.ft_face.get_char_index(glyph_key.c as usize);
@@ -442,7 +442,7 @@ impl FreeTypeRasterizer {
let fixup_factor = if let Some(pixelsize_fixup_factor) = face.pixelsize_fixup_factor {
pixelsize_fixup_factor
} else {
- // Fallback if user has bitmap scaling disabled
+ // Fallback if user has bitmap scaling disabled.
let metrics = face.ft_face.size_metrics().ok_or(Error::MissingSizeMetrics)?;
f64::from(pixelsize) / f64::from(metrics.y_ppem)
};
@@ -465,7 +465,7 @@ impl FreeTypeRasterizer {
(false, fc::HintStyle::None, _) => LoadFlag::NO_HINTING | LoadFlag::MONOCHROME,
(false, ..) => LoadFlag::TARGET_MONO | LoadFlag::MONOCHROME,
(true, fc::HintStyle::None, _) => LoadFlag::NO_HINTING | LoadFlag::TARGET_NORMAL,
- // hintslight does *not* use LCD hinting even when a subpixel mode
+ // `hintslight` does *not* use LCD hinting even when a subpixel mode
// is selected.
//
// According to the FreeType docs,
@@ -478,7 +478,7 @@ impl FreeTypeRasterizer {
// In practice, this means we can have `FT_LOAD_TARGET_LIGHT` with
// subpixel render modes like `FT_RENDER_MODE_LCD`. Libraries like
// cairo take the same approach and consider `hintslight` to always
- // prefer `FT_LOAD_TARGET_LIGHT`
+ // prefer `FT_LOAD_TARGET_LIGHT`.
(true, fc::HintStyle::Slight, _) => LoadFlag::TARGET_LIGHT,
// If LCD hinting is to be used, must select hintmedium or hintfull,
// have AA enabled, and select a subpixel mode.
@@ -565,7 +565,7 @@ impl FreeTypeRasterizer {
while count != 0 {
let value = ((byte >> bit) & 1) * 255;
// Push value 3x since result buffer should be 1 byte
- // per channel
+ // per channel.
res.push(value);
res.push(value);
res.push(value);
@@ -623,7 +623,7 @@ impl FreeTypeRasterizer {
/// This will take the `bitmap_glyph` as input and return the glyph's content downscaled by
/// `fixup_factor`.
fn downsample_bitmap(mut bitmap_glyph: RasterizedGlyph, fixup_factor: f64) -> RasterizedGlyph {
- // Only scale colored buffers which are bigger than required
+ // Only scale colored buffers which are bigger than required.
let bitmap_buffer = match (&bitmap_glyph.buf, fixup_factor.partial_cmp(&1.0)) {
(BitmapBuffer::RGBA(buffer), Some(Ordering::Less)) => buffer,
_ => return bitmap_glyph,
@@ -635,19 +635,20 @@ fn downsample_bitmap(mut bitmap_glyph: RasterizedGlyph, fixup_factor: f64) -> Ra
let target_width = (bitmap_width as f64 * fixup_factor) as usize;
let target_height = (bitmap_height as f64 * fixup_factor) as usize;
- // Number of pixels in the input buffer, per pixel in the output buffer
+ // Number of pixels in the input buffer, per pixel in the output buffer.
let downsampling_step = 1.0 / fixup_factor;
let mut downsampled_buffer = Vec::<u8>::with_capacity(target_width * target_height * 4);
for line_index in 0..target_height {
- // Get the first and last line which will be consolidated in the current output pixel
+ // Get the first and last line which will be consolidated in the current output pixel.
let line_index = line_index as f64;
let source_line_start = (line_index * downsampling_step).round() as usize;
let source_line_end = ((line_index + 1.) * downsampling_step).round() as usize;
for column_index in 0..target_width {
- // Get the first and last column which will be consolidated in the current output pixel
+ // Get the first and last column which will be consolidated in the current output
+ // pixel.
let column_index = column_index as f64;
let source_column_start = (column_index * downsampling_step).round() as usize;
let source_column_end = ((column_index + 1.) * downsampling_step).round() as usize;
@@ -655,7 +656,7 @@ fn downsample_bitmap(mut bitmap_glyph: RasterizedGlyph, fixup_factor: f64) -> Ra
let (mut r, mut g, mut b, mut a) = (0u32, 0u32, 0u32, 0u32);
let mut pixels_picked: u32 = 0;
- // Consolidate all pixels within the source rectangle into a single averaged pixel
+ // Consolidate all pixels within the source rectangle into a single averaged pixel.
for source_line in source_line_start..source_line_end {
let source_pixel_index = source_line * bitmap_width;
@@ -669,7 +670,7 @@ fn downsample_bitmap(mut bitmap_glyph: RasterizedGlyph, fixup_factor: f64) -> Ra
}
}
- // Add a single pixel to the output buffer for the downscaled source rectangle
+ // Add a single pixel to the output buffer for the downscaled source rectangle.
downsampled_buffer.push((r / pixels_picked) as u8);
downsampled_buffer.push((g / pixels_picked) as u8);
downsampled_buffer.push((b / pixels_picked) as u8);
@@ -679,7 +680,7 @@ fn downsample_bitmap(mut bitmap_glyph: RasterizedGlyph, fixup_factor: f64) -> Ra
bitmap_glyph.buf = BitmapBuffer::RGBA(downsampled_buffer);
- // Downscale the metrics
+ // Downscale the metrics.
bitmap_glyph.top = (f64::from(bitmap_glyph.top) * fixup_factor) as i32;
bitmap_glyph.left = (f64::from(bitmap_glyph.left) * fixup_factor) as i32;
bitmap_glyph.width = target_width as i32;
@@ -688,19 +689,19 @@ fn downsample_bitmap(mut bitmap_glyph: RasterizedGlyph, fixup_factor: f64) -> Ra
bitmap_glyph
}
-/// Errors occurring when using the freetype rasterizer
+/// Errors occurring when using the freetype rasterizer.
#[derive(Debug)]
pub enum Error {
- /// Error occurred within the FreeType library
+ /// Error occurred within the FreeType library.
FreeType(freetype::Error),
- /// Couldn't find font matching description
+ /// Couldn't find font matching description.
MissingFont(FontDesc),
- /// Tried to get size metrics from a Face that didn't have a size
+ /// Tried to get size metrics from a Face that didn't have a size.
MissingSizeMetrics,
- /// Requested an operation with a FontKey that isn't known to the rasterizer
+ /// Requested an operation with a FontKey that isn't known to the rasterizer.
FontNotLoaded,
}