View Single Post
Old 04-22-2024, 09:45 PM   #11
sublipri
Member
sublipri can self-interpret dreams as they happen.sublipri can self-interpret dreams as they happen.sublipri can self-interpret dreams as they happen.sublipri can self-interpret dreams as they happen.sublipri can self-interpret dreams as they happen.sublipri can self-interpret dreams as they happen.sublipri can self-interpret dreams as they happen.sublipri can self-interpret dreams as they happen.sublipri can self-interpret dreams as they happen.sublipri can self-interpret dreams as they happen.sublipri can self-interpret dreams as they happen.
 
Posts: 24
Karma: 20342
Join Date: Jul 2023
Device: Kobo Glo, Kobo Sage
Quote:
Originally Posted by gonzule View Post
i was able to properly display the SVG after it was created by the script, so thank you so much!
No problem!

Quote:
Quick question re your binary. Does it support other fbink commands/options? I tried displaying the image using some parameters that work for mewith fbink, but they don't seemt to be recognised here:
The binary doesn't support any of the commands/options from the fbink CLI. It's just a simple utility that's hard-coded to print an SVG with the same properties as your example file. I've modified it to do a flashing clear in (I think) the same way your fbink command does, so hopefully this new version won't require a workaround. Also changed it so that if given a directory as a second argument it will load any font files from there instead of using a hard-coded font, which might make it usable with different SVGs. So you should either use it as:

fbink-svg weather-script-output.svg

or

fbink-svg weather-script-output.svg /path/to/fonts

Here's the code, FWIW:

Spoiler:
Code:
use std::{env, fs};

use fbink_rs::{FbInk, FbInkConfig};
use resvg::tiny_skia;
use resvg::usvg::{self, fontdb};

fn main() {
    let Some(svg_path) = env::args_os().nth(1) else {
        println!("Usage: ./fbink-svg SVG_FILE FONT_DIR");
        return;
    };
    let svg_data = fs::read(svg_path).expect("Failed to read SVG file");
    let config = FbInkConfig {
        is_flashing: true,
        is_cleared: true,
        ..Default::default()
    };
    let fbink = FbInk::new(config).expect("Failed to initialize FBInk");
    let state = fbink.state();
    let width = state.view_width;
    let height = state.view_height;

    let tree = {
        let mut fontdb = fontdb::Database::new();
        let default_font = include_bytes!("../default.ttf");
        if let Some(font_dir) = env::args_os().nth(2) {
            fontdb.load_fonts_dir(font_dir);
        } else {
            fontdb.load_font_data(default_font.to_vec());
        }
        usvg::Tree::from_data(&svg_data, &Default::default(), &fontdb)
            .expect("Failed to create SVG tree")
    };
    let mut pixmap = tiny_skia::Pixmap::new(width, height).expect("Failed to render SVG");
    resvg::render(&tree, Default::default(), &mut pixmap.as_mut());
    fbink
        .print_raw_data(pixmap.data(), width as i32, height as i32, 0, 0)
        .expect("Failed to print SVG to screen");
}
Attached Files
File Type: zip fbink-svg.zip (1.73 MB, 54 views)
sublipri is offline   Reply With Quote