[Koha-devel] Multilingual label printing in Koha (praise be to Bywater!)

dcook at prosentient.com.au dcook at prosentient.com.au
Fri Jul 1 07:16:59 CEST 2022


While this has consumed more of my day than I would’ve anticipated, it’s been a very useful exercise!

 

I downloaded NotoSansTC.otf from Google (although you can just install it from Debian/Ubuntu too although they supply .ttc files), and opened it in FontForge. I used “CID > Flatten”, “Encoding > Reencode > UnicodeBmp”, and then I noticed that the “space” and “hyphen” characters were missing, so I copied them in from the WenQuanYi font. I used “File > Generate Fonts” and chose the “TrueType” export format, which exports as a “.ttf” file. 

 

I loaded that into Koha via the “ttf” section of koha-conf.xml, and now I have Noto fonts rendering English and Chinese via the Koha Label Creator.

 

It’s taken a few hours to learn the basics of FontForge and font files, but now I feel fairly comfortable. I am sure that many other Koha libraries could leverage the same tool and processes to get TTF font files that are able to meet their multilingual needs. 

 

Browsing through the font file, I see a fair number of European symbols from French, Spanish, and Norwegian in the font file.

 

Anyway… get in touch if you want more information about working with font files I guess! These past 48 hours have been very illuminating! 

 

David Cook

Senior Software Engineer

Prosentient Systems

Suite 7.03

6a Glen St

Milsons Point NSW 2061

Australia

 

Office: 02 9212 0899

Online: 02 8005 0595

 

From: dcook at prosentient.com.au <dcook at prosentient.com.au> 
Sent: Friday, 1 July 2022 1:32 PM
To: 'Kyle Hall' <kyle at bywatersolutions.com>; 'Indranil Das Gupta' <indradg at l2c2.co.in>
Cc: 'Koha-devel' <koha-devel at lists.koha-community.org>; 'Brendan Gallagher' <brendan at bywatersolutions.com>
Subject: RE: [Koha-devel] Multilingual label printing in Koha (praise be to Bywater!)

 

Kyle:

 

TIL a new word! I don’t think that I’d ever heard “yinz” before. Thanks for keeping life interesting, Kyle!

 

Once you start going down that path of trying to turn HTML and CSS into a PDF programmatically, I think that you need to start using a proper rendering engine. I’ve used “wkhtmltopdf” (Qt Webkit engine), Puppeteer, Playwright, and headless Chrome.

 

There are a few CPAN modules for working with “wkhtmltopdf” although it looks like they all wrap the binary rather than being Perl bindings for the C library but that’s probably OK. 

https://metacpan.org/pod/WKHTMLTOPDF

https://metacpan.org/pod/PDF::WebKit

 

Looks like it’s also available in Debian and Ubuntu: 

https://packages.debian.org/search?keywords=wkhtmltopdf

https://packages.ubuntu.com/bionic/wkhtmltopdf. 

 

--

 

Indranil: 

 

I think that you may be right about PDF::Reuse (and friends) not being up to the task overall…

 

