1
1
mirror of https://github.com/wez/wezterm.git synced 2024-09-11 14:25:57 +03:00

println -> debug build only logging

This commit is contained in:
Wez Furlong 2018-01-17 00:07:31 -08:00
parent 06b47bfc58
commit 93c10590ca
3 changed files with 17 additions and 14 deletions

View File

@ -49,7 +49,6 @@ impl GlyphInfo {
struct FontInfo {
face: ftwrap::Face,
font: hbwrap::Font,
pattern: fcwrap::Pattern,
cell_height: i64,
cell_width: i64,
}
@ -98,7 +97,7 @@ impl Font {
let pat = self.pattern.render_prepare(&pat)?;
let file = pat.get_file()?;
println!("load_next_fallback: file={}", file);
debug!("load_next_fallback: file={}", file);
let size = pat.get_double("size")?.ceil() as i64;
@ -127,12 +126,11 @@ impl Font {
// Compute metrics for the nominal monospace cell
let (cell_width, cell_height) = face.cell_metrics();
println!("metrics: width={} height={}", cell_width, cell_height);
debug!("metrics: width={} height={}", cell_width, cell_height);
self.fonts.push(FontInfo {
face,
font,
pattern: pat,
cell_height,
cell_width,
});
@ -157,7 +155,7 @@ impl Font {
}
pub fn shape(&mut self, font_idx: usize, s: &str) -> Result<Vec<GlyphInfo>, Error> {
println!(
debug!(
"shape text for font_idx {} with len {} {}",
font_idx,
s.len(),
@ -221,7 +219,7 @@ impl Font {
sizes[last] = diff;
}
}
println!("sizes: {:?}", sizes);
debug!("sizes: {:?}", sizes);
// Now make a second pass to determine if we need
// to perform fallback to a later font.
@ -235,7 +233,7 @@ impl Font {
}
} else if let Some(start) = first_fallback_pos {
// End of a fallback run
println!("range: {:?}-{:?} needs fallback", start, pos);
debug!("range: {:?}-{:?} needs fallback", start, pos);
let substr = &s[start..pos];
let mut shape = self.shape(font_idx + 1, substr)?;
@ -245,7 +243,7 @@ impl Font {
}
if info.codepoint != 0 {
let text = &s[pos..pos + sizes[i]];
println!("glyph from `{}`", text);
debug!("glyph from `{}`", text);
cluster.push(GlyphInfo::new(text, font_idx, info, &positions[i]));
}
}
@ -254,7 +252,7 @@ impl Font {
// fallback run.
if let Some(start) = first_fallback_pos {
let substr = &s[start..];
println!(
debug!(
"at end {:?}-{:?} needs fallback {}",
start,
s.len() - 1,
@ -264,7 +262,7 @@ impl Font {
cluster.append(&mut shape);
}
println!("shaped: {:#?}", cluster);
debug!("shaped: {:#?}", cluster);
Ok(cluster)
}

3
src/log.rs Normal file
View File

@ -0,0 +1,3 @@
macro_rules! debug {
($($arg:tt)*) => (if cfg!(debug_assertions) { println!($($arg)*) })
}

View File

@ -7,6 +7,8 @@ extern crate harfbuzz_sys;
extern crate fontconfig; // from servo-fontconfig
#[cfg(not(target_os = "macos"))]
extern crate freetype;
#[macro_use]
pub mod log;
mod font;
@ -109,7 +111,7 @@ impl<'a> Glyph<'a> {
};
if scale != 1.0f64 {
println!(
debug!(
"scaling {:?} w={} {}, h={} {} by {}",
info,
width,
@ -156,7 +158,7 @@ fn glyphs_for_text<'a, T>(
let mut result = Vec::new();
for info in font.shape(0, s)? {
if info.glyph_pos == 0 {
println!("skip: no codepoint for this one {:?}", info);
debug!("skip: no codepoint for this one {:?}", info);
continue;
}
@ -189,10 +191,10 @@ fn run() -> Result<(), Error> {
Event::KeyDown { keycode: Some(Keycode::Escape), .. } |
Event::Quit { .. } => break,
Event::Window { win_event: WindowEvent::Resized(..), .. } => {
println!("resize");
debug!("resize");
}
Event::Window { win_event: WindowEvent::Exposed, .. } => {
println!("exposed");
debug!("exposed");
canvas.set_draw_color(Color::RGBA(0, 0, 0, 255));
canvas.clear();
canvas.set_blend_mode(BlendMode::Blend);