Re: Using pango in KMSCON (terminal-emulator)



Hi Behdad

On Tue, Feb 19, 2013 at 8:28 AM, Behdad Esfahbod <behdad behdad org> wrote:
On 02/16/2013 04:33 PM, David Herrmann wrote:
3) Whenever I have to draw a cell, I ask pango to give me a buffer for
the given Unicode char (or better: Unicode string which might contain
combining-characters)

The problem is: to correctly handle Unicode text, you need to give Pango
paragraph at a time.  Anything else will have its shortcomings.  libvte gives
Pango a cell at a time (including combining characters).  That works fine for
many scripts, but not for, say, Indic scripts, or for right-to-left text, or
Arabic shaping, etc.

If you are willing to let go of those, the question becomes, why do you want
to use Pango to begin with?  Ie. what writing systems do you want to support?
 You may not need to use Pango to begin with.

I have tried a lot. In fact, I have a basic 256-glyphs 8x16-pixel
static font compiled in as fallback. I have also an optional
GNU-Unifont backend that uses 8x16 / 16x16 pixel glyphs.
I have written a freetype2+font-config backend and a pango_ft2
backend. So I don't particularly depend on pango, but it has provided
the best results of all backends.

That is, it provides exactly what I need. It loads system
configuration automatically, I can tell it the default font properties
and it provides me with the best available glyphs it can find.
I'm particularly talking about the "glyph-substitution" if the font
doesn't provide the glyph. I think I could extend the
freetype2+font-config backend to do that, either. But why bother if
pango can do that by itself? (and also I don't know how to do that
with font-config..)

You're right, pango is probably a bit blown for this simple task. But
pango is installed on most systems, anyway, so I can make use of it.
And users who don't want pango can still use my static built-in fonts.
Maybe sometime I can write a proper freetype2+font-config backend that
does all the parts I want. But until then, I'm pretty happy with
pango.


4) It's important that I get full access to the 2D buffer of the
glyph. I sometimes need to change stride/size/etc. and the
hardware-blitters have different constraints. Hence, I cannot use any
opaque "glyph"/gtk/etc. structures but instead need _direct_ buffer
access.

You can get that with pangocairo.  I hear you want to do your own blitting.
That's fine.

So you mean I should allocate a cairo_image_surface_t, draw to it and
then use the buffer of the image_surface? Yeah, ok, that sounds about
right.



What do I currently do?

Font-Management:
1) I start with pango_ft2_font_map_new()
2) For each font I use I create a pango-context from this ft2 font-map.
3) I set the user-selected font-description for the pango-context
4) I render the standard ASCII character set to measure the standard
width, height and baseline
5) These standard sizes are then used as default cell-size

That sounds about right.  I assume you prefer not to have a cairo dependency
added in?  If you don't mind, pangocairo is the preferred backend.  pangoft2
is obsolete.

I don't want the cairo-dependency in the main kmscon program. However,
as long as the pango font-backend uses cairo only internally, this is
fine. I mean, if a user installs the kmscon pango backend, then they
did compile pango with pango-cairo, anyway (at least 99% do that,
right?). So I don't mind as long as I pass the raw data buffers to the
kmscon text-renderers and don't have to pass cairo_t or similar.

But as you said, that's possible and I will have a look and try using
pangocairo with cairo_image_surface_t's.

However, I'd appreciate if someone could tell me whether there are
ways to improve this? And I have some questions that I couldn't figure
out myself:

1) How do I disable AA fonts? How can I enable subpixel rendering?

I don't think pangoft2 supports subpixel rendering.  pangocairo does.  Not
sure about AA.  You may be able to get away with that by calling a function
using pango_ft2_font_map_set_default_substitute() and setting FC_ANTIALIAS in
there.

I just checked it out, I can set all the subpixel/AA/etc. properties
if I pass the right subpixel-layout. So pangocairo is the way to go,
thanks.



2) How can I detect system-defaults? That is, let the user define
whether to use AA-fonts, subpixel-rendering, font-name, ... I
currently configure this in kmscon-specific configuration but I'd
prefer font-config options.

You should already be getting fontconfig going.  Just ask for font named
"monospace".  There is not "system default" font size.  There *is* X / GNOME
specific stuff for that, but I assume that's not what you are looking for.

I had a user who complained that their config wasn't correctly read.
Turned out to be a wrong configuration and everything works now. I
never played much with font-config so I wasn't sure. But you're right,
everything works properly.
font-config settings are fine, GNOME/KDE etc. settings don't make much
sense, right.


3) How am I notified about font-updates in the system? If the
currently used font is updated I'd like to clear my cache and let
pango re-render the glyphs.

For fontconfig changes, you can do something like this:

http://git.gnome.org/browse/gnome-settings-daemon/tree/plugins/xsettings/fontconfig-monitor.c

Awesome! Thanks! dnotify/inotify on the font-config files, few-seconds
timeout to combine multiple notifications and then clear the caches.
One thing is missing though: You don't update the monitor itself if
the configuration changes? Is that on purpose? There might be new
font-directories or configuration files that we should add to the
monitor.

Also, which pango object do I need to recreate on change? Everything
down to the font-map?


4) What should I use as default render-mode? High-DPI (>300?) no AA
but subpixel? Low-DPI AA but no subpixel? I have actually no idea what
looks best... And what to do if I cannot get DPI or subpixel-layout
information for a display?

If anything, you should enable subpixel for low DPI and siable for high.  It's
tricky though.  Best to not try to out-guess the user.  Just do nothing?

I recently read your article about font-rendering with high DPI and
was wondering what to do. But maybe that decision belongs to
font-config and pango, and I should just let them chose the default
and not care at all. Users can always use font-configurations to
overwrite it, anyway.

Thanks a lot for your help! I will give pangocairo a try.
Regards
David


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]