Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Cairo (graphics)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
{{Short description|Vector graphics-based software library}} {{DISPLAYTITLE:cairo (graphics)}} {{Use mdy dates|date=October 2024}} {{Infobox software | name = Cairo | title = | logo = Cairo banner closeup.svg | logo size = 150px | logo caption = [[File:Cairo graphics.svg|125px]] | screenshot = | caption = | collapsible = | author = [[Keith Packard]], Carl Worth<ref>{{cite web |url= http://cworth.org/ |title=Carl's boring web pages |work=cworth.org |year=2013 |access-date=July 11, 2014}}</ref> | developer = Carl Worth, [[Behdad Esfahbod]] | released = Before {{Start date and age|2003}}<ref name=xrols2003>{{cite web | title=Xr: Cross-device Rendering for Vector Graphics | url=http://cworth.org/~cworth/papers/xr_ols2003/html/ | access-date=June 8, 2009}}</ref> | discontinued = | latest release version = {{Latest stable software release/cairo}} | latest_preview_version = | latest_preview_date = | programming language = [[C (programming language)|C]] | operating system = <!--Does not apply--> | platform = <!--Does not apply--> | size = | language = | language count = | language footnote = | status = | genre = [[Graphics library]] | license = [[GNU Lesser General Public License]] version 2.1 (only) or [[Mozilla Public License]] 1.1 | alexa = | website = {{URL|https://www.cairographics.org}} | repo = {{URL|https://gitlab.freedesktop.org/cairo/cairo}} }} '''Cairo''' (stylized as '''cairo''') is an [[Open-source software|open-source]] [[graphics library]] that provides a [[vector graphics]]-based, device-independent [[Application programming interface|API]] for [[software developer]]s. It provides primitives for [[Plane (mathematics)|two-dimensional]] drawing across a number of different [[front and back ends|backends]]. Cairo uses [[hardware acceleration]]<ref>{{cite web | url = http://cairographics.org/ | title = Cairo homepage | access-date = October 30, 2010}}</ref> when available. == Software architecture == === Language bindings === A library written in one programming language may be used in another language if [[language binding|bindings]] are written; Cairo has a range of bindings for various languages including [[C++]], [[C Sharp (programming language)|C#]] and other [[Common Language Infrastructure|CLI languages]], [[Delphi (programming language)|Delphi]], [[Eiffel (programming language)|Eiffel]], [[Fortran]], [[Factor (programming language)|Factor]], [[Harbour (programming language)|Harbour]], [[Haskell (programming language)|Haskell]], [[Julia (programming language)|Julia]], [[Lua (programming language)|Lua]], [[Perl]], [[PHP]], [[Python (programming language)|Python]], [[Ruby (programming language)|Ruby]], [[Rust (programming language)|Rust]], [[Scheme (programming language)|Scheme]], [[Smalltalk]] and several others like [[Gambas]] (Visual Basic like).<ref>{{cite web |url=http://cairographics.org/bindings/ |title=Cairo Language Bindings |access-date=April 16, 2014}}</ref> === 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 <code>--enable-cairo</code> compile switch). * [[GTK]] began in 2005, with version 2.8, to use Cairo to render the majority of its [[Graphical control element (software)|graphical control elements]], and since version 3.0 all [[rendering (computer graphics)|rendering]] is done through Cairo. * The Cairo development team maintains up-to-date instructions for rendering surfaces to [[Simple DirectMedia Layer|SDL]].<ref>{{cite web |url=http://cairographics.org/SDL/ |title=SDL |website=Cairo |date=February 17, 2009 |access-date=November 3, 2014}}</ref> === Available back-ends === Cairo supports output (including [[rasterisation]]) to a number of different [[front and back ends|back-ends]], known as "surfaces" in its code. Back-ends support includes output to the [[X Window System]], via both [[Xlib]] and [[XCB]], [[Graphics Device Interface|Win32 GDI]], [[Quartz Compositor|OS X Quartz Compositor]], the [[BeOS]] API, [[OS/2]], [[OpenGL]] contexts (directly<ref>{{cite web |url=http://lists.cairographics.org/archives/cairo/2009-July/017713.html |title=New OpenGL backend merged |author=Chris Wilson |date=July 22, 2009 |access-date=February 12, 2010}}</ref> and via glitz), local image buffers, [[Portable Network Graphics|PNG]] files, [[Portable document format|PDF]], [[PostScript]], [[DirectFB]] and [[Scalable Vector Graphics|SVG]] files. There are other back-ends in development targeting the graphics APIs [[OpenVG]],<ref>{{cite web |url=http://lists.freedesktop.org/archives/cairo/2008-January/012833.html |title=Announcing OpenVG backend |author=Øyvind Kolås |date=January 24, 2008 |access-date=February 12, 2010}}</ref> [[Qt (framework)|Qt]],<ref>{{cite web |url=http://blog.vlad1.com/2008/05/06/well-isnt-that-qt/ |title=Well Isn't That Qt |author=Vladimir Vukićević |date=May 6, 2008 |access-date=February 12, 2010 |url-status=dead |archive-url=https://web.archive.org/web/20100409072817/http://blog.vlad1.com/2008/05/06/well-isnt-that-qt/ |archive-date=April 9, 2010}}</ref> [[Skia Graphics Engine|Skia]],<ref>{{cite web |url=http://lists.cairographics.org/archives/cairo/2009-August/018052.html |title=Cool Stuff |author=Chris Wilson |date=August 31, 2009 |access-date=February 12, 2010}}</ref> and Microsoft's [[Direct2D]].<ref>{{cite web |url=http://www.basschouten.com/blog1.php/2009/11/22/direct2d-hardware-rendering-a-browser |title=Direct2D: Hardware Rendering a Browser |author=Bas Schouten |date=November 22, 2009 |access-date=February 12, 2010}}</ref> The BeOS, OS/2, DirectFB and OpenGL backends were dropped in 2022.<ref>{{cite web|url=https://www.phoronix.com/scan.php?page=news_item&px=Cairo-2022-Drops-Old-Code|title=Cairo graphics library drops many old backends|first=Michael|last=Larabel|publisher=Phoronix|date=February 27, 2022|accessdate=June 5, 2022}}</ref><ref>{{cite web |last1=Larabel |first1=Michael |title=Cairo Graphics Library Drops OpenGL Support After A Decade Of Inactivity |url=https://www.phoronix.com/news/Cairo-Drops-OpenGL |website=Phoronix |access-date=7 February 2025 |date=January 29, 2023}}</ref> === Drawing model === [[File:Cairo's drawing model.svg|thumb|The Cairo 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 curve]]s, 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 [[Scalable Vector Graphics]] (SVG), which specifies the color of shapes with [[Cascading Style Sheets]] (CSS) rules.{{Citation needed|date=September 2021}} Whereas Cairo would create a mask of a shape, then make a source for it, and then transfer them onto the surface, an SVG file would simply specify the shape with a <code>style</code> attribute. That said, the models are not incompatible; many SVG renderers use Cairo for heavy lifting.<ref>{{cite web |url=https://github.com/GNOME/librsvg |title=GNOME/librsvg |website=GitHub}}</ref><!-- Well, SVG 1.1. in fact provides a way to achieve similar result via filters. Checkout: https://www.w3.org/TR/SVG11/filters.html --> ==== Example ==== Quite complex "[[Hello world program|Hello world]]" graphics can be drawn with the help of Cairo with only a few lines of [[source code]]: [[File:Cairo example.svg|thumb|none|180px|SVG picture generated by this example]] <syntaxhighlight line lang="c"> #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); } </syntaxhighlight> == Notable usage == Cairo is popular in the open source community for providing cross-platform support for advanced 2D drawing. * [[GTK]], starting in 2005 with version 2.8, uses Cairo to render the majority of its [[Graphical control element (software)|graphical control elements]].<ref>{{cite web |url=http://developers.slashdot.org/article.pl?sid=05/02/04/2021236 |title=GTK+ to Use Cairo Vector Engine |date=February 5, 2005 |access-date=December 27, 2009}}</ref> Since GTK version 3, all the rendering is done using Cairo. ** A program called {{tt|gtk-vector-screenshot}} found in [[Debian]] allows for taking vector (SVG, PDF, or PostScript) [[screenshot]]s of GTK 3 applications.<ref>{{cite web |title=Details of package gtk-vector-screenshot in stretch |url=https://packages.debian.org/stretch/gtk-vector-screenshot |website=Debian}} [https://github.com/nomeata/gtk-vector-screenshot GitHub]</ref> * The [[Mono (software)|Mono Project]],<ref>{{cite web |url=http://www.mono-project.com/Drawing |title=Mono - Drawing |access-date=December 27, 2009}}</ref> including [[Moonlight (runtime)|Moonlight]],<ref>{{cite web |url=http://www.mono-project.com/MoonlightNotes#Rendering |title=Moonlight Notes |access-date=December 27, 2009}}</ref> has been using Cairo since very early in conception to power the back-ends of its [[GDI+]] (libgdiplus) and System.Drawing [[namespaces]]. * The [[Mozilla]] project has made use of Cairo in its [[Gecko (software)|Gecko layout engine]], used for rendering the graphical output of Mozilla products. Gecko 1.8, the layout engine for Mozilla Firefox 2.0 and [[SeaMonkey]] 1.0, used Cairo to render SVG and [[Canvas element|<canvas>]] content. Gecko 1.9,<ref>{{cite web |url=https://wiki.mozilla.org/Gecko_1.9_Roadmap#cairo_Graphics_Substrate |title=Gecko 1.9 Roadmap |access-date=December 27, 2009}}</ref> the release of Gecko that serves as the basis of [[Mozilla Firefox 3|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 [[Enlightenment Foundation Libraries|EFL]] ports. Support has also been added for SVG and <canvas> content using Cairo.{{cn|date=October 2024}} * The [[Poppler (software)|Poppler]] library uses Cairo to render PDF documents. Cairo enables the drawing of antialiased vector graphics and transparent objects.{{cn|date=October 2024}} * The vector graphics application [[Inkscape]] uses the Cairo library for its outline mode display, as well as for [[Portable Document Format|PDF]] and [[PostScript]] export since release 0.46.<ref>{{cite web |url=http://wiki.inkscape.org/wiki/index.php/ReleaseNotes046 |title=ReleaseNotes046 |work=Inkscape Wiki |access-date=March 31, 2008}}</ref> * The original version of [[Manim]] referred to as ManimCairo, a mathematical animation engine used in the animations of 3Blue1Brown's YouTube Videos. Manim has since moved to using [[OpenGL]]. This version is referred to as ManimGL.<ref>{{Cite web |title=ManimCE tutorial by TheoremOfBeethoven — ManimCE tutorial by TB documentation |url=https://zavden.github.io/manimce-tutorial/docs/html/index.html |access-date=January 29, 2023 |website=zavden.github.io}}</ref> * [[MorphOS]] 2.5 features a shared library implementation of Cairo, which was available as stand-alone release for earlier MorphOS versions.{{cn|date=October 2024}} * [[AmigaOS]] 4.1 supports a shared object library of Cairo (libcairo.so) in its default installation.{{cn|date=October 2024}} * [[FontForge]] enabled Cairo by default for rendering in mid-October 2008.{{cn|date=October 2024}} * [[R (programming language)|R]] can output plots in [[Portable Document Format|PDF]], [[PostScript]] and [[Scalable Vector Graphics|SVG]] formats using Cairo if available.{{cn|date=October 2024}} * [[Gnuplot]] 4.4 now uses Cairo for rendering [[Portable Document Format|PDF]] and [[Portable Network Graphics|PNG]] output.<ref>{{cite web | url = http://www.gnuplot.info/announce.4.4.0 | title = Gnuplot version 4.4.0 announcement | work = Gnuplot homepage | access-date = February 22, 2011 | archive-url = https://web.archive.org/web/20110514115341/http://www.gnuplot.info/announce.4.4.0 | archive-date = May 14, 2011 | url-status = dead }}</ref> * Internet Browser for PlayStation 3 uses Cairo since system software update 4.10.{{cn|date=October 2024}} * [[Synfig]] 0.64 now supports optional Cairo rendering.{{cn|date=October 2024}} * On-demand graphing of time series data in [[Graphite (software)|Graphite]].{{cn|date=October 2024}} * The Konfabulator/Yahoo widget engine uses Cairo for identical output to both Win32 and Quartz on [[Mac OS/X]].{{cn|date=October 2024}} *[[SolveSpace]], free and open source 2D and [[3D CAD]] software.{{cn|date=October 2024}} == History == [[Keith Packard]] and Carl Worth founded the Cairo project for use in the [[X Window System]].<ref name=xrols2003 /> It was originally (until at least 2003) called '''Xr''' or '''Xr/Xc'''. The name was changed to emphasize the idea of a cross-platform library to access [[display server]], not tied to the [[X Window System]].<ref> {{cite web | title=Mailing list thread about the Cairo name change | date=July 15, 2003 | url=http://lists.cairographics.org/archives/cairo/2003-July/000192.html | access-date=June 8, 2009}}</ref> The name ''Cairo'' derives from the original name ''Xr'', interpreted as the Greek letters [[chi (letter)|chi]] and [[rho (letter)|rho]].<ref> {{cite web | title=Mailing list thread about the Cairo name change | date=July 12, 2003 | url=http://lists.freedesktop.org/archives/cairo/2003-July/000184.html | access-date=December 2, 2006}} </ref> ==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.<ref>{{Cite web | url=https://www.cairographics.org/FAQ/#using_pango | title=How do I use Pango instead of Cairo's "toy" text API? | access-date=March 20, 2024}}</ref> == See also == {{Portal|Free and open-source software}} * [[Display PostScript]] and [[Quartz 2D]] * [[Skia Graphics Engine]] * [[Starling Framework]] * [[WebGL]] == References == {{Reflist|30em}} == External links == {{Commons category}} * {{Official website|https://www.cairographics.org}} * {{github|SimonSapin/cairocffi}} – CFFI-based Cairo bindings for Python * {{cite web | url = http://cairographics.org/manual/ | title = Cairo API reference manual}} * {{cite web | work = Linux.Ars | url = https://arstechnica.com/articles/columns/linux/linux-20050822.ars | title = Cairo here, there and everywhere | date = August 23, 2005 | publisher = [[Ars Technica]]}} * {{cite web | url = http://www.ibm.com/developerworks/linux/library/l-cairo/ | title = Cross-platform graphics with cairo| website = [[IBM]]}} * {{cite web | url = http://kore-nordmann.de/blog/comparision_of_php_image_libraries.html | title = Comparison of PHP image libraries}} * {{cite web | url = http://zetcode.com/gfx/cairo/ | title = The Cairo graphics tutorial}} {{Freedesktop.org}} [[Category:Cairo (graphics)| ]] [[Category:Free computer libraries]] [[Category:Free software programmed in C]] [[Category:Freedesktop.org]] [[Category:Freedesktop.org libraries]] [[Category:GNOME libraries]] [[Category:GTK]] [[Category:Software using the GNU Lesser General Public License]] [[Category:Software using the Mozilla Public License]]
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)
Pages transcluded onto the current version of this page
(
help
)
:
Template:Citation needed
(
edit
)
Template:Cite web
(
edit
)
Template:Cn
(
edit
)
Template:Commons category
(
edit
)
Template:Freedesktop.org
(
edit
)
Template:Github
(
edit
)
Template:Infobox
(
edit
)
Template:Infobox software
(
edit
)
Template:Main other
(
edit
)
Template:Official website
(
edit
)
Template:Portal
(
edit
)
Template:Reflist
(
edit
)
Template:Short description
(
edit
)
Template:Sister project
(
edit
)
Template:Template other
(
edit
)
Template:Tt
(
edit
)
Template:Use mdy dates
(
edit
)