Clever Geek Handbook
📜 ⬆️ ⬇️

Cairo

Cairo is an open source vector graphics software library . Includes a hardware-independent application programming interface for software developers. Cairo provides graphic primitives for rendering two-dimensional images through a variety of backends . Whenever possible, Cairo uses hardware acceleration .

Cairo
Type ofand
Developer, and
Written on
operating system, and
Latest version
Licenseand
Site

There is an official proposal for standardization in C ++ of the application programming interface for rendering two-dimensional graphics based on the Cairo library. [four]

Content

Software Architecture

Language bindings

Any library written in one programming language can be used in another if the so-called Binding this library to a new language. Cairo has a wide range of bindings to various programming languages: C ++ , C # and other languages ​​that meet the requirements of the CLI standard. There are also Cairo bindings for Delphi , Factor , Haskell , Lua , Perl , PHP , Python , Ruby , Scheme , Smalltalk and others. [five]

Tool Bindings

Since Cairo is just a rendering library, it can bring tangible benefits when integrated with graphical user interface building tools:

  • FLTK has full Cairo support (when compiling FLTK you must specify the option “--enable-cairo”).
  • GNUstep uses Cairo as the main backend on non-Windows systems. [6]
  • GTK + fully supports Cairo. Since 2005, with version 2.8, GTK + has been using Cairo to render most of the graphic controls. Starting with version 3.0 GTK + generally draws everything through Cairo.
  • Cairo is able to directly access the SDL library. [7]

Available Backends

Cairo operates on surface abstraction. The surface is what Cairo draws on. Behind this surface, various backends can hide that can transmit the result of Cairo to the X Window System , Xlib and XCB , Win32 GDI , OS X Quartz Compositor , BeOS , OS / 2 , OpenGL contexts (directly [8] and through glitz ), local image buffer, PNG files, PDF , PostScript , DirectFB and SVG files.

There are other backends that are a graphical application programming interface: OpenVG , [9] Qt , [10] Skia , [11] and Direct2D . [12]

Rendering Model

 
Cairo Rendering Model

The Cairo rendering model includes three steps:

  1. First, a mask is created, which consists of vector primitives or forms. For example, circles, squares, Bezier curves , TrueType fonts , etc.
  2. Then a so-called source must be defined, which can be a color, a color gradient , a bitmap, or a vector image. Further, from the painted parts of the source, cutting is performed by means of a given mask.
  3. Then the result is transferred to the surface, which the corresponding backend picks up.

This rendering model is fundamentally different from the SVG approach to image building.

Example

 
SVG image generated by the specified example

A rather complicated graphic version of the popular “ Hello world!” "Can be implemented using Cairo, for example, as follows:

  1 #include <cairo-svg.h> 
 2
 3 int main ( int argc , char ** argv ) {
 four
 5 cairo_t * cr ;
 6 cairo_surface_t * surface ;
 7 cairo_pattern_t * pattern ;
 8 int x , y ;
 9
 10 surface = ( cairo_surface_t * ) cairo_svg_surface_create ( "Cairo_example.svg" , 110.0 , 110.0 );
 11 cr = cairo_create ( surface );
 12
 13 / * Draw small squares in the background * /
 14 for ( x = 0 ; x < 10 ; x ++ )
 15 for ( y = 0 ; y < 10 ; y ++ )
 16 cairo_rectangle ( cr , x * 10.0 , y * 10.0 , 5 , 5 );
 17
 18 pattern = cairo_pattern_create_radial ( 50 , 50 , 5 , 50 , 50 , 50 );
 19 cairo_pattern_add_color_stop_rgb ( pattern , 0 , 0.75 , 0.15 , 0.99 );
 20 cairo_pattern_add_color_stop_rgb ( pattern , 0.9 , 1 , 1 , 1 );
 21
 22 cairo_set_source ( cr , pattern );
 23 cairo_fill ( cr );
 24
 25 / * Draw the foreground * /
 26 cairo_set_font_size ( cr , 15 );
 27 cairo_select_font_face ( cr , "Georgia" , CAIRO_FONT_SLANT_NORMAL , CAIRO_FONT_WEIGHT_BOLD );
 28 cairo_set_source_rgb ( cr , 0 , 0 , 0 );
 29th
 30 cairo_move_to ( cr , 10 , 25 );
 31 cairo_show_text ( cr , "Hello," );
 32
 33 cairo_move_to ( cr , 10 , 55 );
 34 cairo_show_text ( cr , "Wikipedia!" );
 35
 36 cairo_destroy ( cr );
 37 cairo_surface_destroy ( surface );
 38 return 0 ;
 39 }

Usage

