Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

otf is not a valid font file #56

Closed
zhenzi0322 opened this issue Jan 18, 2022 · 8 comments
Closed

otf is not a valid font file #56

zhenzi0322 opened this issue Jan 18, 2022 · 8 comments

Comments

@zhenzi0322
Copy link

ttf to otf conversion:
image

@wezm
Copy link
Contributor

wezm commented Jan 19, 2022

Hi we will need more details to be able to help you. Please provide a sample of the code you've written to perform ttf to otf conversion with Allsorts.

@zhenzi0322
Copy link
Author

Hi we will need more details to be able to help you. Please provide a sample of the code you've written to perform ttf to otf conversion with Allsorts.

use std::borrow::Borrow;
use std::fs::File;
use std::io::Write;
use allsorts::binary::read::ReadScope;
use allsorts::font_data::FontData;
use allsorts::tables::{FontTableProvider, MaxpTable};
use allsorts::{subset, tag};

use std::error::Error;
type BoxError = Box<dyn Error>;

fn subset_all<F: FontTableProvider>(font_provider: &F, output_path: &str) -> Result<(), BoxError> {
    let table = font_provider.table_data(tag::MAXP)?.expect("no maxp table");
    let scope = ReadScope::new(table.borrow());
    let maxp = scope.read::<MaxpTable>()?;
    let glyph_ids = (0..maxp.num_glyphs).collect::<Vec<_>>();
    let new_font = subset::subset(font_provider, &glyph_ids, None)?;
    let mut output = File::create(output_path)?;
    output.write_all(&new_font)?;
    Ok(())
}

fn main() {
    let buffer = std::fs::read("static/ttf/1808.ttf")
    .expect("unable to read Klei.otf");
    let scope = ReadScope::new(&buffer);
    let font_file = scope.read::<FontData<'_>>().expect("unable to parse font");
    let provider = font_file
        .table_provider(4)
        .expect("unable to create table provider");
    let out_file = "static/demo1.otf";
    let is_ok = subset_all(&provider, out_file).is_ok();
    if is_ok {
        println!("Font conversion successful.{:?}", out_file);
    }
}

@wezm
Copy link
Contributor

wezm commented Jan 19, 2022

Thanks, that helps a lot. Unfortunately our subsetting functionality is not yet up to doing what you're trying to do. Issue #27 has some more information. From memory the main issue is that we aren't building a proper cmap table.

@zhenzi0322
Copy link
Author

Thanks, that helps a lot. Unfortunately our subsetting functionality is not yet up to doing what you're trying to do. Issue #27 has some more information. From memory the main issue is that we aren't building a proper cmap table.

Ok

@zhenzi0322
Copy link
Author

Thanks, that helps a lot. Unfortunately our subsetting functionality is not yet up to doing what you're trying to do. Issue #27 has some more information. From memory the main issue is that we aren't building a proper cmap table.

Will this feature be implemented in the future?

@wezm
Copy link
Contributor

wezm commented Jan 19, 2022

We would like to implement it but there's currently no firm plans/schedule for when it will be done.

@wezm
Copy link
Contributor

wezm commented Feb 1, 2022

I'm going to close this issue as we are tracking this in #27

@wezm wezm closed this as completed Feb 1, 2022
@wezm
Copy link
Contributor

wezm commented Mar 29, 2022

Just letting you know that the 0.9 release (just published) should fix this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants