Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikipediaThe Free Encyclopedia
Search

cairo (graphics)

From Wikipedia, the free encyclopedia
Vector graphics-based software library

Original author(s)Keith Packard, Carl Worth[1]
Developer(s)Carl Worth,Behdad Esfahbod
Initial releaseBefore 2003; 22 years ago (2003)[2]
Stable release
1.18.4 (March 8, 2025; 2 months ago (2025-03-08)[3]) [±]
Repositorygitlab.freedesktop.org/cairo/cairo
Written inC
TypeGraphics library
LicenseGNU Lesser General Public License version 2.1 (only) orMozilla Public License 1.1
Websitewww.cairographics.org

Cairo (stylized ascairo) is anopen-sourcegraphics library that provides avector graphics-based, device-independentAPI forsoftware developers. It provides primitives fortwo-dimensional drawing across a number of differentbackends. Cairo useshardware acceleration[4] when available.

Software architecture

[edit]

Language bindings

[edit]

A library written in one programming language may be used in another language ifbindings are written; Cairo has a range of bindings for various languages includingC++,C# and otherCLI languages,Delphi,Eiffel,Fortran,Factor,Harbour,Haskell,Julia,Lua,Perl,PHP,Python,Ruby,Rust,Scheme,Smalltalk and several others likeGambas (Visual Basic like).[5]

Toolkit bindings

[edit]

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).
  • GTK began in 2005, with version 2.8, to use Cairo to render the majority of itsgraphical control elements, and since version 3.0 allrendering is done through Cairo.
  • The Cairo development team maintains up-to-date instructions for rendering surfaces toSDL.[6]

Available back-ends

[edit]

Cairo supports output (includingrasterisation) to a number of differentback-ends, known as "surfaces" in its code. Back-ends support includes output to theX Window System, via bothXlib andXCB,Win32 GDI,OS X Quartz Compositor, theBeOS API,OS/2,OpenGL contexts (directly[7] and via glitz), local image buffers,PNG files,PDF,PostScript,DirectFB andSVG files.

There are other back-ends in development targeting the graphics APIsOpenVG,[8]Qt,[9]Skia,[10] and Microsoft'sDirect2D.[11] The BeOS, OS/2, DirectFB and OpenGL backends were dropped in 2022.[12][13]

Drawing model

[edit]
The Cairo drawing model

The Cairo drawing model relies on a three-layer model.

Any drawing process takes place in three steps:

  1. First a mask is created, which includes one or more vector primitives or forms, i.e., circles, squares,TrueType fonts,Bézier curves, etc.
  2. 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.
  3. 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 fromScalable Vector Graphics (SVG), which specifies the color of shapes withCascading Style Sheets (CSS) rules.[citation needed] 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 astyle attribute. That said, the models are not incompatible; many SVG renderers use Cairo for heavy lifting.[14]

Example

[edit]

Quite complex "Hello world" graphics can be drawn with the help of Cairo with only a few lines ofsource code:

SVG picture generated by this example
#include<cairo-svg.h>#include<stdio.h>intmain(intargc,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(intx=0;x<10;++x)for(inty=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

[edit]

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 itsgraphical control elements.[15] Since GTK version 3, all the rendering is done using Cairo.
    • A program calledgtk-vector-screenshot found inDebian allows for taking vector (SVG, PDF, or PostScript)screenshots of GTK 3 applications.[16]
  • TheMono Project,[17] includingMoonlight,[18] has been using Cairo since very early in conception to power the back-ends of itsGDI+ (libgdiplus) and System.Drawingnamespaces.
  • TheMozilla project has made use of Cairo in itsGecko layout engine, used for rendering the graphical output of Mozilla products. Gecko 1.8, the layout engine for Mozilla Firefox 2.0 andSeaMonkey 1.0, used Cairo to render SVG and<canvas> content. Gecko 1.9,[19] the release of Gecko that serves as the basis ofFirefox 3, uses Cairo as the graphics back-end for rendering both web page content and theuser interface (or "chrome").
  • TheWebKit framework uses Cairo for all rendering in theGTK andEFL ports. Support has also been added for SVG and <canvas> content using Cairo.[citation needed]
  • ThePoppler library uses Cairo to render PDF documents. Cairo enables the drawing of antialiased vector graphics and transparent objects.[citation needed]
  • The vector graphics applicationInkscape uses the Cairo library for its outline mode display, as well as forPDF andPostScript export since release 0.46.[20]
  • The original version ofManim referred to as ManimCairo, a mathematical animation engine used in the animations of 3Blue1Brown's YouTube Videos. Manim has since moved to usingOpenGL. This version is referred to as ManimGL.[21]
  • MorphOS 2.5 features a shared library implementation of Cairo, which was available as stand-alone release for earlier MorphOS versions.[citation needed]
  • AmigaOS 4.1 supports a shared object library of Cairo (libcairo.so) in its default installation.[citation needed]
  • FontForge enabled Cairo by default for rendering in mid-October 2008.[citation needed]
  • R can output plots inPDF,PostScript andSVG formats using Cairo if available.[citation needed]
  • Gnuplot 4.4 now uses Cairo for renderingPDF andPNG output.[22]
  • Internet Browser for PlayStation 3 uses Cairo since system software update 4.10.[citation needed]
  • Synfig 0.64 now supports optional Cairo rendering.[citation needed]
  • On-demand graphing of time series data inGraphite.[citation needed]
  • The Konfabulator/Yahoo widget engine uses Cairo for identical output to both Win32 and Quartz onMac OS/X.[citation needed]
  • SolveSpace, free and open source 2D and3D CAD software.[citation needed]