Cairo is popular in the opensource community as it provides portability and quality rendering of two-dimensional images.

  • GTK + fully supports Cairo. Since 2005, with version 2.8, GTK + has been using Cairo to render most of the graphic controls. Starting with version 3.0 GTK + generally draws everything through Cairo.
  • The Mono project, [13] including Moonlight , [14] uses Cairo.
  • The Mozilla project uses Cairo in the Gecko browser engine [15] . In Firefox 52, they moved away from it in favor of Direct2D (Windows 10) and Skia (lower), but it is still supported if you switch to it through advanced settings. Starting with Firefox 66, support has been completely removed [16] .
  • The WebKit framework uses Cairo to render in GTK + and EFL ports. Cairo support has also been added for rendering SVG graphics and for the content of the <canvas> tag.
  • The Poppler library uses Cairo to render PDF documents. Cairo is used to build smoothed vector graphics and transparent objects.
  • Inkscape vector graphics editor uses Cairo.
  • MorphOS 2.5 operating system uses Cairo.
  • AmigaOS 4.1 supports the Cairo Shared Object Library (libcairo.so) in the default installation.
  • FontForge's font editor has been using Cairo by default since mid-October 2008.
  • The programming language R is able to output graphics in PDF , PostScript and SVG formats using Cairo.
  • Gnuplot 4.4 is used by Cairo to render to PDF and PNG . [17]
  • The PlayStation 3 web browser has been using Cairo since the system update version 4.10.
  • Synfig 0.64 now optionally supports image rendering through Cairo.
  • Graphite's computer system performance monitoring and visualization program is capable of rendering graphics through Cairo.

History

Keith Packard and Carl Worth founded the Cairo project for use in the X Window System . [18] At the beginning (at least until 2003) the project was called Xr or Xr / Xc . The name was changed in order to emphasize the idea of ​​portability of the library with the ability to access an arbitrary display server that is not tied only to the X Window System . [nineteen]

The name Cairo comes from the original name Xr , interpreted by the letters of the Greek alphabet χ and ρ. [20]

See also

  • Display PostScript
  • Skia graphics engine
  • Starling framework
  • Webgl

Notes

  1. ↑ The cairo Open Source Project on Open Hub: Languages ​​Page - 2006.
    <a href=" https://wikidata.org/wiki/Track:Q124688 "> </a> <a href=" https://wikidata.org/wiki/Track:P1972 "> </a>
  2. ↑ https://www.cairographics.org/news/cairo-1.17.2/
  3. ↑ 1 2 http://web.archive.org/web/20180224092509/https://www.cairographics.org/
  4. ↑ A Proposal to Add 2D Graphics Rendering and Display to C ++ Revision 2 (unspecified) . Open Standards (July 3, 2014). Date of appeal September 12, 2014.
  5. ↑ Cairo Language Bindings (Neopr.) . Date of appeal April 16, 2014.
  6. ↑ Fedor, Adam User Defaults Summary for GNUstep Backend (Neopr.) (September 29, 2011). Date of treatment November 3, 2014.
  7. ↑ Cairo - SDL (Neopr.) (February 17, 2009). Date of treatment November 3, 2014.
  8. ↑ Chris Wilson. New OpenGL backend merged (unopened) (July 22, 2009). Date of treatment February 12, 2010.
  9. ↑ Øyvind Kolås. Announcing OpenVG backend (unopened) (January 24, 2008). Date of treatment February 12, 2010.
  10. ↑ Vladimir Vukićević. Well Isn't That Qt (unopened) (May 6, 2008). Date of treatment February 12, 2010. Archived April 9, 2010.
  11. ↑ Chris Wilson. Cool Stuff (Neopr.) (August 31, 2009). Date of treatment February 12, 2010.
  12. ↑ Bas Schouten. Direct2D: Hardware Rendering a Browser (unopened) (November 22, 2009). Date of treatment February 12, 2010.
  13. ↑ Mono - Drawing (neopr.) . Date of treatment December 27, 2009.
  14. ↑ Moonlight Notes (unspecified) . Date of treatment December 27, 2009.
  15. ↑ Gecko 1.9 Roadmap (neopr.) . Date of treatment December 27, 2009.
  16. ↑ Remove cairo D2D backend (unopened) . Date of treatment January 9, 2019.
  17. ↑ Gnuplot version 4.4.0 announcement (unspecified) . Gnuplot homepage . Date of treatment February 22, 2011.
  18. ↑ Error in footnotes ? : Invalid <ref> ; no text for xrols2003 footnotes
  19. ↑ Mailing list thread about the Cairo name change (unopened) . Date of treatment June 8, 2009.
  20. ↑ Mailing list thread about the cairo name change (unopened) . Date of treatment December 2, 2006.

External links

  • cairographics.org - the official site of Cairo
  • GitHub Cairo Project - CFFI-based Cairo bindings for Python
  • Cairo API reference manual (unspecified) .
  • Cairo here, there and everywhere (neopr.) . Linux.Ars . Ars Technica .
  • Cross-platform graphics with cairo (neopr.) .
  • Comparison of PHP image libraries (neopr.) .
  • The Cairo graphics tutorial (neopr.) .
Source - https://ru.wikipedia.org/w/index.php?title=Cairo&oldid=97365756


More articles:

  • BroadVoice
  • Sky Over Berlin 2
  • Kortua, Heraclius
  • Xi Jinping
  • Ruf Metz
  • Aprelevka
  • Black Belt (Region)
  • Verkhnedneprovsky County
  • Vishnevskoe (lake)
  • Branch and Boundary Method

All articles

Clever Geek | 2019