Skip to content

Commit

Permalink
Make FontTemplateData's Debug formatter more concise
Browse files Browse the repository at this point in the history
Otherwise the log gets spammed with all the individual bytes of the
underlying font file.
  • Loading branch information
jonleighton committed Feb 22, 2018
1 parent 691f3be commit 799bf87
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 3 deletions.
14 changes: 13 additions & 1 deletion components/gfx/platform/freetype/font_template.rs
Expand Up @@ -3,6 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

use servo_atoms::Atom;
use std::fmt;
use std::fs::File;
use std::io::{Read, Error};
use webrender_api::NativeFontHandle;
Expand All @@ -11,12 +12,23 @@ use webrender_api::NativeFontHandle;
/// The identifier is an absolute path, and the bytes
/// field is the loaded data that can be passed to
/// freetype and azure directly.
#[derive(Debug, Deserialize, Serialize)]
#[derive(Deserialize, Serialize)]
pub struct FontTemplateData {
// If you add members here, review the Debug impl below

pub bytes: Vec<u8>,
pub identifier: Atom,
}

impl fmt::Debug for FontTemplateData {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
fmt.debug_struct("FontTemplateData")
.field("bytes", &format!("[{} bytes]", self.bytes.len()))
.field("identifier", &self.identifier)
.finish()
}
}

impl FontTemplateData {
pub fn new(identifier: Atom, font_data: Option<Vec<u8>>) -> Result<FontTemplateData, Error> {
let bytes = match font_data {
Expand Down
19 changes: 18 additions & 1 deletion components/gfx/platform/macos/font_template.rs
Expand Up @@ -24,8 +24,10 @@ use webrender_api::NativeFontHandle;
/// The identifier is a PostScript font name. The
/// CTFont object is cached here for use by the
/// paint functions that create CGFont references.
#[derive(Debug, Deserialize, Serialize)]
#[derive(Deserialize, Serialize)]
pub struct FontTemplateData {
// If you add members here, review the Debug impl below

/// The `CTFont` object, if present. This is cached here so that we don't have to keep creating
/// `CTFont` instances over and over. It can always be recreated from the `identifier` and/or
/// `font_data` fields.
Expand All @@ -39,6 +41,21 @@ pub struct FontTemplateData {
pub font_data: Option<Arc<Vec<u8>>>
}

impl fmt::Debug for FontTemplateData {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
fmt.debug_struct("FontTemplateData")
.field("ctfont", &self.ctfont)
.field("identifier", &self.identifier)
.field(
"font_data",
&self.font_data
.as_ref()
.map(|bytes| format!("[{} bytes]", bytes.len()))
)
.finish()
}
}

unsafe impl Send for FontTemplateData {}
unsafe impl Sync for FontTemplateData {}

Expand Down
19 changes: 18 additions & 1 deletion components/gfx/platform/windows/font_template.rs
Expand Up @@ -4,15 +4,32 @@

use platform::windows::font_list::{descriptor_from_atom, font_from_atom};
use servo_atoms::Atom;
use std::fmt;
use std::io;
use webrender_api::NativeFontHandle;

#[derive(Debug, Deserialize, Serialize)]
#[derive(Deserialize, Serialize)]
pub struct FontTemplateData {
// If you add members here, review the Debug impl below

pub bytes: Option<Vec<u8>>,
pub identifier: Atom,
}

impl fmt::Debug for FontTemplateData {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
fmt.debug_struct("FontTemplateData")
.field(
"bytes",
&self.bytes
.as_ref()
.map(|bytes| format!("[{} bytes]", bytes.len()))
)
.field("identifier", &self.identifier)
.finish()
}
}

impl FontTemplateData {
pub fn new(identifier: Atom,
font_data: Option<Vec<u8>>) -> Result<FontTemplateData, io::Error> {
Expand Down

0 comments on commit 799bf87

Please sign in to comment.