Charts! For vowels!

Contrary to (my) assumptions, I actually wrote a program to draw the vowel diagrams like on the IPA chart, instead of the normal “I will! Honest! But later”. Apart from being used to show which symbol means what, the IPA Handbook also uses them to show more accurately what the vowels actually are. This is the intended use of this program, of course, because otherwise you might as well have an image.

Installation

Unzip this file to a directory somewhere. That’s it. (But see below if you want to integrate it into WordPress.)

Requirements
  • PHP ≥4.x
  • GD2 graphics library and FreeType (which are probably installed by default)
  • Um, a web server?

Adding vowel points

The program works in a similar way to mimeTeX: put the URL with a few parameters in an img tag or wherever and it’ll produce a nice-looking image. The simplest image is just to navigate to the URL, in my case http://adradh.org.uk/vc/vowelchart.php:

…which is not very useful. To place a vowel, put symbol=x,y in the query string. The top left corner is 0,0 and the bottom right 20,30:

So to put ‹ə› in the middle, where it ought to be, go to vowelchart.php?ə=10,15. Or if you prefer, it understands the X-SAMPA vowels: vowelchart.php?@=10,15. As you probably guessed, you can separate multiple vowels with &, it being a query string after all. So to add ‹i u a ɒ› just go to vowelchart.php?@=10,15&i=0,0&u=20,0&a=0,30&Q=20,30:

If you really want you can put whole words at one point (as I did above with the co-ordinates):

This is simply ?hello=4,10&world=4,20. At the moment you can’t put two symbols in the same place and have them either side of the dot: another reason why this isn’t so good for the official IPA diagram. It just puts things to the left of the dot if their x coordinate is more than 18, and to the right otherwise; there are no checks for collisions.

Changing the defaults

Maybe you don’t like the blue dots? Perhaps red would be better? Then you can change it with _dot=#cc0000:

Currently only the format #rrggbb is supported for colours. You can change the colours of other things in the same way with the properties _text, _grid, and _bg.

You’ll probably want to use those more sparingly than that. You can change the size of the diagram, dots, or text with _width, _height, _dotsize, and _fontsize:

By default there is a 15 pixel margin around the grid to prevent symbols hanging off the edges from being clipped off. If you want you can change the size of this with _margin.

The last property is _font. As you’d expect, it changes the font face used for drawing the text. However, it requires that the font file be in the same directory as itself. If you have a font you prefer over Gentium, copy it into the folder and then set _font to the file name (not the font name!). So if I want to use Lucida Sans Unicode, if it is in a file called lsu.ttf, then I upload that to the server and then have _font=lsu.ttf:

This works for any TrueType font that has the IPA Extensions block defined. If it doesn’t, then obviously some of the symbols won’t show up.

If you want to change the default value of some property, if for example you always want the dots to be red or you can’t stand Gentium, all of the properties are right at the top of the PHP file. You can just change them there, bearing in mind (if you don’t know PHP already) that the font filename has to be in quotation marks, the colours of the form #rrggbb are instead 0xrrggbb, and that all lines end in a ;. In short, you can change the values, but not the way they’re represented.

WordPress plugin

This wouldn’t be complete, of course, without a function for fauxML. This is how I’ve been doing these graphs the whole time; img tags would have been far too picky.

You need to install the fauxML plugin, then add this at the bottom of the wp-content/plugins/fauxml/fauxml.php file:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
function _vowels($arr) {
	$str = preg_replace('/\\s*=\\s*/', '=', $arr[1]);
	$str = preg_replace('/\\s*,\\s*/', ',', $str);
	$params_ = preg_split('/\\s+/', $str);
	$params = array();
	foreach ($params_ as $p) {
		list($a, $b) = split('=', $p);
		$params[] = urlencode($a) . '=' . urlencode($b);
	}
	$str = implode('&', $params);
	// change this to wherever you put vowelchart.php
	return "<img src='/vc/vowelchart.php?$str' alt=''"
		. " class='vowels' />";
}
 
wp_add_faux_ml('/\\[vowels\s+(.*?)\\s*\\]/s', '_vowels');

With this you can say, for example, [vowels i=1,2 @=9,14 (etc) ] and a chart will be drawn there and then. This isn’t cached like the mimeTeX without CGI plugin, since it’s assuming it’s running off your server and you’re not leeching.

Tags: ,

Leave a Reply

You must be logged in to post a comment.