From 6320b2635b0c0b6b4b5cfdcf821c4cf3c939a811 Mon Sep 17 00:00:00 2001 From: Alex Butler Date: Wed, 8 Nov 2017 00:44:38 +0000 Subject: [PATCH] Improve docs Fix benches Fix readme Up version to 0.6.0 --- Cargo.toml | 2 +- README.md | 2 +- benches/bench.rs | 12 ++++++------ src/builder.rs | 13 ++++++------- 4 files changed, 14 insertions(+), 15 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 2c6dfbe..a3f405c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "gfx_glyph" -version = "0.5.1" +version = "0.6.0" authors = ["Alex Butler "] description = "Fast GPU cached text rendering using gfx-rs & rusttype" repository = "https://github.com/alexheretic/gfx-glyph" diff --git a/README.md b/README.md index 823217f..e5ce515 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ extern crate gfx_glyph; use gfx_glyph::{Section, GlyphBrushBuilder}; let garamond: &[u8] = include_bytes!("GaramondNo8-Reg.ttf"); -let mut glyph_brush = GlyphBrushBuilder::using_font(garamond) +let mut glyph_brush = GlyphBrushBuilder::using_font_bytes(garamond) .build(gfx_factory.clone()); let section = Section { diff --git a/benches/bench.rs b/benches/bench.rs index 3797a71..6b146cc 100644 --- a/benches/bench.rs +++ b/benches/bench.rs @@ -27,7 +27,7 @@ fn render_3_medium_sections_fully(b: &mut ::test::Bencher) { use std::f32; use gfx_glyph::*; - let brush = GlyphBrushBuilder::using_font(TEST_FONT); + let brush = GlyphBrushBuilder::using_font_bytes(TEST_FONT); let text = include_str!("lipsum.txt"); bench( @@ -64,7 +64,7 @@ fn no_cache_render_3_medium_sections_fully(b: &mut ::test::Bencher) { use std::f32; use gfx_glyph::*; - let brush = GlyphBrushBuilder::using_font(TEST_FONT) + let brush = GlyphBrushBuilder::using_font_bytes(TEST_FONT) .cache_glyph_positioning(false) .cache_glyph_drawing(false); let text = include_str!("lipsum.txt"); @@ -101,7 +101,7 @@ fn no_cache_render_3_medium_sections_fully(b: &mut ::test::Bencher) { fn render_1_large_section_partially(b: &mut ::test::Bencher) { use gfx_glyph::*; - let brush = GlyphBrushBuilder::using_font(TEST_FONT); + let brush = GlyphBrushBuilder::using_font_bytes(TEST_FONT); let text = include_str!("lots_of_lipsum.txt"); bench(b, &[Section { text, bounds: (600.0, 600.0), ..Section::default() }], brush); @@ -113,7 +113,7 @@ fn render_1_large_section_partially(b: &mut ::test::Bencher) { fn no_cache_render_1_large_section_partially(b: &mut ::test::Bencher) { use gfx_glyph::*; - let brush = GlyphBrushBuilder::using_font(TEST_FONT) + let brush = GlyphBrushBuilder::using_font_bytes(TEST_FONT) .cache_glyph_positioning(false) .cache_glyph_drawing(false); let text = include_str!("lots_of_lipsum.txt"); @@ -127,7 +127,7 @@ fn render_100_small_sections_fully(b: &mut ::test::Bencher) { use std::f32; use gfx_glyph::*; - let brush = GlyphBrushBuilder::using_font(TEST_FONT); + let brush = GlyphBrushBuilder::using_font_bytes(TEST_FONT); let text = include_str!("small_lipsum.txt"); let mut section_layouts = vec![]; @@ -150,7 +150,7 @@ fn no_cache_render_100_small_sections_fully(b: &mut ::test::Bencher) { use std::f32; use gfx_glyph::*; - let brush = GlyphBrushBuilder::using_font(TEST_FONT) + let brush = GlyphBrushBuilder::using_font_bytes(TEST_FONT) .cache_glyph_positioning(false) .cache_glyph_drawing(false); let text = include_str!("small_lipsum.txt"); diff --git a/src/builder.rs b/src/builder.rs index d18f200..84e529c 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -41,6 +41,8 @@ impl<'a> GlyphBrushBuilder<'a> { Self::using_font(font(font_0_data).unwrap()) } + /// Specifies the default font used to render glyphs. + /// Referenced with `FontId(0)`, which is default. pub fn using_font(font_0_data: Font<'a>) -> Self { GlyphBrushBuilder { font_data: vec![font_0_data], @@ -53,14 +55,16 @@ impl<'a> GlyphBrushBuilder<'a> { } } - /// Adds additional fonts to the one added in [`using_font`](#method.using_font). + /// Adds additional fonts to the one added in [`using_font`](#method.using_font) / + /// [`using_font_bytes`](#method.using_font_bytes). /// Returns a [`FontId`](struct.FontId.html) to reference this font. pub fn add_font_bytes>>(&mut self, font_data: B) -> FontId { self.font_data.push(font(font_data.into()).unwrap()); FontId(self.font_data.len() - 1) } - /// Adds additional fonts to the one added in [`using_font`](#method.using_font). + /// Adds additional fonts to the one added in [`using_font`](#method.using_font) / + /// [`using_font_bytes`](#method.using_font_bytes). /// Returns a [`FontId`](struct.FontId.html) to reference this font. pub fn add_font(&mut self, font_data: Font<'a>) -> FontId { self.font_data.push(font_data); @@ -156,11 +160,6 @@ impl<'a> GlyphBrushBuilder<'a> { let (cache_width, cache_height) = self.initial_cache_size; let font_cache_tex = create_texture(&mut factory, cache_width, cache_height).unwrap(); - // let mut font_map = HashMap::with_capacity(self.font_data.len()); - // for (idx, data) in self.font_data.into_iter().enumerate() { - // font_map.insert(FontId(idx), ) - // } - GlyphBrush { fonts: self.font_data.into_iter().enumerate() .map(|(idx, data)| (FontId(idx), data))