Skip to content

Commit

Permalink
Improve docs
Browse files Browse the repository at this point in the history
Fix benches
Fix readme
Up version to 0.6.0
  • Loading branch information
alexheretic committed Nov 8, 2017
1 parent 5c86390 commit 6320b26
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "gfx_glyph"
version = "0.5.1"
version = "0.6.0"
authors = ["Alex Butler <[email protected]>"]
description = "Fast GPU cached text rendering using gfx-rs & rusttype"
repository = "https://github.com/alexheretic/gfx-glyph"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
12 changes: 6 additions & 6 deletions benches/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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);
Expand All @@ -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");
Expand All @@ -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![];
Expand All @@ -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");
Expand Down
13 changes: 6 additions & 7 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand All @@ -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<B: Into<SharedBytes<'a>>>(&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);
Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit 6320b26

Please sign in to comment.