Thursday, 21 December 2006

Phags-pa Fonts 1 : BabelStone Phags-pa Book

Part of the 1345 Phags-pa Sanskrit inscription at Juyongguan



To celebrate the recent encoding of the Phags-pa script in Unicode 5.0 I am releasing some free OpenType Unicode Phags-pa fonts that fully implement Phags-pa shaping behaviour (for which see Section 10.3 of The Unicode Standard version 5.0). These fonts work correctly under Windows XP and later, although I have had to set the script tag in the OT tables to <latn> rather than <phag> in order to trick Uniscribe into applying the font's OpenType features [insert long and bitter anti-Uniscribe rant here]. I'm afraid that I have no idea whether these fonts will work on platforms other than Windows.

The first font that I am releasing is BabelStone Phags-pa Book, which is a general purpose Phags-pa font which emulates the simple lines of Phags-pa letters used in Yuan dynasty printed Phags-pa texts such as Menggu Ziyun 蒙古字韵 and Baijiaxing Mengguwen 百家姓蒙古文. The font may be downloaded from here.

To demonstrate that my Phags-pa fonts do work in principle on Windows XP and later, here is a rotated screenshot of Notepad running under Windows XP (Uniscribe version 1.0420.2600.2180), showing the text of the Phags-pa inscription pictured at the top of this page rendered with "BabelStone Phags-pa Book" at 20 points (this sample of text shows features such as glyph ligation, positional vowel forms, contextual mirroring and overriding of contextual mirroring using standardized variants) :



However, not all applications will let you display correctly shaping Phags-pa text. For example I have been totally unable to get Microsoft Word 2003 or 2007 to apply any of my Phags-ps fonts to selected Phags-pa text, and whatever I try all I get are little square boxes [not true -- see Addendum 2 below]. I guess that this is expected behaviour for Word, which many of us who work with complex scripts consider to be the epitome of evil. OpenOffice.org copes slightly better, in that it lets you apply a Phags-pa font, but it unfortunately does not apply any of the font's OpenType features, so that Phags-pa text is rendered as a sequence of non-shaping glyphs. The same problem is seen with Internet Explorer 6 and 7, which will use my Phags-pa fonts if applied in a stylesheet, but will not apply any of the OpenType features. The screenshot below shows the above Notepad document as displayed in IE7 on Windows XP. Note that there is no shaping behaviour (no glyph ligation, no positional vowel forms, no contextual mirroring) [also not entirely true -- see Addendum 1 below] :



In contrast, Mozilla Firefox 2.0 does support the OpenType features in my Phags-pa fonts (not that difficult ... all it has to do is use the Uniscribe API), and so renders the Phags-pa document correctly [also not entirely true -- see Addendum 3 below] :



Finally, here is the actual Phags-pa text that I have been testing with, so you can see how your system copes with it (you must first install BabelStone Phags-pa Book). The text is laid out horizontally, with line 1 at the bottom, and so you should read it either by twisting your head anticlockwise 90 degrees or by turning your monitor clockwise 90 degrees (IE does support vertical layout, but other browsers, such as Firefox, do not, so for maximum browser compatibility I have used horizontal layout here).


Sample of Phags-pa Sanskrit Text

[Part of the Uṣṇīṣavijaya-dhāraṇī 佛頂尊勝陀羅尼經]


ꡏꡟ ꡋꡞ ꡏꡟ ꡋꡞ ᠂ ꡏ ꡜꡖ ꡏꡟ ꡋꡞ ᠂ ꡓꡞ ꡏꡟ ᠁

ꡈꡞ ꡋꡞ ꡓꡘ ꡈ ꡗ ᠃ ꡏ ꡏ ꡝ ꡗꡟꡘ ꡓꡞ ꡚꡟꡊ ᠁

ꡜꡖ ꡏꡟ ꡊꡱꡠ ᠃ ꡎ ꡒꡱ ꡀꡖ ꡗ ᠃ ꡳꡛ ꡜ ᠁

ꡏꡞ ᠃ ꡌꡱ ꡈꡞꡚ ꡪꡞ︀ ꡈꡠ ᠃ ꡛꡘ ꡓ ꡈ ꡉꡖ ᠁

ꡉꡖ ꡂ ꡈ ᠃ ꡝ ꡓ ꡙꡡ ꡀꡞ ꡋꡞ ᠂ ꡚ ꡩꡖ︀ ꡌ ᠁

〔ꡛ〕ꡧ ꡎꡜꡖ ꡓ ᠃ ꡓꡞ ꡚꡟꡊ ꡊꡜꡠ ꡟꡚ ꡬꡞ ᠁

〔ꡝꡖ〕 ꡜ ꡘ ꡝꡖ ꡜ ꡘ ᠂ ꡏ ꡏ ꡝ ꡗꡟꡘ ꡛꡋ ꡊ ᠁

