Generated by GPT-5-mini| Cairo (graphics) | |
|---|---|
| Name | Cairo |
| Developer | Red Hat, X.Org Foundation, independent contributors |
| Released | 2002 |
| Programming language | C (programming language) |
| Operating system | Linux, Microsoft Windows, macOS, Android (operating system), iOS |
| License | LGPL / MIT License |
Cairo (graphics) Cairo is a 2D graphics library for producing vector graphics with consistent output across X Window System, Microsoft Windows, macOS, Android (operating system) and PDF. It provides operators for drawing and compositing that aim for high-quality rendering for applications such as GNOME, Mozilla Firefox, WebKit, LibreOffice and GTK+. Cairo interposes between applications and backends like XRender, Quartz (graphics layer), and OpenGL to produce device-independent images suitable for screen, printer, and file formats including PDF and SVG.
Cairo implements a 2D drawing model influenced by PostScript, PDF, and SVG while exposing an API designed for integration with toolkits such as GTK+, Qt (software), and Pango. It supports path construction, transformation matrices, patterns, and compositing operators derived from Porter–Duff compositing. The library aims to provide consistent rendering across diverse backends including XFree86, Wayland, and Win32 GDI by abstracting device specifics and offering alternatives like ImageMagick integration and output to file formats used by Adobe Systems.
Cairo's architecture separates front-end drawing APIs from multiple backends: image buffers, vector file outputs, and platform-specific compositing layers. The design uses surface and context abstractions similar to concepts from PostScript and PDF, with surfaces implemented for PNG-style image buffers, PDF generation, and SVG export. A core rasterizer converts paths into pixel spans using algorithms influenced by Anti-aliasing research and implementations in projects like XRender and Quartz 2D, while pattern and gradient primitives mirror those defined in SVG specifications. Cairo's modular backend approach facilitates integration with window systems such as X.Org, Wayland (display server), and Microsoft Windows through dedicated backend modules.
Cairo exposes a drawing model supporting paths, subpaths, stroking, filling, and even advanced features like masking and clipping, all built around a 3x3 transformation matrix pipeline akin to PostScript and PDF graphics state. It implements a painting model with solid colors, linear and radial gradients, and surface patterns comparable to SVG paint servers. Compositing follows the Porter–Duff compositing rules and includes support for alpha channels compatible with PNG and PDF transparency semantics. Cairo also supports text drawing integration with libraries such as Pango and font systems like FreeType and platform services including Core Text on macOS and Uniscribe on Microsoft Windows.
Cairo's core is written in C (programming language) with stable C API and C++ compatibility; bindings exist for many languages and frameworks, including Python (programming language), Perl, Ruby (programming language), Java (programming language), C# (programming language), Haskell (programming language), Go (programming language), and Rust (programming language). Integrations are present in GUI toolkits and applications like GTK+, Qt (software), Mozilla Firefox, Chromium, and LibreOffice. The API includes surface creation, context management, state save/restore, path construction, and backend-specific extensions used by projects such as Poppler for PDF rendering and librsvg for SVG rasterization.
Cairo uses multiple backends to balance quality and performance: a software rasterizer for portable pixel output, an accelerated backend leveraging OpenGL and GLX for GPU compositing, and native backends using XRender and Win32 GDI for reduced copy overhead. Performance tuning has involved integration with Pixman for optimized pixel manipulation and scanline operations, and experiments with hardware acceleration through Mesa (computer graphics) and ANGLE (Almost Native Graphics Layer Engine). Rendering pipeline optimizations address stroking and fill rasterization, glyph caching for text performance with FreeType and HarfBuzz, and strategies for minimizing round-trip operations on window systems like Wayland (display server).
Cairo began as an effort in the early 2000s with contributors from Red Hat, X.Org Foundation, and independent developers aiming to provide a modern 2D API for GTK+ and the wider free software ecosystem. The project absorbed ideas from XRender, Cairo's predecessor libraries, and vector graphic formats such as SVG and PDF. Over time, Cairo became a dependency for major projects including GNOME, Firefox, and LibreOffice, and evolved through contributions hosted by communities connected to Freedesktop.org and GitLab. Its licensing under permissive MIT License and LGPL variants aided adoption by both open source and commercial entities like Adobe Systems and companies embedding Cairo in rendering stacks.
Cairo is used in desktop environments such as GNOME and KDE (K Desktop Environment) through toolkit backends, in web browsers like Mozilla Firefox and Chromium for 2D rendering fallbacks, and in document toolchains producing PDF output via libraries like Poppler and Ghostscript. Applications in graphics editing, charting, and mapping use Cairo through bindings in Inkscape, GIMP, and QGIS-related plugins. Its role in embedded devices appears in Android (operating system), iOS, and custom appliances where consistent vector output and export to SVG or PDF are required by software vendors and integrators.
Category:Graphics libraries