Comments (8)
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.
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.
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.
@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.
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.
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.
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.
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)
- font lose glyph name HOT 1
- Writing slow (30+ seconds) for certain fonts (CJK, Noto Chinese) HOT 2
- TypeError: Cannot read properties of undefined (reading 'featureIndexes')
- fvar.instances returns empty name entry if nameID is 17 (preferredSubfamily) HOT 13
- 'liga' should not support only latin words
- missing emoji substitutions HOT 9
- Character rendering issues occur when stroking text. HOT 11
- Detect and remove inner contours from path? HOT 5
- Naming Table Parsing seems buggy HOT 1
- Why isn't the fromSVG API included in the release version? HOT 1
- The variable font code uses Proxy, a non-polyfillable ES6 type. HOT 7
- Local build rules were deleted this should not have happened. HOT 13
- variable fonts: VariationManager set axes values for rendering HOT 12
- Proposal: API change freeze HOT 7
- SVG related y-Axis conversion differs in version 2.0.0
- Handling vertical advance; ascender / descender doesn't look correct for some fonts HOT 6
- `charToGlyph` throws error for missing glyph for fonts with default encoding HOT 1
- Gasp write support broken, opentype.js cannot read the fonts it creates
- `lowMemory` option causes glyphs to be skipped when writing font (with `toArrayBuffer`)
- `Uncaught (in promise) ReferenceError: exports is not defined` when using in Next.js HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from opentype.js.