0

I am trying to parse some webfonts like woff,ttf etc.

Thats why i started working with this lib

https://github.com/PhenX/php-font-lib

But there is no usage example for example, how to parse some relevant information from a font.ttf file.

This is an example for the lib

http://pxd.me/php-font-lib/www/font_explorer.html

Anybody has some experience with this library and could give me a starting point?

Greetings and thanks

Creative crypter
  • 1,348
  • 6
  • 30
  • 67
  • What do you mean by "parse"? – Mike Jun 30 '15 at 21:08
  • hi, i mean, how to extract relevant information from the font, like the "glyfs", you know what i mean? – Creative crypter Jun 30 '15 at 21:09
  • It is probably not likely that you will find anyone here that has used this particular library before. You may be better off contacting the developer. Perhaps submit an issue on github simply saying that the documentation lacks examples. – Mike Jun 30 '15 at 21:12
  • 1
    @Creativecrypter Actually, no, we don't know what you mean. You'll need to be much more specific. –  Jun 30 '15 at 22:16
  • you can try https://github.com/pomax/php-font-parser, for ttf and otf, but not woff, but what you should really do is explain what you're *actually* trying to do, instead of merely hinting at it. Are you simply trying to extract outlines for letters? Full text shaping? Actual OpenType metadata extraction? What are you doing that makes you feel you need a PHP font parser? – Mike 'Pomax' Kamermans Jul 01 '15 at 04:38
  • hi, example: i have the font "myfont.ttf" and i need to extract all possible glyf´s of it. is this specific ? greetings! – Creative crypter Jul 01 '15 at 10:38
  • don't put that in the comments, update your question with that information so that all the details are in your post. Also, because it sounds very much like we're still in XY Problem territory: *why* do you need all the glyphs? Are you going to draw text? If so, just having the glyph outlines is not enough. – Mike 'Pomax' Kamermans Jul 01 '15 at 18:50

1 Answers1

0

If, based on your additional question details, what you actually need is to extract all glyph outlines, then you're far better off using TTX to extract the glyf table as an XML file, and then simply read that in using PHP. Much easier to code, and seriously far less work.

However, and this is the biggie: having the glyph outlines is not the same as now being able to style text. Words like "difference" are not "d" + "i" + "f" + ...etc, because fonts also come with repositioning information to make sure certain letter combinations look better than if you just "drop letters one after another", and letters can get replaced with completely different outlines for even better looks (many good fonts will have a dedicated glyph for the "ff" ligature, for instance, which is completely different from just two "f" glyphs next to each other, both in terms of outline points and metrics).

But it seems like you're asking an XY Problem question, so it might be worth asking youself "why" five times.

  1. You want to parse a font in PHP. Why?
  2. Because you want all the glyphs in the font. Okay: why?
  3. Because... what are you going to use those for, and why?
  4. presumably you want to draw text. Where?
  5. On images? Your question is actually "How do I draw text on images in PHP?" (answer: imagemagick + im extension). On a page? Your question is actually "how do I get text with a specific font on a webpage" (answer: CSS @font-face rule), etc.

Stackoverflow can best help you when you don't ask about how to achieve what you've already imagined as solution to your problem, but when you state what you need to achieve, and then explain what you've already thought of, or tried.

Community
  • 1
  • 1
Mike 'Pomax' Kamermans
  • 49,297
  • 16
  • 112
  • 153