Skip to content

Commit

Permalink
[TTF] Clean up hosted viewer
Browse files Browse the repository at this point in the history
  • Loading branch information
codyd51 committed Feb 18, 2023
1 parent da31692 commit 5383797
Showing 1 changed file with 11 additions and 121 deletions.
132 changes: 11 additions & 121 deletions rust_programs/ttf_viewer/src/main_std.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use agx_definitions::{
Color, Drawable, LikeLayerSlice, Line, NestedLayerSlice, Point, PointF64, Polygon,
Color, Drawable, LikeLayerSlice, Line, LineF64, NestedLayerSlice, Point, PointF64, Polygon,
PolygonStack, Rect, RectInsets, Size, StrokeThickness,
};
use pixels::{Pixels, SurfaceTexture};
use ttf_renderer::{
parse, render_glyph_onto, Codepoint, Font, GlyphRenderDescription, GlyphRenderInstructions,
parse, render_antialiased_glyph_onto, render_glyph_onto, Codepoint, Font,
GlyphRenderDescription, GlyphRenderInstructions,
};
use winit::dpi::LogicalSize;
use winit::event::Event;
Expand All @@ -28,21 +29,7 @@ use std::{cmp, env, error, fs, io};
pub fn main2() -> Result<(), Box<dyn error::Error>> {
let window_size = Size::new(800, 600);
let window = Rc::new(AwmWindow::new("Hosted Font Viewer", window_size));
let fonts = [
"/Users/philliptennen/Downloads/ASCII/ASCII.ttf",
"/Users/philliptennen/Downloads/TestFont.ttf",
"/Users/philliptennen/Downloads/mplus1mn-bold-ascii.ttf",
"/Users/philliptennen/Downloads/SF-Pro.ttf",
"/Users/philliptennen/Downloads/pacifico/Pacifico.ttf",
"/Users/philliptennen/Downloads/nexa/NexaText-Trial-Regular.ttf",
"/Users/philliptennen/Downloads/roboto 2/Roboto-Medium.ttf",
"/Users/philliptennen/Downloads/GeneralSans_Complete/Fonts/WEB/fonts/GeneralSans-Regular.ttf",
"/System/Library/Fonts/Keyboard.ttf",
"/System/Library/Fonts/Symbol.ttf",
"/System/Library/Fonts/Geneva.ttf",
"/Users/philliptennen/Downloads/oswald/Oswald-Regular.ttf",
"/System/Library/Fonts/NewYorkItalic.ttf",
];
let fonts = ["/System/Library/Fonts/NewYorkItalic.ttf"];
let font_path = fonts.last().unwrap();
Rc::new(RefCell::new(FontViewer::new(
Rc::clone(&window),
Expand All @@ -53,27 +40,10 @@ pub fn main2() -> Result<(), Box<dyn error::Error>> {
}

pub fn main() -> Result<(), Box<dyn error::Error>> {
let font_path = "/Users/philliptennen/Downloads/ASCII/ASCII.ttf";
let font_path = "/Users/philliptennen/Downloads/TestFont.ttf";
let font_path = "/Users/philliptennen/Downloads/mplus1mn-bold-ascii.ttf";
let font_path = "/System/Library/Fonts/Symbol.ttf";
let font_path = "/System/Library/Fonts/Keyboard.ttf";
let font_path = "/Users/philliptennen/Downloads/pacifico/Pacifico.ttf";
let font_path = "/Users/philliptennen/Downloads/nexa/NexaText-Trial-Regular.ttf";
let font_path = "/Users/philliptennen/Downloads/orange-juice/orange juice 2.0.ttf";
let font_path = "/Users/philliptennen/Downloads/montserrat/Montserrat-Regular.ttf";
let font_path = "/Users/philliptennen/Downloads/roboto 2/Roboto-Medium.ttf";
let font_path = "/Users/philliptennen/Downloads/coolvetica-2/coolvetica.ttf";
let font_path = "/System/Library/Fonts/NewYorkItalic.ttf";
let font_path = "/Users/philliptennen/Downloads/SF-Pro.ttf";
let font_path = "/Users/philliptennen/Downloads/GeneralSans_Complete/Fonts/WEB/fonts/GeneralSans-Regular.ttf";
let font_path = "/System/Library/Fonts/Geneva.ttf";
let font_path = "/Users/philliptennen/Downloads/andrew_elegant/ANDREW ELEGANT Regular.ttf";
let font_path = "../os_dist/fonts/sf_pro.ttf";
let font_path = "/System/Library/Fonts/SFCompactRounded.ttf";
let font_path = "/Users/philliptennen/Downloads/helvetica-2.ttf";

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

let main_view_sizer = |superview_size: Size| Rect::from_parts(Point::zero(), superview_size);
Expand All @@ -88,49 +58,8 @@ pub fn main() -> Result<(), Box<dyn error::Error>> {
let font = parse(&font_data);

//render_all_glyphs_in_font(&mut main_view_slice, &font, &font_size, Some(3000));
render_string(
&mut main_view_slice,
&font,
&font_size,
//"Sphinx of black quartz, judge my vow. This is a test of font rendering! I am trying out various glyphs and punctuations to see how they're handled. 1234567890!@#$%^&*()_+-=[]{}\\\'\"|,<.>/?§±`~",
//"axle OS, uptime: 64s",
"Safari",
);
render_string(&mut main_view_slice, &font, &font_size, "axle");
//render_glyph(&mut main_view_slice, &font.glyphs[2], 0.4, 0.4);
let p1 = polygon_from_point_tups(&[
(0, 20),
(20, 10),
(40, 20),
(60, 10),
(80, 20),
(80, 30),
(60, 20),
(70, 30),
(60, 40),
(80, 40),
(80, 50),
(40, 40),
(0, 50),
(0, 40),
(10, 40),
(10, 30),
(0, 30),
]);
let p2 = polygon_from_point_tups(&[
(30, 20),
(20, 20),
(15, 25),
(15, 35),
(25, 40),
(40, 40),
(30, 30),
]);
let p3 = polygon_from_point_tups(&[(100, 100), (400, 100), (400, 400), (100, 400)]);

//p1.fill(&mut main_view_slice, Color::red());
//polygon.fill(&mut main_view_slice, Color::red());
//let stack = PolygonStack::new(&[p1, p2]);
//stack.fill(&mut main_view_slice, Color::red());

window.enter_event_loop();
Ok(())
Expand All @@ -153,52 +82,13 @@ fn render_string(onto: &mut Box<dyn LikeLayerSlice>, font: &Font, font_size: &Si
(font.bounding_box.size.width as f64 * scale_x) as isize,
(font.bounding_box.size.height as f64 * scale_y) as isize,
);
for (i, ch) in msg.chars().enumerate() {
for (_, ch) in msg.chars().enumerate() {
let glyph = match font.glyph_for_codepoint(Codepoint::from(ch)) {
None => continue,
Some(glyph) => glyph,
};
/*
let metrics = glyph.metrics();
println!("{ch}: Got metrics {metrics:?}");
let scaled_glyph_metrics = glyph.metrics().scale(scale_x, scale_y);
println!("\tGot scaled metrics {scaled_glyph_metrics:?}");
let glyph_origin = Point::new(
//cursor.x + scaled_glyph_metrics.left_side_bearing,
cursor.x,
cursor.y + scaled_glyph_metrics.top_side_bearing,
);
*/
//let mut dest_slice = onto.get_slice(Rect::from_parts(cursor, scaled_em_size));
//let mut dest_slice = onto.get_slice(Rect::from_parts(cursor, scaled_em_size));
let (draw_box, metrics) = render_glyph_onto(
glyph,
font,
//&mut dest_slice,
onto,
cursor,
Color::black(),
*font_size,
);

/*
println!(
"{ch}: Incrementing cursor from {} to {}",
cursor.x,
cursor.x + (scaled_glyph_metrics.advance_width as isize)
);
*/
/*
cursor = Point::new(
cursor.x + (scaled_glyph_metrics.advance_width as isize),
cursor.y,
);
if cursor.x >= onto.frame().size.width - (font_size.width * 2) {
cursor.y += scaled_em_size.height;
cursor.x = cursor_origin.x;
}
*/
let (_, metrics) =
render_antialiased_glyph_onto(glyph, font, onto, cursor, Color::black(), *font_size);
cursor = Point::new(cursor.x + (metrics.advance_width as isize), cursor.y);
if cursor.x >= onto.frame().size.width - font_size.width {
cursor.y += scaled_em_size.height;
Expand Down

0 comments on commit 5383797

Please sign in to comment.