However, I discovered that a number of Chinese fonts like Noto CJK fonts (e.g. Noto Sans TC) and WenQuanYi (https://packages.ubuntu.com/bionic/fonts-wqy-zenhei) actually contain glyphs for both English and Chinese. Using “fontforge”, I was able to create a TTF file from the WenQuanYi TTC file, which can be used by Koha’s Label Creator to print both English and Chinese on the same label using the same font. I just referenced my new TTF via koha-conf.xml and voila!

 

(I did notice that if I copy the text from the PDF and paste it elsewhere, it will just show gibberish, but apparently that’s a pre-existing problem with the PDF generator…) 

 

Unfortunately, I wasn’t able to get a good quality TTF from the Noto Sans TC. It worked well on the Chinese and English but it couldn’t display space characters, so I couldn’t use that in the end. 

 

I find this whole font business very interesting. Personally, I’d love to know how browsers and word processors decide which font to apply. I keep thinking that they must have maps based off of Unicode code points and then choose an appropriate font based on that. But I don’t know for sure. 

 

In theory, PDF::Reuse could be changed to use “fontconfig” to see what font is available on the OS for a particular Unicode codepoint, so we could write a simple algorithm combined with a hash map to provide better font support for Koha’s Label Creator… but yeah it would take some time and energy. While I find it interesting, I’m not sure that I find it interesting enough to devote my free time to it. 

 

I guess we’ll see how long this tickles my brain.

 

David Cook

Senior Software Engineer

Prosentient Systems

Suite 7.03

6a Glen St

Milsons Point NSW 2061

Australia

 

Office: 02 9212 0899

Online: 02 8005 0595

 

From: Kyle Hall <kyle at bywatersolutions.com <mailto:kyle at bywatersolutions.com> > 
Sent: Thursday, 30 June 2022 9:27 PM
To: Indranil Das Gupta <indradg at l2c2.co.in <mailto:indradg at l2c2.co.in> >
Cc: dcook at prosentient.com.au <mailto:dcook at prosentient.com.au> ; Koha-devel <koha-devel at lists.koha-community.org <mailto:koha-devel at lists.koha-community.org> >; Brendan Gallagher <brendan at bywatersolutions.com <mailto:brendan at bywatersolutions.com> >
Subject: Re: [Koha-devel] Multilingual label printing in Koha (praise be to Bywater!)

 

That's awesome! Thanks Yinz!

 

I think the unicorn we need is something like https://metacpan.org/pod/PDF::FromHTML but with support for CSS. AFAIK such a thing doesn't exist :/

 

Kyle

 

On Thu, Jun 30, 2022 at 5:48 AM Indranil Das Gupta <indradg at l2c2.co.in <mailto:indradg at l2c2.co.in> > wrote:

Yep! the Bywater Solutions plugin by Kyle does the job nicely "outside the box" :-) 

 

IIRC the label printing code was last worked on by Chris N a long long time back. As far as I can tell the non Latin printing issue is due to the PDF library we are using. Prolly needs a rewrite for that part which requires both time and funds :-( 

 

-Indranil 

 

 

 

On Thu, 30 Jun, 2022, 12:34 pm , <dcook at prosentient.com.au <mailto:dcook at prosentient.com.au> > wrote:

Hi all,

I had a problem where I couldn't print Chinese and English on barcode labels
using Koha's built-in Label Creator, since it uses individual font files and
I couldn't find a free and open individual font that supports both European
and Chinese scripts.

Fortunately, I recalled that Kyle @ ByWater Solutions created this plugin:
https://github.com/bywatersolutions/koha-plugin-label-maker. It uses HTML
and CSS to generate labels in the browser, and the browser is already
capable of using multiple different fonts to support multiple different
scripts. The plugin did a great job of rendering barcodes with both Chinese
and English written on them! Thanks, Bywater Solutions, for saving the day!

--
Nerdy thoughts:

If I look at the "Computed" styles in the F12 tools in Chrome on Windows 10,
it says the English is rendered using the "Times New Roman" font, and it
says that the Chinese is rendered using the "Microsoft YaHei" font. If I do
the same thing in Microsoft Word, the English is in "Calibri" and the
Chinese is in "DengXian". If you read
https://fonts.google.com/noto/use#how-are-noto-fonts-organized it says "If
you have text in multiple languages that use different scripts, either the
app or the person who typesets the text needs to switch between the
different fonts accordingly."

I'm not an expert on fonts, so I'm not sure what would be involved with
getting Koha's PDF libraries to use different fonts for different scripts. I
don't know how Chrome and Word detect that they need to use a different
font. I don't know if it's a map of Unicode codepoints to existing font
mappings, or if it iterates through a list of fallbacks, or what. 

I probably won't go too far down this rabbit hole, since the ByWater Koha
Plugin solved my immediate use case, but it's an interesting topic, and this
is a major limitation with Koha's Label Creator, so we might want to think
about a change in the future...

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

Office: 02 9212 0899
Online: 02 8005 0595


_______________________________________________
Koha-devel mailing list
Koha-devel at lists.koha-community.org <mailto:Koha-devel at lists.koha-community.org> 
https://lists.koha-community.org/cgi-bin/mailman/listinfo/koha-devel
website : https://www.koha-community.org/
git : https://git.koha-community.org/
bugs : https://bugs.koha-community.org/



-- 

Kyle M. Hall

Loose Cannon, ByWater Solutions

 <mailto:kyle at bywatersolutions.com> kyle at bywatersolutions.com
 <http://bywatersolutions.com/> https://bywatersolutions.com

 <http://bywatersolutions.com/what-is-koha/> What is Koha?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.koha-community.org/pipermail/koha-devel/attachments/20220701/23a59f35/attachment-0001.htm>


More information about the Koha-devel mailing list