photopea / Typr.js

Typr.js - process fonts in Javascript
MIT License
914 stars 73 forks source link

Support CID-keyed CFF #5

Closed be5invis closed 5 years ago

photopea commented 7 years ago

Hi be5invis. Can you show me a sample of such font?

be5invis commented 7 years ago

Hmm, Source Han Sans? It is CID-keyed and large enough for performance testing.

photopea commented 7 years ago

Do such fonts actually occur in the nature? I have tested this library with thousands of fonts and have never seen it. It seems like there are just several such fonts and they were made for testing CFF libraries.

be5invis commented 7 years ago

@photopea ALL OpenType fonts in Japanese and Chinese are CID. Source Han Sans and Source Han Serif are two free samples of them.

my2iu commented 6 years ago

I was able hack in some support for CID fonts in a version of Typr.js that I was working on because I got tripped up by the NotoSans CJK fonts on Android. I read over the spec and looked over opentype.js to see how they do it. It's not too much work. It involves the reading of an extra data structure, and then instead of using CFF.Private, you have to choose which Private to use based on the glyph.

https://github.com/my2iu/Typr.js/commit/d7a6062553706918c226b4c3d7d7c4d43d7fc2c7

Unfortunately, I was in the middle of translating the code to Java, so it's diverged a bit and can't be applied directly upstream.

photopea commented 6 years ago

I am not familiar with the font terminology, but I think i might have implemented it in the past year. Can you please check it?

my2iu commented 6 years ago

I'm pretty sure I branched only about 6 months ago, and the public version of Typr.js hasn't had a change for 7 months, so I don't think it's been implemented yet. The CID stuff is described in Compact Font Format Specification (just search for CID).

You need to detect the special ROS indicator (opcodes 12 and then 30 at the start of the Top DICT) for CID fonts. Then, you can parse some additional CID tables. Then, later on, when parsing the CFF data, you need to pull data from these additional tables instead of the data from the topDict.

The only such font I've encountered so far is the Noto Sans CJK fonts for displaying Chinese/Japanese/Korean characters , but I imagine other CJK fonts will have the same problems.

If you want, I can try to rewrite my changes in JS so they can be reapplied to your repository when I have the time.

my2iu commented 6 years ago

Btw, if you ever want to package up photopea as a Windows 10 app or MacOS app, let me know, and I can probably give you a bunch of code for grabbing system font information in Electron/Objective-C.

photopea commented 6 years ago

Omg, there are 115 MB of fonts. Could you open any of these fonts in www.Photopea.com and try to type with it? Are you sure it is not possible?

BTW. I am not a fan of publishing OS-specific software. I hope that once, open web standards will let us access fonts of the users device. But thanks for your offer!

my2iu commented 6 years ago

TypeError: Cannot read property "Subrs" of undefined on line 13503.

(It is looking up the subroutines of the topDict, but it should be looking up the subroutines in the CID tables of the particular glyph)

p.s. I think the web browser makers have come to an agreement that the list of user fonts will not be made available in the browser. There was a security problem where advertisers would use Flash to enumerate the list of fonts on the system, fingerprint you using this font list, and then track people across websites based on which fonts they have installed.

my2iu commented 6 years ago

Apparently, you can grab an individual CJK font from here: https://github.com/googlei18n/noto-cjk/blob/master/NotoSansSC-Regular.otf

photopea commented 5 years ago

Hi guys, I think I fixed it. Sorry that it took me two years :(