Cairo (Vector graphic)

a 2D graphics library with support for multiple output devices … - Home / github / wikipedia

Cairo is in a maintenance-only mode. - HN (2024)

When it comes to 2D rendering libraries there is in general not too many options if you want to target CPU or both CPU+GPU. Targeting GPU-only is bad for users that run on a hardware where GPU doesn’t perform well or is not available at all due to driver issues or just not present (like servers). - HN (2024)

  • Cairo (CPU only)
  • Skia (CPU + GPU) - choosen by ladybug browser
    • Tiny Skia (CPU only, not focused on performance)
  • GPU only libs (there is many in C++ and Rust)
  • Qt’s QPainter (CPU only, GPU without anti-aliasing / deprecated)

The cairo API provides operations similar to the drawing operators of PostScript and PDF. Operations in cairo including stroking and filling cubic Bézier splines, transforming and compositing translucent images, and antialiased text rendering. All drawing operations can be transformed by any affine transformation (scale, rotation, shear, etc.)

Used by

see also

Tutorial

Example

Text

Fortunately, the pango library exists and does do sophisticated text layout, shaping, etc. and integrates very nicely with cairo. We heartily recommend that “real” applications wanting to display text with cairo use pango to do it.

SVG

OpenGL / Vulkan

  • vkvg - an open-source 2D graphics library written in C using Vulkan as backend. The API follows the same pattern as Cairo, but new functions and original drawing mechanics may be added.
  • Using cairo with OpenGL - advice is to render to a glTexture and display it after.

Perf

  • Cairo CPU : 1.00
  • Cairo GL : 0.25
  • Cairo Xlib: 1.60
  • Qt Raster : 0.98
  • Qt GL : 0.66
  • Qt Native : 0.26
  • Skia GL : 1.68
  • FastUIDraw: 9.20

Build

Use meson now.

Alternatives & Comparison

The proposed c++ 2d graphics standard is based on Cairo. - HN

Written on March 5, 2021, Last update on October 6, 2024
vector-graphic image-lib 2d svg