crystal-community / crystal-libraries-needed

A list of libraries that are needed or wanted for the Crystal-Language
141 stars 4 forks source link

Pango bindings - generic lib for laying out and rendering of text #55

Open bew opened 7 years ago

bew commented 7 years ago

From main website:

Pango is a library for laying out and rendering of text, with an emphasis on internationalization. Pango can be used anywhere that text layout is needed, though most of the work on Pango so far has been done in the context of the GTK+ widget toolkit. Pango forms the core of text and font handling for GTK+-2.x.

Pango is designed to be modular; the core Pango layout engine can be used with different font backends. There are three basic backends, with multiple options for rendering with each.

Dynamically loaded modules then handle text layout for particular combinations of script and font backend. Pango ships with a wide selection of modules, including modules for Hebrew, Arabic, Hangul, Thai, and a number of Indic scripts. Virtually all of the world's major scripts are supported.

The integration of Pango with Cairo (See #54) provides a complete solution with high quality text handling and graphics rendering.


Manual: https://developer.gnome.org/pango/stable/

aravindavk commented 2 years ago

Not all the Pango APIs were added, but a few are available with the Chitra library.

Chitra is a 2D graphics library for Crystal language, that uses Cairo and Pango(Pango for text rendering). The following example shows writing a text. For Cairo bindings it uses https://github.com/TamasSzekeres/cairo-cr and custom bindings for Pango integration(https://github.com/aravindavk/chitra/blob/main/src/pangocairo.cr)

require "chitra/global_context"

size 500, 50
# Background color white
background 1

no_stroke
line_height 1.1
font "Latin Modern Roman", 20
text_align "center"
text_box "Hello World!", 10, 10, width-20

save "hello.png" # pdf, SVG and png are supported

hello

Documentation: https://aravindavk.in/chitra/ Github Repo: https://github.com/aravindavk/chitra License: MIT

NOTE: This library is still in the early development phase.

HCLarsen commented 2 years ago

If memory serves, Pango/Cairo are part of GLib, so you might want to check gtk4.cr to see if any of it's covered there.