Cairo (Vector graphic)

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

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.)

see also

  • HN (2024) - Cairo is in a maintenance-only mode. 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).
    • Cairo (CPU only)
    • Skia (CPU + GPU) - 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)
  • cairomm - A C++ API for cairo. / doc
  • AskGTK: Cairo, Skia and Gtk

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

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.

Used by

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

Alternatives & Comparison

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

Written on March 5, 2021, Last update on April 8, 2023
c++ 2d vector graphic lib svg