Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP-GD: Dealing with Unicode characters

I am developing a web service that renders characters using the PHP GD extension, using a user-selected TTF font.

This works fine in ASCII-land, but there are a few problems:

  1. The string to be rendered comes in as UTF-8. I would like to limit the list of user-selectable fonts to be only those which can render the string properly, as some fonts only have glyphs for ASCII characters, ISO 8601, etc.

  2. In the case where some decorative characters are included, it would be fine to render the majority of characters in the selected font and render the decorative characters in Arial (or whatever font contains the extended glyphs).

It does not seem like PHP-GD has support for querying the font metadata sufficiently to figure out if a character can be rendered in a given font. What is a good way to get font metrics into PHP? Is there a command-line utility that can dump in XML or other parsable format?

like image 748
sehugg Avatar asked May 21 '10 02:05

sehugg


2 Answers

PHP-Cairo built against Pango and fontconfig should have enough brains to do font substitution when appropriate.

like image 131
Ignacio Vazquez-Abrams Avatar answered Oct 05 '22 10:10

Ignacio Vazquez-Abrams


You can try to use pdf_info_font() from pdflib extension. Good example is there: http://www.pdflib.com/pdflib-cookbook/fonts/font-metrics-info/php-font-metrics-info/

like image 25
Dmytro Zavalkin Avatar answered Oct 05 '22 11:10

Dmytro Zavalkin