alacarte-maps / alacarte

Renderer for OpenStreetMap tiles.
https://alacarte-maps.github.io/
Other
58 stars 18 forks source link

Unicode font support with Cairo #68

Open florianjacob opened 8 years ago

florianjacob commented 8 years ago

While alaCarte itself should have no problem with unicode, the drawing libraries we currently use (Cairo / Pango) can be very particular when it comes to unicode font rendering. Maybe some of our outgoing render calls to them are wrong.

Advantages:

Scheirle commented 7 years ago

Umlauts are working fine here: 11-1075-707

But as you can see in the bottom right corner in the debug string there are still some boxes ([]). Maybe because the font (DejaVu Sans) does not support them?

diff --git a/src/server/renderer/renderer.cpp b/src/server/renderer/renderer.cpp
index b8897f0..006ff75 100644
--- a/src/server/renderer/renderer.cpp
+++ b/src/server/renderer/renderer.cpp
@@ -124,6 +124,7 @@ void Renderer::printTileId(cairo_t* cr,
        labelstrm << "X: " << id->getX() << " Y: " << id->getY();
        labelstrm << " Zoom: " << id->getZoom();
        labelstrm << " Style: " << id->getStylesheetPath();
+       labelstrm << " UT: üöäß子曰:";
        std::string label = labelstrm.str();
        cairo_text_path(cr, label.c_str());    

Cairo: 1.14.6

florianjacob commented 7 years ago

Maybe we should switch to Noto Sans, which contains almost everything under the sun?

There's a 3 years old version in Jessie: https://packages.debian.org/de/jessie/fonts-noto

florianjacob commented 7 years ago

Seems like the unicode characters are passed correctly to the font rendering. We tested with several Noto font variants: e.g. Noto Sans CJK JP renders latin and japanese correctly, but not arabic. Therefore a user could specify a japanese or cyirilic font, and it would work.

The usual solution according to https://www.google.com/get/noto/help/guidelines/ for the web is to suppot a list of font family ordered by priorities, so that glyphs of more than one font can be used.

Problem with Cairo:

Text and features related to fonts are poorly supported.

Simple text based on Latin or Cyrillic alphabets is generally displayed correctly. Horizontal alignment is quite well supported, really simple vertical alignment (top, middle, bottom) is supported too.

Other languages, and particularly those based on right-to-left or top-to-bottom directions are not supported at all.

Fonts are managed by Cairo, which is known to be bad at managing advanced font features. Font family, size, weight and style are supported for common simple values, but don’t follow the specification on many points (including the font family choice when multiple values are given). Hinting and anti-aliasing are supported. Kerning, stretching, font variants, word and letter spacing options, glyph orientations, baseline shifts and many other properties are not supported.

Source: http://cairosvg.org/documentation/#text-and-fonts

Therefore, we cannot support e.g. the whole world with Noto.

According to https://en.wikipedia.org/wiki/Unicode_font#List_of_Unicode_fonts the only other font with substantial unicode coverage is the Bitmap font GNU Unifont - not a real alternative.

Seems like we would need to switch the graphics library to support this properly - maybe https://skia.org/ is a possible candidate. https://en.wikipedia.org/wiki/Skia_Graphics_Engine

I think we considered Skia some time before, but can't remember the problems we had with Skia.

moees commented 3 years ago

Is there any support for right to left languages i.e. arabic, I tried Cairo and Noto Sans but the rendering still gives inversed characters.