Monday, November 7 2005

Flashcards revisited

A while back, I made quick and dirty hiragana flashcards, using the Mac OS X print dialog to print single-word pages 16-up. As my Japanese class moves along, though, there’s a need for something more sophisticated. Each lesson in our book includes a number of kanji words that will be on the test, and while my previous method will work, the hard-coded font sizes and word placement get messy to maintain.

If I’m going to write an honest-to-gosh flashcard generator, though, I might as well go whole-hog and make it capable of printing study words vertically, the way they’d be printed in a book or newspaper. Learning to recognize horizontal text might get me through the test, but it’s not enough for real Japanese literacy.

Here’s the Perl script (requires PDF::API2::Lite), a horizontal example, and vertical example. You’ll need to supply the name of your own TrueType/OpenType font that includes the kanji, unless you happen to have a copy of Kozuka Mincho Pro Regular around the house.

Note that the above PDF files have been significantly reduced in size (by an order of magnitude!) by using Mac OS X’s Preview app and saving them with the Quartz filter “Reduce File Size”. The words in the sample are from the review sheet for this week’s lesson…

Update: One problem with my vertical-printing solution quickly became obvious, and I don’t have a good solution for it. The short version is “Unicode is meaning, not appearance”, so variant glyphs can’t be easily selected, even if they’re present in your font. Specifically, the katakana prolonged-sound mark 「ー」 should be a vertical line when you’re writing vertically. Also, all of the small kana 「ぁぃぅぇぉっ」 should be offset up and to the right, and good fonts include correct variants, but I can cheat on that one; I just need to move the glyph, not change its shape.

No one seems to have figured out the necessary font-encoding tricks to pull this off with PDF::API2. At least, it’s not turning up in any google incantation I try, which leaves me with one conceptually disgusting workaround: rotate and flip. Calligraphers and type-weenies will cringe, but at text sizes it will pass. The correct character is on the left:

vertical kana hack

Now to write the code for both workarounds…

[side note: Adobe’s premier software suite is remarkably fragile; I just got it into a state where I couldn’t run Photoshop. How? I started Illustrator, which opened Adobe’s software-update tool in the background, then quit Illustrator. When I started Photoshop, it tried to open the update tool again, couldn’t, and crashed.]