1
1
mirror of https://github.com/wez/wezterm.git synced 2025-01-08 23:17:36 +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 { struct FontInfo {
face: ftwrap::Face, face: ftwrap::Face,
font: hbwrap::Font, font: hbwrap::Font,
pattern: fcwrap::Pattern,
cell_height: i64, cell_height: i64,
cell_width: i64, cell_width: i64,
} }
@ -98,7 +97,7 @@ impl Font {
let pat = self.pattern.render_prepare(&pat)?; let pat = self.pattern.render_prepare(&pat)?;
let file = pat.get_file()?; 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; let size = pat.get_double("size")?.ceil() as i64;
@ -127,12 +126,11 @@ impl Font {
// Compute metrics for the nominal monospace cell // Compute metrics for the nominal monospace cell
let (cell_width, cell_height) = face.cell_metrics(); 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 { self.fonts.push(FontInfo {
face, face,
font, font,
pattern: pat,
cell_height, cell_height,
cell_width, cell_width,
}); });
@ -157,7 +155,7 @@ impl Font {
} }
pub fn shape(&mut self, font_idx: usize, s: &str) -> Result<Vec<GlyphInfo>, Error> { pub fn shape(&mut self, font_idx: usize, s: &str) -> Result<Vec<GlyphInfo>, Error> {
println!( debug!(
"shape text for font_idx {} with len {} {}", "shape text for font_idx {} with len {} {}",
font_idx, font_idx,
s.len(), s.len(),
@ -221,7 +219,7 @@ impl Font {
sizes[last] = diff; sizes[last] = diff;
} }
} }
println!("sizes: {:?}", sizes); debug!("sizes: {:?}", sizes);
// Now make a second pass to determine if we need // Now make a second pass to determine if we need
// to perform fallback to a later font. // to perform fallback to a later font.
@ -235,7 +233,7 @@ impl Font {
} }
} else if let Some(start) = first_fallback_pos { } else if let Some(start) = first_fallback_pos {
// End of a fallback run // End of a fallback run
println!("range: {:?}-{:?} needs fallback", start, pos); debug!("range: {:?}-{:?} needs fallback", start, pos);
let substr = &s[start..pos]; let substr = &s[start..pos];
let mut shape = self.shape(font_idx + 1, substr)?; let mut shape = self.shape(font_idx + 1, substr)?;
@ -245,7 +243,7 @@ impl Font {
} }
if info.codepoint != 0 { if info.codepoint != 0 {
let text = &s[pos..pos + sizes[i]]; 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])); cluster.push(GlyphInfo::new(text, font_idx, info, &positions[i]));
} }
} }
@ -254,7 +252,7 @@ impl Font {
// fallback run. // fallback run.
if let Some(start) = first_fallback_pos { if let Some(start) = first_fallback_pos {
let substr = &s[start..]; let substr = &s[start..];
println!( debug!(
"at end {:?}-{:?} needs fallback {}", "at end {:?}-{:?} needs fallback {}",
start, start,
s.len() - 1, s.len() - 1,
@ -264,7 +262,7 @@ impl Font {
cluster.append(&mut shape); cluster.append(&mut shape);
} }
println!("shaped: {:#?}", cluster); debug!("shaped: {:#?}", cluster);
Ok(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 extern crate fontconfig; // from servo-fontconfig
#[cfg(not(target_os = "macos"))] #[cfg(not(target_os = "macos"))]
extern crate freetype; extern crate freetype;
#[macro_use]
pub mod log;
mod font; mod font;
@ -109,7 +111,7 @@ impl<'a> Glyph<'a> {
}; };
if scale != 1.0f64 { if scale != 1.0f64 {
println!( debug!(
"scaling {:?} w={} {}, h={} {} by {}", "scaling {:?} w={} {}, h={} {} by {}",
info, info,
width, width,
@ -156,7 +158,7 @@ fn glyphs_for_text<'a, T>(
let mut result = Vec::new(); let mut result = Vec::new();
for info in font.shape(0, s)? { for info in font.shape(0, s)? {
if info.glyph_pos == 0 { if info.glyph_pos == 0 {
println!("skip: no codepoint for this one {:?}", info); debug!("skip: no codepoint for this one {:?}", info);
continue; continue;
} }
@ -189,10 +191,10 @@ fn run() -> Result<(), Error> {
Event::KeyDown { keycode: Some(Keycode::Escape), .. } | Event::KeyDown { keycode: Some(Keycode::Escape), .. } |
Event::Quit { .. } => break, Event::Quit { .. } => break,
Event::Window { win_event: WindowEvent::Resized(..), .. } => { Event::Window { win_event: WindowEvent::Resized(..), .. } => {
println!("resize"); debug!("resize");
} }
Event::Window { win_event: WindowEvent::Exposed, .. } => { Event::Window { win_event: WindowEvent::Exposed, .. } => {
println!("exposed"); debug!("exposed");
canvas.set_draw_color(Color::RGBA(0, 0, 0, 255)); canvas.set_draw_color(Color::RGBA(0, 0, 0, 255));
canvas.clear(); canvas.clear();
canvas.set_blend_mode(BlendMode::Blend); canvas.set_blend_mode(BlendMode::Blend);