Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/alexdemb/cairodart
Cairo bindings for Dart.
https://github.com/alexdemb/cairodart
Last synced: 20 days ago
JSON representation
Cairo bindings for Dart.
- Host: GitHub
- URL: https://github.com/alexdemb/cairodart
- Owner: alexdemb
- License: other
- Created: 2015-01-26T06:41:08.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2016-08-30T14:18:11.000Z (about 8 years ago)
- Last Synced: 2024-04-10T02:08:44.335Z (7 months ago)
- Language: Dart
- Size: 369 KB
- Stars: 7
- Watchers: 1
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
- awesome-dart - cairodart - Cairo bindings for Dart.[<img src="https://travis-ci.org/alexander-dembinsky/cairodart.svg?branch=master">](https://travis-ci.org/alexander-dembinsky/cairodart) (Libraries / Graphics)
README
# CairoDart
The goal of this project is to provide Dart language bindings for Cairo 2D graphics library (http://cairographics.org/).
Current binding supports Cairo v1.12.### Building
First of all you should install Cairo library on your machine.
For installation details see (http://cairographics.org/download/)CairoDart provides API around native library, so the "glue" code should be compiled before start working with CairoDart.
QMake is used for building native part of cairodart, so it should be installed prior to building.
Also environment variable DART_SDK should be set to location of installed Dart SDK.
```
$ cd native
$ qmake
$ make
```### Starting unit tests
First start
```
$ pub get
```from the root of the project tree.
To start unit tests run following command:
```
$ dart test/all_test.dart
```### Examples
You can find examples in *example* directory of the project.
Here is an example of CairoDart script that generates several 2D shapes:
```dart
library cairodart.example;import 'dart:io';
import 'dart:math';import 'package:cairodart/cairodart.dart';
main() {
Directory dir = Directory.systemTemp.createTempSync('cairodart');var filePath = 'example${Platform.pathSeparator}filled_shapes.png';
File file = new File(filePath);
file.createSync();Surface surface = new ImageSurface(Format.ARGB32, 400, 200);
Context ctx = new Context(surface);ctx.lineWidth = 1.0;
// Red circle
ctx..translate(150, 100)
..setSourceRgb(0, 0, 0)
..arc(0, 0, 50, 0, 2 * PI)
..strokePreserve()
..setSourceRgba(1, 0, 0, 0.7)
..fill();// Green circle
ctx..translate(50, 0)
..setSourceRgb(0, 0, 0)
..arc(0, 0, 50, 0, 2 * PI)
..strokePreserve()
..setSourceRgba(0, 1, 0, 0.7)
..fill();// Blue circle
ctx..translate(-25, 50)
..setSourceRgb(0, 0, 0)
..arc(0, 0, 50, 0, 2 * PI)
..strokePreserve()
..setSourceRgba(0, 0, 1, 0.7)
..fill();// Save to png file
surface.writeTo(filePath);}
```Now a little example with transparency:
```dart
library cairodart.example;import 'dart:io';
import 'package:cairodart/cairodart.dart';
main() {
Directory dir = Directory.systemTemp.createTempSync('cairodart');var filePath = 'example/${Platform.pathSeparator}transparency.png';
File file = new File(filePath);
file.createSync();Surface surface = new ImageSurface(Format.ARGB32, 350, 350);
Context ctx = new Context(surface);ctx.translate(10, 175);
for (int i = 0; i < 10; i++) {
ctx.translate(25, 0);
var rect = new Rectangle(0, -10, 20, 20);
ctx.rectangle(rect);
ctx.setSourceRgba(0, 1, 0, 0.1 * i);
ctx.fill();
}// Save to png file
surface.writeTo(filePath);
}
```### Not implemented features
The first version of CairoDart provides binaries for Linux only.
Binries for Windows and Mac OS will be available in future versions.The first version of CairoDart does not provide bindings for the following features:
- Xlib Surfaces
- Win32 Surfaces
- XCB Surfaces
- Quartz Surfaces
- XLib-XRender Backend
- Quartz (CGFont) Fonts
- Win32 Fonts
- FreeType FontsAll these features are expected to be implemented in future versions.
### Bugs
If you find a bug please register new issue with bug description, code example and version of library.
But before you do this please check if this bug is already registered.### Contribution
Help is much appreciated!
Before submitting pull request please ensure that you changes does not brake old unit tests and covered by new.