Cairo (graphics)
Original author(s) | Keith Packard, Carl Worth[1] |
---|---|
Developer(s) | Carl Worth, Behdad Esfahbod |
Initial release | Before 2003[2] |
Stable release | |
Repository | gitlab |
Written in | C |
Type | Graphics library |
License | GNU Lesser General Public License version 2.1 (only) or Mozilla Public License 1.1 |
Website | www |
Cairo (stylized as cairo) is an
Software architecture
Language bindings
A library written in one programming language may be used in another language if
Toolkit bindings
Since Cairo is only a drawing library, it can be quite useful to integrate it with a graphical user interface toolkit.
- FLTK has full Cairo support (through
--enable-cairo
compile switch). - graphical control elements, and since version 3.0 all renderingis done through Cairo.
- The Cairo development team maintains up-to-date instructions for rendering surfaces to SDL.[6]
Available back-ends
Cairo supports output (including
There are other back-ends in development targeting the graphics APIs
Drawing model
The Cairo drawing model relies on a three-layer model.
Any drawing process takes place in three steps:
- First a mask is created, which includes one or more vector primitives or forms, i.e., circles, squares, TrueType fonts, Bézier curves, etc.
- Then source must be defined, which may be a color, a color gradient, a bitmap or some vector graphics, and from the painted parts of this source a die cut is made with the help of the above defined mask.
- Finally the result is transferred to the destination or surface, which is provided by the back-end for the output.
This constitutes a fundamentally different approach from
style
attribute. That said, the models are not incompatible; many SVG renderers use Cairo for heavy lifting.[13]Example
Quite complex "
#include <cairo-svg.h>
#include <stdio.h>
int main(int argc, char **argv) {
cairo_surface_t *surface = cairo_svg_surface_create("Cairo_example.svg", 100.0, 100.0);
cairo_t *cr = cairo_create(surface);
/* Draw the squares in the background */
for (int x = 0; x < 10; ++x)
for (int y = 0; y < 10; ++y)
cairo_rectangle(cr, x * 10.0, y * 10.0, 5, 5);
cairo_pattern_t *pattern = cairo_pattern_create_radial(50, 50, 5, 50, 50, 50);
cairo_pattern_add_color_stop_rgb(pattern, 0, 0.75, 0.15, 0.99);
cairo_pattern_add_color_stop_rgb(pattern, 0.9, 1, 1, 1);
cairo_set_source(cr, pattern);
cairo_fill(cr);
/* Writing in the foreground */
cairo_set_font_size (cr, 15);
cairo_select_font_face (cr, "Georgia", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD);
cairo_set_source_rgb (cr, 0, 0, 0);
cairo_move_to(cr, 10, 25);
cairo_show_text(cr, "Hallo");
cairo_move_to(cr, 10, 75);
cairo_show_text(cr, "Wikipedia!");
cairo_destroy(cr);
cairo_surface_destroy(surface);
}
Notable usage
Cairo is popular in the open source community for providing cross-platform support for advanced 2D drawing.
- graphical control elements.[14]Since GTK version 3, all the rendering is done using Cairo.
- A program called gtk-vector-screenshot found in Debian allows for taking vector (SVG, PDF, or PostScript) screenshots of GTK 3 applications.[15]
- The namespaces.
- The Firefox 3, uses Cairo as the graphics back-end for rendering both web page content and the user interface(or "chrome").
- The WebKit framework uses Cairo for all rendering in the GTK and EFL ports. Support has also been added for SVG and <canvas> content using Cairo.
- The Poppler library uses Cairo to render PDF documents. Cairo enables the drawing of antialiased vector graphics and transparent objects.
- The vector graphics application PDF and PostScript export since release 0.46.[19]
- The original version of
- MorphOS 2.5 features a shared library implementation of Cairo, which was available as stand-alone release for earlier MorphOS versions.
- AmigaOS 4.1 supports a shared object library of Cairo (libcairo.so) in its default installation.
- FontForge enabled Cairo by default for rendering in mid-October 2008.
- SVGformats using Cairo if available.
- PNG output.[21]
- Internet Browser for PlayStation 3 uses Cairo since system software update 4.10.
- Synfig 0.64 now supports optional Cairo rendering.
- On-demand graphing of time series data in Graphite.
- The Konfabulator/Yahoo widget engine uses Cairo for identical output to both Win32 and Quartz on Mac OS/X.
- 3D CADsoftware.
History
Complex text layout
Cairo handles Latin and CJK based fonts, but does not directly support complex text layout fonts, which require shaping the glyphs. The Cairo developers recommend using Pango, which provides complex text layout and can integrate with Cairo.[24]
See also
References
- ^ "Carl's boring web pages". cworth.org. 2013. Retrieved 11 July 2014.
- ^ a b "Xr: Cross-device Rendering for Vector Graphics". Retrieved 2009-06-08.
- ^ "Cairo 1.18 Released - First Stable Release In Five Years". www.phoronix.com. Retrieved 2023-09-23.
- ^ "Cairo homepage". Retrieved 2010-10-30.
- ^ "Cairo Language Bindings". Retrieved 2014-04-16.
- ^ "SDL". Cairo. 2009-02-17. Retrieved 2014-11-03.
- ^ Chris Wilson (2009-07-22). "New OpenGL backend merged". Retrieved 2010-02-12.
- ^ Øyvind Kolås (2008-01-24). "Announcing OpenVG backend". Retrieved 2010-02-12.
- ^ Vladimir Vukićević (2008-05-06). "Well Isn't That Qt". Archived from the original on 2010-04-09. Retrieved 2010-02-12.
- ^ Chris Wilson (2009-08-31). "Cool Stuff". Retrieved 2010-02-12.
- ^ Bas Schouten (2009-11-22). "Direct2D: Hardware Rendering a Browser". Retrieved 2010-02-12.
- ^ Larabel, Michael (2022-02-27). "Cairo graphics library drops many old backends". Phoronix. Retrieved 2022-06-05.
- ^ "GNOME/librsvg". GitHub.
- ^ "GTK+ to Use Cairo Vector Engine". Retrieved 2009-12-27.
- ^ "Details of package gtk-vector-screenshot in stretch". Debian. GitHub
- ^ "Mono - Drawing". Retrieved 2009-12-27.
- ^ "Moonlight Notes". Retrieved 2009-12-27.
- ^ "Gecko 1.9 Roadmap". Retrieved 2009-12-27.
- ^ "ReleaseNotes046". Inkscape Wiki. Retrieved 2008-03-31.
- ^ "ManimCE tutorial by TheoremOfBeethoven — ManimCE tutorial by TB documentation". zavden.github.io. Retrieved 2023-01-29.
- ^ "Gnuplot version 4.4.0 announcement". Gnuplot homepage. Archived from the original on 2011-05-14. Retrieved 2011-02-22.
- ^ "Mailing list thread about the Cairo name change". 15 July 2003. Retrieved 2009-06-08.
- ^ "Mailing list thread about the Cairo name change". 12 July 2003. Retrieved 2006-12-02.
- ^ "How do I use Pango instead of Cairo's "toy" text API?". Retrieved 2024-03-20.
External links
- Official website
- cairocffi on GitHub – CFFI-based Cairo bindings for Python
- "Cairo API reference manual".
- "Cairo here, there and everywhere". Linux.Ars. Ars Technica. 23 August 2005.
- "Cross-platform graphics with cairo". IBM.
- "Comparison of PHP image libraries".
- "The Cairo graphics tutorial".