Giter Club home page Giter Club logo

Comments (8)

davelab6 avatar davelab6 commented on August 30, 2024 1

I think a good end goal for this issue would be for http://nodebox.github.io/opentype.js/glyph-inspector.html to display the glyph name and unicode value, in the right-side table shown when you click on glyphs.

Currently, if I visit the page and click the '3' glyph (by visually identifying it):

index      22
namexMin   72
xMax       1127
yMin       -21

Expected:

index     22
glyphname three
unicode   U+0033 3 3
namexMin  72
xMax      1127
yMin      -21

from opentype.js.

davelab6 avatar davelab6 commented on August 30, 2024 1

Would it work to make a font.glyphToChar($index) that is similar to charToGlyph() and returns 0 if the glyph index input isn't associated with a character, such as if its a composite or accessed only via OpenType GSUB substitution, but returns a unicode number if found?

from opentype.js.

davelab6 avatar davelab6 commented on August 30, 2024

I believe (may be wrong) that, as you can see on
http://nodebox.github.io/opentype.js/font-inspector.html , the CMAP table
is available today only in 'raw' form, and you'll need to process the data
further to get the 'real' glyph ID to unicode character map (as specified
in https://www.microsoft.com/typography/OTSPEC/cmap.htm)

from opentype.js.

fpirsch avatar fpirsch commented on August 30, 2024

@toreym
font.charToGlyph(myChar) returns a Glyph object with index 0 (missing glyph) if the character is not in the font.

@davelab6
Nice idea. But the glyph → codepoint correspondence is more difficult than the codepoint → glyph correspondence, because of composites, substitutions etc.

from opentype.js.

fpirsch avatar fpirsch commented on August 30, 2024

Basically it's a reverse lookup in the CMAP table, so it takes either memory (to build and store the reverse table) or a lot of computations.
I would suggest lazy-building a reverse table on the first call to font.glyphToChar(). Subsequent calls would just use the table.
However, to make things more complicated, some glyphs are used in multple characters (which is the point of composites), such as cyrillic characters Є and Э which both use the same 'Є' glyph in the Arial font, see #50

from opentype.js.

toreym avatar toreym commented on August 30, 2024

While I still don't completely understand the cmap table, after learning more about how it's built and the complexities you mentioned with mirroring glyphs I see why this isn't a simple solution.

I personally like the lazy load approach as I wouldn't want to take the hit on initial load if the user would never need this additional index.

Is it even possible to reverse look up a glyph in the cmap table? (A question from my lack of knowledge of how this table is structured).

In regard to #50 I'd assume a transformed glyph would have it's own value in the glyphs list with a transform value right? If so, then the glyphToChar() method would be a good solution as one could simply loop through the glyphs and call this method to get available unicode values.

from opentype.js.

fdb avatar fdb commented on August 30, 2024

It's potentially a many-to-one mapping, so I'm not sure if we can return one unicode character for each glyph.

However @toreym for your use case (getting a list of all Unicode characters in the font) it doesn't really matter, since you want a list anyway. I'll look into it further.

from opentype.js.

fdb avatar fdb commented on August 30, 2024

Glyphs now have a unicode and unicodes property. So you can see all unicode values by concatenating the values from the unicodes property:

var unicodes = [];
for (var i = 0; i < font.gyphs.length; i += 1) {
    unicodes = unicodes.concat(font.glyphs[i].unicodes);
}

from opentype.js.

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.