LemonBoy / bar

A featherweight, lemon-scented, bar based on xcb
MIT License
1.63k stars 194 forks source link

Japanese characters not showing at all in bar #68

Closed reportados123 closed 10 years ago

reportados123 commented 10 years ago

Hi, I have a problem with bar, for some reason bar is unable to render japanese characters despite it rendering in my terminal properly.

For example, if I enter in the command

echo 'Hello こんにちは' | bar -g 120x20+10+80 -f "-gohu-gohufont-medium-r-normal--11-80-100-100-c-60-iso10646-1" -p

The displayed bar will render the text "Hello" but not the japanese text "こんにちは"

On the other hand, if I just type this into urxvt,

echo 'Hello こんにちは'

It will properly echo out the english and japanese text onto the screen. In my Xresources, I only have the stlarch font and gohufont being used, which are the same fonts that I am using for bar. I don't understand why the japanese characters won't render on bar, but it will anywhere else (ie ncmpcpp, urxvt, etc) despite using the same fonts.

EDIT: If it helps, I am on arch linux and I installed bar via git cloning and then sudo make install.

reportados123 commented 10 years ago

Okay, so I got the japanese font to work, by doing this

echo 'Hello こんにちは' | bar -g 120x20+10+80 -f "-misc-fixed-medium-r-normal-ja-0-0-75-75-c-0-iso10646-1","-gohu-gohufont-medium-r-normal--11-80-100-100-c-60-iso10646-1" -p

However, doing this means that I can't use gohufont despite having it as my alternative font. If I switch around the order, with gohufont being first, gohufont works but not the japanese font.

graboy commented 10 years ago

This is because bar assumes that a font which satisfies some symbols from a character set can satisfy all of them. To get around this, you can use gohufont's iso8859 character set as the primary font, and the iso10646 japanese font as the secondary font. For example:

echo "Hello こんにちは" | bar -g 120x20+10+80 -f "-gohu-gohufont-medium-r-normal--11-80-100-100-c-60-iso8859-1","-misc-fixed-medium-r-normal-ja-0-0-75-75-c-0-iso10646-1" -p

I plan on making a pull request to allow bar to handle an arbitrary number of fonts, and I'll fix this incompatibility along the way.

LemonBoy commented 10 years ago

I went for only two fontsets because of performance reasons, a cache-miss would scan N fontsets and this isn't that good when you could potentially redraw everything every few ms. Re the original issue, you need to place the fonts in that order as the range of characters provided by the fixed font overlaps the gohufont one.

reportados123 commented 10 years ago

Thanks for the help graboy and LemonBoy! It works! I'm hoping graboy's patch to make it in, as the above solution is a workaround that only works in this case. If I were to use a font such as uushi which iso10646 is the only possible encoding available, the above workaround will not work. Testing graboy's patch works fine for me, so if everything is okay, I'd be happy to see his patch to make it in as it solves the problem without me having to change encodings.