项目作者: sammycage

项目描述 :
Tiny 2D vector graphics library in C
高级语言: C
项目地址: git://github.com/sammycage/plutovg.git
创建时间: 2020-11-07T17:14:29Z
项目社区:https://github.com/sammycage/plutovg

开源协议:MIT License

下载


Releases
License
Build Status
CodeFactor

PlutoVG

PlutoVG is a standalone 2D vector graphics library in C.

Features

  • Path Filling, Stroking and Dashing
  • Solid, Gradient and Texture Paints
  • Fonts and Texts
  • Clipping and Compositing
  • Transformations
  • Images

Example

  1. #include <plutovg.h>
  2. int main(void)
  3. {
  4. const int width = 150;
  5. const int height = 150;
  6. const float center_x = width / 2.f;
  7. const float center_y = height / 2.f;
  8. const float face_radius = 70;
  9. const float mouth_radius = 50;
  10. const float eye_radius = 10;
  11. const float eye_offset_x = 25;
  12. const float eye_offset_y = 20;
  13. const float eye_x = center_x - eye_offset_x;
  14. const float eye_y = center_y - eye_offset_y;
  15. plutovg_surface_t* surface = plutovg_surface_create(width, height);
  16. plutovg_canvas_t* canvas = plutovg_canvas_create(surface);
  17. plutovg_canvas_save(canvas);
  18. plutovg_canvas_arc(canvas, center_x, center_y, face_radius, 0, PLUTOVG_TWO_PI, 0);
  19. plutovg_canvas_set_rgb(canvas, 1, 1, 0);
  20. plutovg_canvas_fill_preserve(canvas);
  21. plutovg_canvas_set_rgb(canvas, 0, 0, 0);
  22. plutovg_canvas_set_line_width(canvas, 5);
  23. plutovg_canvas_stroke(canvas);
  24. plutovg_canvas_restore(canvas);
  25. plutovg_canvas_save(canvas);
  26. plutovg_canvas_arc(canvas, eye_x, eye_y, eye_radius, 0, PLUTOVG_TWO_PI, 0);
  27. plutovg_canvas_arc(canvas, center_x + eye_offset_x, eye_y, eye_radius, 0, PLUTOVG_TWO_PI, 0);
  28. plutovg_canvas_set_rgb(canvas, 0, 0, 0);
  29. plutovg_canvas_fill(canvas);
  30. plutovg_canvas_restore(canvas);
  31. plutovg_canvas_save(canvas);
  32. plutovg_canvas_arc(canvas, center_x, center_y, mouth_radius, 0, PLUTOVG_PI, 0);
  33. plutovg_canvas_set_rgb(canvas, 0, 0, 0);
  34. plutovg_canvas_set_line_width(canvas, 5);
  35. plutovg_canvas_stroke(canvas);
  36. plutovg_canvas_restore(canvas);
  37. plutovg_surface_write_to_png(surface, "smiley.png");
  38. plutovg_canvas_destroy(canvas);
  39. plutovg_surface_destroy(surface);
  40. return 0;
  41. }

output:

smiley.png

Installation

Follow the steps below to install PlutoVG using either Meson or CMake.

Using Meson

  1. git clone https://github.com/sammycage/plutovg.git
  2. cd plutovg
  3. meson setup build
  4. meson compile -C build
  5. meson install -C build

Using CMake

  1. git clone https://github.com/sammycage/plutovg.git
  2. cd plutovg
  3. cmake -B build .
  4. cmake --build build
  5. cmake --install build

Projects using PlutoVG