[Koha] Fonts for "Label creator"

dcook at prosentient.com.au dcook at prosentient.com.au
Tue Jul 5 12:06:26 NZST 2022


Hi all,

Do folk ever need to print labels in multiple languages with different scripts and find that the “Label creator” doesn’t work? European scripts will print but Chinese, Japanese, Korean and others don’t? Well I have a story about how to make it work...

--

Recently, I needed to print labels that had both English and Chinese, but the Chinese was showing up as an empty box like ▯ while the English appeared correctly. Initially I turned to the Koha plugin https://github.com/bywatersolutions/koha-plugin-label-maker which worked great, because it leverages the browser's ability to detect different scripts and dynamically choses appropriate fonts to match them (on Chrome on Windows 10 the browser would use Times New Roman for the English and use "Microsoft YaHei" for the Chinese). However, the problem itched my brain, so I kept looking for answers in core Koha.

In the "koha-conf.xml" file, there is a "ttf" element. Within that XML, there are font elements where font codes get mapped to "ttf" TrueType font files. While it's not the most elegant solution, you can choose to replace these font files, so that "Courier Bold" can actually be something else. 

Unfortunately, I still had a problem. While the browser could switch fonts, Koha can only use 1 font. Currently, it can't dynamically switch between different fonts. Adding that support would require time and money which I didn't have. Fortunately, Chinese fonts like Noto Sans CJK TC contain not only Chinese but also English! I didn't need Koha to change fonts; I could just use one font!

However, the Noto fonts on Debian/Ubuntu come as large "ttc" files which are collections of font files and not as individual "ttf" files. Even downloading particular fonts like Noto Sans CJK TC Bold from Google, they came as "otf" files, which aren't compatible with Koha. 

After a lot of reading, I downloaded a tool called "FontForge". I could open the "otf" file, "flatten" it, re-encode it using a Unicode option, and then export as a "ttf" file. I replaced the "Courier Bold" file of /usr/share/fonts/truetype/dejavu/DejaVuSansMono-Bold.ttf in Koha with my newly generated Noto ttf file.

It printed out the Chinese text, but I noticed instead of spaces in English it was now showing the empty box ▯ again. Ubuntu had a package called "fonts-wqy-zenhei" which provides another Chinese font, so I ran that through the same process and that worked perfectly. 

Since Noto is a very popular font and I am very stubborn, I decided to keep trying with the Noto. Using FontForge, I was able to manually add in the missing space definition in the font file, so I was able to export a Noto Sans CJK TC Bold "ttf" file, which also worked perfectly.

I got Koha to print barcode labels with English and Chinese text!

--

If people want to know more specifics, I'm happy to provide more technical/specific information. I figured I'd share this story though, as I imagine that other people must bump into this same problem. I'm personally familiar with the English, French, Chinese, and Korean languages so those are the languages I'm best capable to help with, but I imagine I could still help with any language. 

David Cook
Senior Software Engineer
Prosentient Systems
Suite 7.03
6a Glen St
Milsons Point NSW 2061
Australia



More information about the Koha mailing list