Code Monkey home page Code Monkey logo

Comments (2)

aclysma avatar aclysma commented on August 27, 2024

As it happens just this afternoon I wrote a snippet of code that does exactly this. FYI calling subtable.glyph_index on every character in a font (especially a CJK font with 1000s of characters) is expensive so I filter the range of unicode characters I want to rasterize.

This is almost copy-paste from fontdue's loading code, so +1 for adding an API to access the data fontdue is collecting! (Would also be nice to be able to filter to a list of ranges. By far, fontdue iterating every character in a large CJK font is the slowest part of my code.)

    let character_ranges_to_include = vec![
        (32, 128),
        //(0x4e00, 0x5FCC) // large range of CJK characters for testing
    ];

    let mut characters_to_include = vec![];

    use ttf_parser::{Face, GlyphId, TableName};
    let face = Face::from_slice(font_data, 0).unwrap();

    for subtable in face.character_mapping_subtables() {
        subtable.codepoints(|codepoint| {
            for range in &character_ranges_to_include {
                if codepoint >= range.0 && codepoint <= range.1 {
                    if let Some(glyph_id) = subtable.glyph_index(codepoint) {
                        //let name = face.glyph_name(glyph_id);
                        //println!("glyph codepoint: {} {:?} id: {:?} name: {:?}", codepoint, std::char::from_u32(codepoint), glyph_id, name);

                        characters_to_include.push(std::char::from_u32(codepoint).unwrap());
                    }
                }
            }
        });
    }
read metadata 0.40333298ms
load font to fontdue 232.11732ms <-- could be reduced by filtering ranges of characters
rasterize 0.7775ms
create rects to place 0.060416ms
generated placement for 512x512 texture in 0.148333ms
determined placement 0.431833ms
blit to single texture 0.173125ms

from fontdue.

mooman219 avatar mooman219 commented on August 27, 2024

You can achieve enumerating over all the glyph data like: https://github.com/mooman219/fontdue/blob/master/tests/letter_render_tests.rs#L70

I recently changed this to make it easier.

from fontdue.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.