History

[edit]

Keith Packard and Carl Worth founded the Cairo project for use in theX Window System.[2] It was originally (until at least 2003) calledXr orXr/Xc. The name was changed to emphasize the idea of a cross-platform library to accessdisplay server, not tied to theX Window System.[23]The nameCairo derives from the original nameXr, interpreted as the Greek letterschi andrho.[24]

Complex text layout

[edit]

Cairo handles Latin and CJK based fonts, but does not directly supportcomplex text layout fonts, which require shaping the glyphs. The Cairo developers recommend usingPango, which provides complex text layout and can integrate with Cairo.[25]

See also

[edit]

References

[edit]
  1. ^"Carl's boring web pages".cworth.org. 2013. RetrievedJuly 11, 2014.
  2. ^ab"Xr: Cross-device Rendering for Vector Graphics". RetrievedJune 8, 2009.
  3. ^"cairo-1.18.4".www.cairographics.org. RetrievedMarch 12, 2025.
  4. ^"Cairo homepage". RetrievedOctober 30, 2010.
  5. ^"Cairo Language Bindings". RetrievedApril 16, 2014.
  6. ^"SDL".Cairo. February 17, 2009. RetrievedNovember 3, 2014.
  7. ^Chris Wilson (July 22, 2009)."New OpenGL backend merged". RetrievedFebruary 12, 2010.
  8. ^Øyvind Kolås (January 24, 2008)."Announcing OpenVG backend". RetrievedFebruary 12, 2010.
  9. ^Vladimir Vukićević (May 6, 2008)."Well Isn't That Qt". Archived fromthe original on April 9, 2010. RetrievedFebruary 12, 2010.
  10. ^Chris Wilson (August 31, 2009)."Cool Stuff". RetrievedFebruary 12, 2010.
  11. ^Bas Schouten (November 22, 2009)."Direct2D: Hardware Rendering a Browser". RetrievedFebruary 12, 2010.
  12. ^Larabel, Michael (February 27, 2022)."Cairo graphics library drops many old backends". Phoronix. RetrievedJune 5, 2022.
  13. ^Larabel, Michael (January 29, 2023)."Cairo Graphics Library Drops OpenGL Support After A Decade Of Inactivity".Phoronix. RetrievedFebruary 7, 2025.
  14. ^"GNOME/librsvg".GitHub.
  15. ^"GTK+ to Use Cairo Vector Engine". February 5, 2005. RetrievedDecember 27, 2009.
  16. ^"Details of package gtk-vector-screenshot in stretch".Debian.GitHub
  17. ^"Mono - Drawing". RetrievedDecember 27, 2009.
  18. ^"Moonlight Notes". RetrievedDecember 27, 2009.
  19. ^"Gecko 1.9 Roadmap". RetrievedDecember 27, 2009.
  20. ^"ReleaseNotes046".Inkscape Wiki. RetrievedMarch 31, 2008.
  21. ^"ManimCE tutorial by TheoremOfBeethoven — ManimCE tutorial by TB documentation".zavden.github.io. RetrievedJanuary 29, 2023.
  22. ^"Gnuplot version 4.4.0 announcement".Gnuplot homepage. Archived fromthe original on May 14, 2011. RetrievedFebruary 22, 2011.
  23. ^"Mailing list thread about the Cairo name change". July 15, 2003. RetrievedJune 8, 2009.
  24. ^"Mailing list thread about the Cairo name change". July 12, 2003. RetrievedDecember 2, 2006.
  25. ^"How do I use Pango instead of Cairo's "toy" text API?". RetrievedMarch 20, 2024.

External links

[edit]
Wikimedia Commons has media related toCairo (graphics).
OS components
Sound
Graphics
Other
Libraries
Frameworks
Meetings
Retrieved from "https://en.wikipedia.org/w/index.php?title=Cairo_(graphics)&oldid=1288098858"
Categories:
Hidden categories:

[8]ページ先頭

©2009-2025 Movatter.jp