Hi,

On 01.02.2013 13:07, Vasya Belkin wrote:
[...]
> The thing with cairo's toy font API: I have no idea what is that :)

Cairo has several toy APIs. These are things which are "nice to have", but
shouldn't really be used by applications. For example, cairo can directly read
and write PNG files, but it can't do other file formats. And cairo can render
western languages, but more complicated scripts break.

The reason these APIs exist, I heard, is to make it easier to write small
examples and unit tests (which only should use public API).

> But I
> really should check textbox.lua.

Here is the short version to get the size of some text:

local layout =
lgi.Pango.Layout.new(lgi.PangoCairo.font_map_get_default():create_context())
-- Choose a font
layout:set_font_description(beautiful.get_font("Times New Roman 12")
-- Tell it how it should shorten text that is too long
layout:set_ellipsize("END")
-- We want this left-aligned
layout:set_alignment("LEFT")
-- Finally, some text
layout.text = "The quick brown fox..."
-- How large is the text?
local ink, logical = layout:get_pixel_extents()
print(ink.width, ink.height)
print(logical.width, logical.height)

(The ink extents describe the area "in which pixels are affected" and the
logical extents is what you should pretend the text uses for e.g. calculating
distances)

(Disclaimer: The returned information can be slightly wrong. Technically, you
are supposed to inform the layout about the target that it is drawing to. This
is needed to make "proper" decisions about the effect of e.g. hinting on the
text size. Let's just hope that nothing goes wrong. :-) )

More information about pango layouts can be found in its API documentation:

http://developer.gnome.org/pango/stable/pango-Layout-Objects.html

Most of the functions should map quite naturally to what lgi does. Most
properties (things that have a "set" and a "get" function) can be accessed
directly. For example, in the above example "layout.text = 'foo'" actually calls
pango_layout_set_text().

(And of course textbox.lua still applies)

> The problem is that I think it's very hard
> to know and understand the possibilities of cairo's and pango's API,
> because of the lack of examples and documentation (or links to them) in
> Awesome. May be I'm wrong, but being myself a programmer, I really thought
> I can learn myself, but here, with Awesome, I always have troubles.

These APIs are just too powerful. Pango scares me, too, but I think I have a
relatively well understanding of cairo. :-)

> Actually the only thing I need in the wm is the possibility to organize
> "scrollable" (by buttons clicks) desktop at the TV screen, that I've
> managed to create somehow in 3.4, but, for now, not in 3.5.

Uhm. I'm not sure I understand what you mean here. If you still have

> But enough with
> complaints! The community of Awesome is really awesome. Thank you, Julien,
> thank you, Uli, thank you all :)
[...]

Thanks :-)

Uli
-- 
Bitte nicht mit dem verbleibenden Auge in den Laser gucken.
 - Vincent Ebert

-- 
To unsubscribe, send mail to [email protected].

Reply via email to