Skip to content

Commit

Permalink
[TTF] Update hosted runner for benchmarking render performance
Browse files Browse the repository at this point in the history
  • Loading branch information
codyd51 committed Feb 7, 2024
1 parent cee2b7d commit 7dc2cd9
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 25 deletions.
4 changes: 2 additions & 2 deletions rust_programs/ttf_viewer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ axle_rt_derive = {path = "../axle_rt_derive" }
agx_definitions = {path = "../agx_definitions"}
ttf_renderer = {path = "../ttf_renderer"}
# These dependencies are only enabled in use_std mode
pixels = { version = "0.11.0", optional = true }
winit = { version = "0.28.0", optional = true }
pixels = { version = "0.13.0", optional = true }
winit = { version = "0.29.10", optional = true, features = ["rwh_05"] }
97 changes: 74 additions & 23 deletions rust_programs/ttf_viewer/src/main_std.rs
Original file line number Diff line number Diff line change
@@ -1,30 +1,18 @@
use agx_definitions::{
Color, Drawable, LikeLayerSlice, Line, LineF64, NestedLayerSlice, Point, PointF64, Polygon,
PolygonStack, Rect, RectInsets, Size, StrokeThickness,
Color, FillMode, LikeLayerSlice, NestedLayerSlice, Point, PointF64, Polygon, PolygonStack,
Rect, Size, StrokeThickness,
};
use pixels::{Pixels, SurfaceTexture};
use ttf_renderer::{
parse, render_antialiased_glyph_onto, render_glyph_onto, Codepoint, Font,
GlyphRenderDescription, GlyphRenderInstructions,
};
use winit::dpi::LogicalSize;
use winit::event::Event;
use winit::event_loop::{ControlFlow, EventLoop};
use winit::window::WindowBuilder;
use ttf_renderer::{parse, render_glyph_onto, Codepoint, Font};

use crate::font_viewer::FontViewer;
use crate::utils::render_all_glyphs_in_font;
use libgui::bordered::Bordered;
use libgui::font::load_font;
use libgui::label::Label;
use libgui::text_input_view::TextInputView;
use libgui::ui_elements::UIElement;
use libgui::KeyCode;
use libgui::{view::View, AwmWindow};
use libgui_derive::{Drawable, NestedLayerSlice, UIElement};
use libgui::AwmWindow;
use std::cell::RefCell;
use std::cmp::{max, min};
use std::rc::{Rc, Weak};
use std::time::Instant;
use std::{cmp, env, error, fs, io};
use std::rc::Rc;
use std::{error, fs};

pub fn main2() -> Result<(), Box<dyn error::Error>> {
let window_size = Size::new(800, 600);
Expand All @@ -42,23 +30,86 @@ pub fn main2() -> Result<(), Box<dyn error::Error>> {
pub fn main() -> Result<(), Box<dyn error::Error>> {
let font_path = "/Users/philliptennen/Documents/fonts/helvetica-2.ttf";

let font_size = Size::new(16, 16);
let font_size = Size::new(64, 64);
let window_size = Size::new(1240, 1000);
let window = Rc::new(AwmWindow::new("Hosted Font Viewer", window_size));

let slice = window.get_slice();
slice.fill(Color::white());
let label = Label::new_with_font(
//load_font(font_path)
"tijpx",
Color::black(),
load_font(font_path),
Size::new(64, 64),
move |l, superview_size| Rect::from_parts(Point::new(16, 100), Size::new(200, 100)),
);

let main_view_sizer = |superview_size: Size| Rect::from_parts(Point::zero(), superview_size);
let main_view = TextInputView::new(Some(font_path), font_size, move |_v, superview_size| {
main_view_sizer(superview_size)
});

Rc::clone(&window).add_component(Rc::clone(&main_view) as Rc<dyn UIElement>);

let mut main_view_slice = main_view.get_slice();
Rc::clone(&window).add_component(Rc::clone(&label) as Rc<dyn UIElement>);
label.get_slice().fill(Color::red());

for ch in "tijpx".chars() {
main_view
.view
.draw_char_and_update_cursor(ch, Color::black());
}

slice.fill_polygon_stack(
&PolygonStack::new(&[Polygon::new(&[
PointF64::new(10.0, 10.0),
PointF64::new(100.0, 10.0),
PointF64::new(100.0, 100.0),
PointF64::new(10.0, 100.0),
])]),
Color::new(200, 80, 130),
FillMode::Outline,
);

/*
slice.fill_rect(
Rect::new(10, 10, 90, 90),
Color::red(),
StrokeThickness::Filled,
);
*/

/*
slice.fill_polygon_stack(
&PolygonStack::new(&[Polygon::new(&[
PointF64::new(0.0, 0.0),
PointF64::new(100.0, 0.0),
PointF64::new(100.0, 100.0),
PointF64::new(0.0, 100.0),
])]),
Color::green(),
FillMode::Outline,
);
*/

//let mut main_view_slice = main_view.get_slice();

let font_data = fs::read(font_path).unwrap();
let font = parse(&font_data);
//let font_render_context = FontRenderContext::new(&font, font_size);

//render_all_glyphs_in_font(&mut main_view_slice, &font, &font_size, Some(3000));
render_string(&mut main_view_slice, &font, &font_size, "axle");
//render_string(&mut main_view_slice, &font, &font_size, "axle");
/*
render_string(
&mut main_view_slice,
&font,
&font_size,
&"abcdefghijklmnopqrstuvwzyz123456789".repeat(10),
);
*/
//render_glyph(&mut main_view_slice, &font.glyphs[2], 0.4, 0.4);

window.enter_event_loop();
Expand Down

0 comments on commit 7dc2cd9

Please sign in to comment.