aboutsummaryrefslogtreecommitdiff
path: root/font
diff options
context:
space:
mode:
authorChristian Duerr <chrisduerr@users.noreply.github.com>2018-07-21 17:17:41 +0000
committerGitHub <noreply@github.com>2018-07-21 17:17:41 +0000
commitf50ca1a54c94fe324d22d985c1acae1ff7c16a80 (patch)
tree7fc2e79f7dccf512fe71f841ef5434e0b1d2b5d7 /font
parentb05ad74fe6d42ce0f913e02ef633ca119fc0b43e (diff)
downloadalacritty-f50ca1a54c94fe324d22d985c1acae1ff7c16a80.tar.gz
alacritty-f50ca1a54c94fe324d22d985c1acae1ff7c16a80.zip
Scrollback cleanup
There were some unneeded codeblocks and TODO/XXX comments in the code that have been removed. All issues marked with TODO/XXX have either been already resolved or tracking issues exist.
Diffstat (limited to 'font')
-rw-r--r--font/Cargo.lock224
-rw-r--r--font/src/darwin/byte_order.rs4
-rw-r--r--font/src/darwin/mod.rs57
-rw-r--r--font/src/ft/fc/char_set.rs8
-rw-r--r--font/src/ft/fc/config.rs2
-rw-r--r--font/src/ft/fc/mod.rs4
-rw-r--r--font/src/ft/fc/object_set.rs9
-rw-r--r--font/src/ft/fc/pattern.rs38
-rw-r--r--font/src/ft/mod.rs42
-rw-r--r--font/src/lib.rs42
10 files changed, 341 insertions, 89 deletions
diff --git a/font/Cargo.lock b/font/Cargo.lock
new file mode 100644
index 00000000..260ac8e0
--- /dev/null
+++ b/font/Cargo.lock
@@ -0,0 +1,224 @@
+[[package]]
+name = "bitflags"
+version = "0.8.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "bitflags"
+version = "1.0.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "cc"
+version = "1.0.17"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "cfg-if"
+version = "0.1.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "cmake"
+version = "0.1.31"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "cc 1.0.17 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "core-foundation"
+version = "0.5.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "core-foundation-sys 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
+ "libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "core-foundation-sys"
+version = "0.5.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "core-graphics"
+version = "0.13.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
+ "core-foundation 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
+ "foreign-types 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
+ "libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "core-text"
+version = "9.2.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "core-foundation 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
+ "core-graphics 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "foreign-types 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
+ "libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "euclid"
+version = "0.17.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "num-traits 0.1.43 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "expat-sys"
+version = "2.1.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "cmake 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)",
+ "pkg-config 0.3.11 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "font"
+version = "0.1.0"
+dependencies = [
+ "core-foundation 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
+ "core-foundation-sys 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
+ "core-graphics 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "core-text 9.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "euclid 0.17.3 (registry+https://github.com/rust-lang/crates.io-index)",
+ "foreign-types 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
+ "freetype-rs 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)",
+ "log 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
+ "servo-fontconfig 0.4.0 (git+https://github.com/jwilm/rust-fontconfig?branch=updated-2017-10-8)",
+]
+
+[[package]]
+name = "foreign-types"
+version = "0.3.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "foreign-types-shared 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "foreign-types-shared"
+version = "0.1.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "freetype-rs"
+version = "0.13.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "bitflags 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)",
+ "freetype-sys 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "freetype-sys"
+version = "0.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)",
+ "libz-sys 1.0.18 (registry+https://github.com/rust-lang/crates.io-index)",
+ "pkg-config 0.3.11 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "libc"
+version = "0.2.42"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "libz-sys"
+version = "1.0.18"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "cc 1.0.17 (registry+https://github.com/rust-lang/crates.io-index)",
+ "libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)",
+ "pkg-config 0.3.11 (registry+https://github.com/rust-lang/crates.io-index)",
+ "vcpkg 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "log"
+version = "0.4.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "cfg-if 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "num-traits"
+version = "0.1.43"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "num-traits 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "num-traits"
+version = "0.2.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "pkg-config"
+version = "0.3.11"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "servo-fontconfig"
+version = "0.4.0"
+source = "git+https://github.com/jwilm/rust-fontconfig?branch=updated-2017-10-8#be2b94de833ec69cf767186262a5fb8360fa5b45"
+dependencies = [
+ "libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)",
+ "servo-fontconfig-sys 4.0.3 (git+https://github.com/jwilm/libfontconfig?branch=updated-2017-10-8)",
+]
+
+[[package]]
+name = "servo-fontconfig-sys"
+version = "4.0.3"
+source = "git+https://github.com/jwilm/libfontconfig?branch=updated-2017-10-8#5c1845e1bffa11cf4d3e6fb27f456bf5c814ce1b"
+dependencies = [
+ "expat-sys 2.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
+ "freetype-sys 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "pkg-config 0.3.11 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "vcpkg"
+version = "0.2.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[metadata]
+"checksum bitflags 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1370e9fc2a6ae53aea8b7a5110edbd08836ed87c88736dfabccade1c2b44bff4"
+"checksum bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "d0c54bb8f454c567f21197eefcdbf5679d0bd99f2ddbe52e84c77061952e6789"
+"checksum cc 1.0.17 (registry+https://github.com/rust-lang/crates.io-index)" = "49ec142f5768efb5b7622aebc3fdbdbb8950a4b9ba996393cb76ef7466e8747d"
+"checksum cfg-if 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "405216fd8fe65f718daa7102ea808a946b6ce40c742998fbfd3463645552de18"
+"checksum cmake 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)" = "95470235c31c726d72bf2e1f421adc1e65b9d561bf5529612cbe1a72da1467b3"
+"checksum core-foundation 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "286e0b41c3a20da26536c6000a280585d519fd07b3956b43aed8a79e9edce980"
+"checksum core-foundation-sys 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "716c271e8613ace48344f723b60b900a93150271e5be206212d052bbc0883efa"
+"checksum core-graphics 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fb0ed45fdc32f9ab426238fba9407dfead7bacd7900c9b4dd3f396f46eafdae3"
+"checksum core-text 9.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2bd581c37283d0c23311d179aefbb891f2324ee0405da58a26e8594ab76e5748"
+"checksum euclid 0.17.3 (registry+https://github.com/rust-lang/crates.io-index)" = "c95fd0d455f114291a3109286bd387bd423770058474a2d3f38b712cd661df60"
+"checksum expat-sys 2.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "c470ccb972f2088549b023db8029ed9da9426f5affbf9b62efff7009ab8ed5b1"
+"checksum foreign-types 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1"
+"checksum foreign-types-shared 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b"
+"checksum freetype-rs 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a1418e2a055fec8efe18c1a90a54b2cf5e649e583830dd4c71226c4e3bc920c6"
+"checksum freetype-sys 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "eccfb6d96cac99921f0c2142a91765f6c219868a2c45bdfe7d65a08775f18127"
+"checksum libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)" = "b685088df2b950fccadf07a7187c8ef846a959c142338a48f9dc0b94517eb5f1"
+"checksum libz-sys 1.0.18 (registry+https://github.com/rust-lang/crates.io-index)" = "87f737ad6cc6fd6eefe3d9dc5412f1573865bded441300904d2f42269e140f16"
+"checksum log 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6fddaa003a65722a7fb9e26b0ce95921fe4ba590542ced664d8ce2fa26f9f3ac"
+"checksum num-traits 0.1.43 (registry+https://github.com/rust-lang/crates.io-index)" = "92e5113e9fd4cc14ded8e499429f396a20f98c772a47cc8622a736e1ec843c31"
+"checksum num-traits 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "775393e285254d2f5004596d69bb8bc1149754570dcc08cf30cabeba67955e28"
+"checksum pkg-config 0.3.11 (registry+https://github.com/rust-lang/crates.io-index)" = "110d5ee3593dbb73f56294327fe5668bcc997897097cbc76b51e7aed3f52452f"
+"checksum servo-fontconfig 0.4.0 (git+https://github.com/jwilm/rust-fontconfig?branch=updated-2017-10-8)" = "<none>"
+"checksum servo-fontconfig-sys 4.0.3 (git+https://github.com/jwilm/libfontconfig?branch=updated-2017-10-8)" = "<none>"
+"checksum vcpkg 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "7ed0f6789c8a85ca41bbc1c9d175422116a9869bd1cf31bb08e1493ecce60380"
diff --git a/font/src/darwin/byte_order.rs b/font/src/darwin/byte_order.rs
index 29efb5b1..2ea46fcb 100644
--- a/font/src/darwin/byte_order.rs
+++ b/font/src/darwin/byte_order.rs
@@ -24,7 +24,7 @@ pub const kCGBitmapByteOrder32Host: u32 = kCGBitmapByteOrder32Little;
pub const kCGBitmapByteOrder32Host: u32 = kCGBitmapByteOrder32Big;
#[cfg(target_endian = "little")]
-pub fn extract_rgb(bytes: Vec<u8>) -> Vec<u8> {
+pub fn extract_rgb(bytes: &[u8]) -> Vec<u8> {
let pixels = bytes.len() / 4;
let mut rgb = Vec::with_capacity(pixels * 3);
@@ -32,7 +32,7 @@ pub fn extract_rgb(bytes: Vec<u8>) -> Vec<u8> {
let offset = i * 4;
rgb.push(bytes[offset + 2]);
rgb.push(bytes[offset + 1]);
- rgb.push(bytes[offset + 0]);
+ rgb.push(bytes[offset]);
}
rgb
diff --git a/font/src/darwin/mod.rs b/font/src/darwin/mod.rs
index 14381113..4351af61 100644
--- a/font/src/darwin/mod.rs
+++ b/font/src/darwin/mod.rs
@@ -132,8 +132,8 @@ impl ::Rasterize for Rasterizer {
Ok(Rasterizer {
fonts: HashMap::new(),
keys: HashMap::new(),
- device_pixel_ratio: device_pixel_ratio,
- use_thin_strokes: use_thin_strokes,
+ device_pixel_ratio,
+ use_thin_strokes,
})
}
@@ -162,7 +162,7 @@ impl ::Rasterize for Rasterizer {
}
/// Get rasterized glyph for given glyph key
- fn get_glyph(&mut self, glyph: &GlyphKey) -> Result<RasterizedGlyph, Error> {
+ fn get_glyph(&mut self, glyph: GlyphKey) -> Result<RasterizedGlyph, Error> {
// get loaded font
let font = self.fonts
@@ -196,7 +196,7 @@ impl Rasterizer {
for descriptor in descriptors {
if descriptor.style_name == style {
// Found the font we want
- let scaled_size = size.as_f32_pts() as f64 * self.device_pixel_ratio as f64;
+ let scaled_size = f64::from(size.as_f32_pts()) * f64::from(self.device_pixel_ratio);
let font = descriptor.to_font(scaled_size, true);
return Ok(font);
}
@@ -220,7 +220,7 @@ impl Rasterizer {
Slant::Normal => false,
_ => true,
};
- let scaled_size = size.as_f32_pts() as f64 * self.device_pixel_ratio as f64;
+ let scaled_size = f64::from(size.as_f32_pts()) * f64::from(self.device_pixel_ratio);
let descriptors = descriptors_for_family(&desc.name[..]);
for descriptor in descriptors {
@@ -246,11 +246,11 @@ impl Rasterizer {
// Helper to try and get a glyph for a given font. Used for font fallback.
fn maybe_get_glyph(
&self,
- glyph: &GlyphKey,
+ glyph: GlyphKey,
font: &Font,
) -> Option<Result<RasterizedGlyph, Error>> {
let scaled_size = self.device_pixel_ratio * glyph.size.as_f32_pts();
- font.get_glyph(glyph.c, scaled_size as _, self.use_thin_strokes)
+ font.get_glyph(glyph.c, f64::from(scaled_size), self.use_thin_strokes)
.map(|r| Some(Ok(r)))
.unwrap_or_else(|e| match e {
Error::MissingGlyph(_) => None,
@@ -301,7 +301,7 @@ pub fn get_family_names() -> Vec<String> {
/// Return fallback descriptors for font/language list
fn cascade_list_for_languages(
ct_font: &CTFont,
- languages: &Vec<String>
+ languages: &[String]
) -> Vec<Descriptor> {
// convert language type &Vec<String> -> CFArray
@@ -356,7 +356,7 @@ impl Descriptor {
let menlo = ct_new_from_descriptor(&descriptor.ct_descriptor, size);
// TODO fixme, hardcoded en for english
- let mut fallbacks = cascade_list_for_languages(&menlo, &vec!["en".to_owned()])
+ let mut fallbacks = cascade_list_for_languages(&menlo, &["en".to_owned()])
.into_iter()
.filter(|desc| desc.font_path != "")
.map(|desc| desc.to_font(size, false))
@@ -368,12 +368,11 @@ impl Descriptor {
// many chars. We add the symbols back in.
// Investigate if we can actually use the .-prefixed
// fallbacks somehow.
- descriptors_for_family("Apple Symbols")
- .into_iter()
- .next() // should only have one element; use it
- .map(|descriptor| {
- fallbacks.push(descriptor.to_font(size, false))
- });
+ if let Some(descriptor) =
+ descriptors_for_family("Apple Symbols").into_iter().next()
+ {
+ fallbacks.push(descriptor.to_font(size, false))
+ };
// Include Menlo in the fallback list as well
fallbacks.insert(0, Font {
@@ -390,9 +389,9 @@ impl Descriptor {
};
Font {
- ct_font: ct_font,
- cg_font: cg_font,
- fallbacks: fallbacks,
+ ct_font,
+ cg_font,
+ fallbacks,
}
}
}
@@ -424,8 +423,8 @@ impl Font {
let line_height = (ascent + descent + leading + 0.5).floor();
Metrics {
- average_advance: average_advance,
- line_height: line_height,
+ average_advance,
+ line_height,
descent: -(self.ct_font.descent() as f32),
}
}
@@ -482,13 +481,13 @@ impl Font {
}
let glyph_index = self.glyph_index(character)
- .ok_or(Error::MissingGlyph(character))?;
+ .ok_or_else(|| Error::MissingGlyph(character))?;
let bounds = self.bounding_rect_for_glyph(Default::default(), glyph_index);
let rasterized_left = bounds.origin.x.floor() as i32;
let rasterized_width =
- (bounds.origin.x - (rasterized_left as f64) + bounds.size.width).ceil() as u32;
+ (bounds.origin.x - f64::from(rasterized_left) + bounds.size.width).ceil() as u32;
let rasterized_descent = (-bounds.origin.y).ceil() as i32;
let rasterized_ascent = (bounds.size.height + bounds.origin.y).ceil() as i32;
let rasterized_height = (rasterized_descent + rasterized_ascent) as u32;
@@ -519,8 +518,8 @@ impl Font {
let context_rect = CGRect::new(
&CGPoint::new(0.0, 0.0),
&CGSize::new(
- rasterized_width as f64,
- rasterized_height as f64
+ f64::from(rasterized_width),
+ f64::from(rasterized_height)
)
);
@@ -542,8 +541,8 @@ impl Font {
// Set fill color to white for drawing the glyph
cg_context.set_rgb_fill_color(1.0, 1.0, 1.0, 1.0);
let rasterization_origin = CGPoint {
- x: -rasterized_left as f64,
- y: rasterized_descent as f64,
+ x: f64::from(-rasterized_left),
+ y: f64::from(rasterized_descent),
};
self.ct_font.draw_glyphs(&[glyph_index as CGGlyph],
@@ -552,7 +551,7 @@ impl Font {
let rasterized_pixels = cg_context.data().to_vec();
- let buf = extract_rgb(rasterized_pixels);
+ let buf = extract_rgb(&rasterized_pixels);
Ok(RasterizedGlyph {
c: character,
@@ -560,7 +559,7 @@ impl Font {
top: (bounds.size.height + bounds.origin.y).ceil() as i32,
width: rasterized_width as i32,
height: rasterized_height as i32,
- buf: buf,
+ buf,
})
}
@@ -585,7 +584,7 @@ impl Font {
);
if res {
- Some(glyphs[0] as u32)
+ Some(u32::from(glyphs[0]))
} else {
None
}
diff --git a/font/src/ft/fc/char_set.rs b/font/src/ft/fc/char_set.rs
index e6fe027a..151d14a3 100644
--- a/font/src/ft/fc/char_set.rs
+++ b/font/src/ft/fc/char_set.rs
@@ -24,7 +24,13 @@ foreign_type! {
}
impl CharSet {
- pub fn new() -> CharSet {
+ pub fn new() -> Self {
+ Self::default()
+ }
+}
+
+impl Default for CharSet {
+ fn default() -> Self {
CharSet(unsafe { FcCharSetCreate() })
}
}
diff --git a/font/src/ft/fc/config.rs b/font/src/ft/fc/config.rs
index 92993fe8..9744b37a 100644
--- a/font/src/ft/fc/config.rs
+++ b/font/src/ft/fc/config.rs
@@ -38,7 +38,7 @@ impl Config {
impl ConfigRef {
/// Returns one of the two sets of fonts from the configuration as
/// specified by `set`.
- pub fn get_fonts<'a>(&'a self, set: SetName) -> &'a FontSetRef {
+ pub fn get_fonts(&self, set: SetName) -> &FontSetRef {
unsafe {
let ptr = FcConfigGetFonts(self.as_ptr(), set as u32);
FontSetRef::from_ptr(ptr)
diff --git a/font/src/ft/fc/mod.rs b/font/src/ft/fc/mod.rs
index ac0c9442..865f63c9 100644
--- a/font/src/ft/fc/mod.rs
+++ b/font/src/ft/fc/mod.rs
@@ -180,9 +180,9 @@ pub enum Width {
}
impl Width {
- fn to_isize(&self) -> isize {
+ fn to_isize(self) -> isize {
use self::Width::*;
- match *self {
+ match self {
Ultracondensed => 50,
Extracondensed => 63,
Condensed => 75,
diff --git a/font/src/ft/fc/object_set.rs b/font/src/ft/fc/object_set.rs
index 42e03f64..47d11674 100644
--- a/font/src/ft/fc/object_set.rs
+++ b/font/src/ft/fc/object_set.rs
@@ -24,8 +24,13 @@ foreign_type! {
}
impl ObjectSet {
- #[allow(dead_code)]
- pub fn new() -> ObjectSet {
+ pub fn new() -> Self {
+ Self::default()
+ }
+}
+
+impl Default for ObjectSet {
+ fn default() -> Self {
ObjectSet(unsafe {
FcObjectSetCreate()
})
diff --git a/font/src/ft/fc/pattern.rs b/font/src/ft/fc/pattern.rs
index 592d3859..bb0c4c38 100644
--- a/font/src/ft/fc/pattern.rs
+++ b/font/src/ft/fc/pattern.rs
@@ -39,8 +39,8 @@ pub struct StringPropertyIter<'a> {
impl<'a> StringPropertyIter<'a> {
fn new<'b>(pattern: &'b PatternRef, object: &'b [u8]) -> StringPropertyIter<'b> {
StringPropertyIter {
- pattern: pattern,
- object: object,
+ pattern,
+ object,
index: 0
}
}
@@ -82,8 +82,8 @@ pub struct BooleanPropertyIter<'a> {
impl<'a> BooleanPropertyIter<'a> {
fn new<'b>(pattern: &'b PatternRef, object: &'b [u8]) -> BooleanPropertyIter<'b> {
BooleanPropertyIter {
- pattern: pattern,
- object: object,
+ pattern,
+ object,
index: 0
}
}
@@ -101,7 +101,7 @@ impl<'a> BooleanPropertyIter<'a> {
};
if result == FcResultMatch {
- Some(!(value == 0))
+ Some(value != 0)
} else {
None
}
@@ -118,8 +118,8 @@ pub struct IntPropertyIter<'a> {
impl<'a> IntPropertyIter<'a> {
fn new<'b>(pattern: &'b PatternRef, object: &'b [u8]) -> IntPropertyIter<'b> {
IntPropertyIter {
- pattern: pattern,
- object: object,
+ pattern,
+ object,
index: 0
}
}
@@ -171,7 +171,7 @@ pub struct HintStylePropertyIter<'a> {
}
impl<'a> HintStylePropertyIter<'a> {
- fn new<'b>(pattern: &'b PatternRef) -> HintStylePropertyIter<'b> {
+ fn new(pattern: &PatternRef) -> HintStylePropertyIter {
HintStylePropertyIter {
inner: IntPropertyIter::new(pattern, b"hintstyle\0")
}
@@ -201,7 +201,7 @@ pub struct LcdFilterPropertyIter<'a> {
}
impl<'a> LcdFilterPropertyIter<'a> {
- fn new<'b>(pattern: &'b PatternRef) -> LcdFilterPropertyIter<'b> {
+ fn new(pattern: &PatternRef) -> LcdFilterPropertyIter {
LcdFilterPropertyIter {
inner: IntPropertyIter::new(pattern, b"lcdfilter\0")
}
@@ -236,14 +236,14 @@ pub struct DoublePropertyIter<'a> {
impl<'a> DoublePropertyIter<'a> {
fn new<'b>(pattern: &'b PatternRef, object: &'b [u8]) -> DoublePropertyIter<'b> {
DoublePropertyIter {
- pattern: pattern,
- object: object,
+ pattern,
+ object,
index: 0
}
}
fn get_value(&self, index: usize) -> Option<f64> {
- let mut value = 0 as c_double;
+ let mut value = f64::from(0);
let result = unsafe {
FcPatternGetDouble(
@@ -379,7 +379,13 @@ macro_rules! string_accessor {
}
impl Pattern {
- pub fn new() -> Pattern {
+ pub fn new() -> Self {
+ Self::default()
+ }
+}
+
+impl Default for Pattern {
+ fn default() -> Self {
Pattern(unsafe { FcPatternCreate() })
}
}
@@ -483,11 +489,11 @@ impl PatternRef {
BooleanPropertyIter::new(self, object)
}
- pub fn hintstyle<'a>(&'a self) -> HintStylePropertyIter<'a> {
+ pub fn hintstyle(&self) -> HintStylePropertyIter {
HintStylePropertyIter::new(self)
}
- pub fn lcdfilter<'a>(&'a self) -> LcdFilterPropertyIter<'a> {
+ pub fn lcdfilter(&self) -> LcdFilterPropertyIter {
LcdFilterPropertyIter::new(self)
}
@@ -565,7 +571,7 @@ impl PatternRef {
RgbaPropertyIter::new(self, b"rgba\0")
}
- pub fn set_rgba(&self, rgba: Rgba) -> bool {
+ pub fn set_rgba(&self, rgba: &Rgba) -> bool {
unsafe {
self.add_integer(b"rgba\0", rgba.to_isize())
}
diff --git a/font/src/ft/mod.rs b/font/src/ft/mod.rs
index 68d2faf3..516f3b9c 100644
--- a/font/src/ft/mod.rs
+++ b/font/src/ft/mod.rs
@@ -80,8 +80,8 @@ impl ::Rasterize for FreeTypeRasterizer {
Ok(FreeTypeRasterizer {
faces: HashMap::new(),
keys: HashMap::new(),
- library: library,
- device_pixel_ratio: device_pixel_ratio,
+ library,
+ device_pixel_ratio,
})
}
@@ -94,7 +94,7 @@ impl ::Rasterize for FreeTypeRasterizer {
Ok(Metrics {
average_advance: full.cell_width,
line_height: height,
- descent: descent,
+ descent,
})
}
@@ -102,7 +102,7 @@ impl ::Rasterize for FreeTypeRasterizer {
self.get_face(desc, size)
}
- fn get_glyph(&mut self, glyph_key: &GlyphKey) -> Result<RasterizedGlyph, Error> {
+ fn get_glyph(&mut self, glyph_key: GlyphKey) -> Result<RasterizedGlyph, Error> {
self.get_rendered_glyph(glyph_key)
}
@@ -172,7 +172,7 @@ impl FreeTypeRasterizer {
} as f64;
Ok(FullMetrics {
- size_metrics: size_metrics,
+ size_metrics,
cell_width: width
})
}
@@ -188,7 +188,7 @@ impl FreeTypeRasterizer {
pattern.add_family(&desc.name);
pattern.set_weight(weight.into_fontconfig_type());
pattern.set_slant(slant.into_fontconfig_type());
- pattern.add_pixelsize(size.as_f32_pts() as _);
+ pattern.add_pixelsize(f64::from(size.as_f32_pts()));
let font = fc::font_match(fc::Config::get_current(), &mut pattern)
.ok_or_else(|| Error::MissingFont(desc.to_owned()))?;
@@ -210,7 +210,7 @@ impl FreeTypeRasterizer {
let mut pattern = fc::Pattern::new();
pattern.add_family(&desc.name);
pattern.add_style(style);
- pattern.add_pixelsize(size.as_f32_pts() as _);
+ pattern.add_pixelsize(f64::from(size.as_f32_pts()));
let font = fc::font_match(fc::Config::get_current(), &mut pattern)
.ok_or_else(|| Error::MissingFont(desc.to_owned()))?;
@@ -232,24 +232,24 @@ impl FreeTypeRasterizer {
let ft_face = self.library.new_face(&path, index)?;
// Get available pixel sizes if font isn't scalable.
- let non_scalable = if !pattern.scalable().next().unwrap_or(true) {
+ let non_scalable = if pattern.scalable().next().unwrap_or(true) {
+ None
+ } else {
let mut pixelsize = pattern.pixelsize();
debug!("pixelsizes: {:?}", pixelsize);
Some(FixedSize {
pixelsize: pixelsize.next().expect("has 1+ pixelsize"),
})
- } else {
- None
};
let face = Face {
- ft_face: ft_face,
+ ft_face,
key: FontKey::next(),
load_flags: Self::ft_load_flags(pattern),
render_mode: Self::ft_render_mode(pattern),
lcd_filter: Self::ft_lcd_filter(pattern),
- non_scalable: non_scalable,
+ non_scalable,
};
debug!("Loaded Face {:?}", face);
@@ -264,19 +264,15 @@ impl FreeTypeRasterizer {
}
}
- fn face_for_glyph(&mut self, glyph_key: &GlyphKey, have_recursed: bool) -> Result<FontKey, Error> {
+ fn face_for_glyph(&mut self, glyph_key: GlyphKey, have_recursed: bool) -> Result<FontKey, Error> {
let c = glyph_key.c;
let use_initial_face = if self.faces.contains_key(&glyph_key.font_key) {
// Get face and unwrap since we just checked for presence.
- let face = self.faces.get(&glyph_key.font_key).unwrap();
+ let face = &self.faces[&glyph_key.font_key];
let index = face.ft_face.get_char_index(c as usize);
- if index != 0 || have_recursed {
- true
- } else {
- false
- }
+ index != 0 || have_recursed
} else {
false
};
@@ -289,7 +285,7 @@ impl FreeTypeRasterizer {
}
}
- fn get_rendered_glyph(&mut self, glyph_key: &GlyphKey)
+ fn get_rendered_glyph(&mut self, glyph_key: GlyphKey)
-> Result<RasterizedGlyph, Error> {
// Render a custom symbol for the underline and beam cursor
match glyph_key.c {
@@ -334,7 +330,7 @@ impl FreeTypeRasterizer {
// Render a normal character if it's not a cursor
let font_key = self.face_for_glyph(glyph_key, false)?;
- let face = self.faces.get(&font_key).unwrap();
+ let face = &self.faces[&font_key];
let index = face.ft_face.get_char_index(glyph_key.c as usize);
let size = face.non_scalable.as_ref()
@@ -360,7 +356,7 @@ impl FreeTypeRasterizer {
left: glyph.bitmap_left(),
width: pixel_width,
height: glyph.bitmap().rows(),
- buf: buf,
+ buf,
})
}
@@ -490,7 +486,7 @@ impl FreeTypeRasterizer {
}
Ok((bitmap.width(), packed))
},
- mode @ _ => panic!("unhandled pixel mode: {:?}", mode)
+ mode => panic!("unhandled pixel mode: {:?}", mode)
}
}
diff --git a/font/src/lib.rs b/font/src/lib.rs
index 330ed362..fe9e9e85 100644
--- a/font/src/lib.rs
+++ b/font/src/lib.rs
@@ -17,6 +17,9 @@
//! CoreText is used on Mac OS.
//! FreeType is used on everything that's not Mac OS.
//! Eventually, ClearType support will be available for windows
+
+#![cfg_attr(feature = "cargo-clippy", deny(clippy, if_not_else, enum_glob_use, wrong_pub_self_convention))]
+
#[cfg(not(target_os = "macos"))]
extern crate fontconfig;
#[cfg(not(target_os = "macos"))]
@@ -116,7 +119,7 @@ impl FontDesc {
{
FontDesc {
name: name.into(),
- style: style
+ style,
}
}
}
@@ -146,7 +149,7 @@ impl FontKey {
}
}
-#[derive(Debug, Copy, Clone, PartialEq, Eq)]
+#[derive(Debug, Copy, Clone, Eq)]
pub struct GlyphKey {
pub c: char,
pub font_key: FontKey,
@@ -165,6 +168,19 @@ impl Hash for GlyphKey {
}
}
+impl PartialEq for GlyphKey {
+ fn eq(&self, other: &Self) -> bool {
+ unsafe {
+ // This transmute is fine:
+ //
+ // - If GlyphKey ever becomes a different size, this will fail to compile
+ // - Result is being used for equality checking and has no fields (it's a u64)
+ let other = ::std::mem::transmute::<GlyphKey, u64>(*other);
+ ::std::mem::transmute::<GlyphKey, u64>(*self).eq(&other)
+ }
+ }
+}
+
/// Font size stored as integer
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq, PartialOrd, Ord)]
pub struct Size(i16);
@@ -183,7 +199,7 @@ impl Size {
/// Get the f32 size in points
pub fn as_f32_pts(self) -> f32 {
- self.0 as f32 / Size::factor()
+ f32::from(self.0) / Size::factor()
}
}
@@ -224,14 +240,14 @@ pub fn get_underline_cursor_glyph(descent: i32, width: i32) -> Result<Rasterized
let buf = vec![255u8; (width * height * 3) as usize];
// Create a custom glyph with the rectangle data attached to it
- return Ok(RasterizedGlyph {
+ Ok(RasterizedGlyph {
c: UNDERLINE_CURSOR_CHAR,
top: descent + height,
left: 0,
height,
width,
- buf: buf,
- });
+ buf,
+ })
}
// Returns a custom beam cursor character
@@ -245,14 +261,14 @@ pub fn get_beam_cursor_glyph(
let buf = vec![255u8; (beam_width * height * 3) as usize];
// Create a custom glyph with the rectangle data attached to it
- return Ok(RasterizedGlyph {
+ Ok(RasterizedGlyph {
c: BEAM_CURSOR_CHAR,
top: ascent,
left: 0,
height,
width: beam_width,
- buf: buf,
- });
+ buf,
+ })
}
// Returns a custom box cursor character
@@ -276,14 +292,14 @@ pub fn get_box_cursor_glyph(
}
// Create a custom glyph with the rectangle data attached to it
- return Ok(RasterizedGlyph {
+ Ok(RasterizedGlyph {
c: BOX_CURSOR_CHAR,
top: ascent,
left: 0,
height,
width,
- buf: buf,
- });
+ buf,
+ })
}
struct BufDebugger<'a>(&'a [u8]);
@@ -331,5 +347,5 @@ pub trait Rasterize {
fn load_font(&mut self, &FontDesc, Size) -> Result<FontKey, Self::Err>;
/// Rasterize the glyph described by `GlyphKey`.
- fn get_glyph(&mut self, &GlyphKey) -> Result<RasterizedGlyph, Self::Err>;
+ fn get_glyph(&mut self, GlyphKey) -> Result<RasterizedGlyph, Self::Err>;
}