〔᠁〕 ꡈ ꡛꡟ ꡂ ꡈ ᠃ ꡓ ꡘ ꡓ ꡐ ꡋ ᠁

〔ꡎ〕ꡜꡖ ꡛ ꡛꡎꡖ ꡘ ꡬ ꡂ ꡈꡞ ꡂ ꡂ ᠁

〔᠁ꡗ〕 ꡉꡖ ꡳꡡ ꡳꡎꡜꡖꡱꡟ ꡳꡎꡜꡖꡱꡟ ꡳꡎꡜ ᠁

〔ꡳꡡ〕 ꡳꡎꡜꡖꡱꡟ ꡛꡧꡖ ꡜꡖ ᠅ ꡳꡡ ꡋ ꡏꡡ ꡎꡜ ꡂ ꡓ ᠁



And if all this has whetted your appetite for writing Phags-pa yourself, I have created a Phags-pa keyboard layout that can be used on Windows 2000 and later, which can be downloaded from here.

In the next installment I will discuss Phags-pa shaping behaviour in some more detail, and there will be some more Phags-pa fonts available for download in a few days time, so keep watching this space.



Addendum 1 [2006-12-22]

Sharp-eyed readers will have noticed, as I only did this morning, that my statement that Internet Explorer does not apply the OpenType features of my Phags-pa font is not entirely true. If you look carefully at the screenshot of Internet Explorer you will notice that there are in fact two short sections of correctly shaping Phags-pa text -- ꡩꡖ︀ on line 7 and ꡌꡱ ꡈꡞꡚ ꡪꡞ︀ on line 8. At first glance these islands of shaping in a sea of unshaping would seem to be inexplicable, but when you look at the underlying character codes (<A869 A856 FE00> and <A84C A871 0020 A848 A85E A85A 0020 A86A A85E FE00> respectively) the reason becomes clear(ish) -- these sections of text both contain variation selectors (VS-1, which reverses the default mirroring behaviour of the preceding character), so evidently Internet Explorer is applying the font's OpenType features when and only when variation selectors are involved. My guess is that as InternetExplorer does not recognise the Phags-pa script, it treats Phags-pa (and other Unicode 5.0) characters as a non-complex script and outputs the characters directly without the help of Uniscribe, but when it encounters a variation selector, then it decides it does need to treat the run which includes the variation selector as a complex script, and outputs the run using Uniscribe.



Addendum 2 [2006-12-23]

I've just been informed that Word 2003 does let you use BabelStone Phags-pa Book for Phags-pa text, and when I just retested with Word 2007 I also found that I had no problems using my fonts, although Word still does not apply the OpenType shaping unless variation selectors are involved (i.e. it has the same behaviour as Internet Explorer). I can't explain why I had problems with Word 2003 and 2007 on two different machines a few days ago, but no problems today -- I can only suppose it may have been some difference between the beta font I was testing with and the released font ... I think I had better just blame user error. Anyway, please do keep me informed of any success or failure you might have in using the font with different applications.



Addendum 3 [2008-11-13]

I originally stated that Firefox supports OpenType features in my Phags-pa font. I have just realized that this is not entirely true. The sample Phags-pa text only renders correctly in Firefox because each line includes at least one punctuation mark from the Mongolian block, and so the text is being passed through the Mongolian text rendering system. Unfortunately, if you remove all the Mongolian punctuation marks the Phags-pa text no longer shows any joining or shaping behaviour :-(

As expected, Google Chrome does not render Phags-pa text correctly, and nor does IE8, so at present there is no browser that I am aware of that does unconditionally apply joining and shaping behaviour to Phags-pa text.


5 comments:

Tom Gewecke said...

Often I can get Windows complex opentype stuff to work in OS X in OpenOffice. This one will not, but I wonder if it could relate to the latn script tag in the tables. Have you tested the font with other tags like tibetan in OO at all? tom at bluesky dot org.

Andrew West said...

I don't think that the script tag is the issue here, although if you want I'll send you a version of the font with script tag correctly set to "phag" (or perhaps I ought to try "mong").

Personally I think the problem is that "clever" applications such as Word and OOo only correctly process characters that they know about, and as they don't yet know about Unicode 5.0 they treat Phags-pa characters as unassigned codepoints.

Of course it shouldn't be too hard for someone involved with OOo to add in support for Phags-pa.

Tom Gewecke said...

You are probably right about the tag, but if you have time to fix me up another version, that would be great. I was thinking the tag for Tibetan might help as I know OO does that OK.

Andrew West said...

Santa'll be getting his sled ready soon, so I'll send it to you tomorrow.

Andrew West said...

Tom has confirmed that changing the script tag to <phag>, <mong> or <tibt> makes no difference.