Go binding for the cairo graphics library

Overview

go-cairo

Go binding for the cairo graphics library

Based on Dethe Elza's version https://bitbucket.org/dethe/gocairo but significantly extended and updated.

Go specific extensions:

  • NewSurfaceFromImage(image.Image)
  • Surface.GetData() []byte
  • Surface.SetData([]byte)
  • Surface.GetImage() image.Image
  • Surface.SetImage(image.Image)

go-cairo also sports a sub package extimage with image.Image/draw.Image implementations for 32 bit ARGB and 24 bit RGB color models.

Overview:

Missing features

  • TextCluster
  • FontExtents
  • FontFace
  • FontOptions
  • ScaledFont
  • Glyph

Installation:

Install cairo:

For Debian and Debian derivatives including Ubuntu:

sudo apt-get install libcairo2-dev

For Fedora:

sudo yum install cairo-devel

For openSUSE:

zypper install cairo-devel

For MacOS you may get errors finding cairo-pdf.h. To fix this run:

xcode-select --install

Install go-cairo and run go-cairo-example:

go get github.com/ungerik/go-cairo
go install github.com/ungerik/go-cairo/go-cairo-example && go-cairo-example

Copyrights: See LICENSE file

Bitdeli Badge

Comments
  • Need get_current_point

    Need get_current_point

    Cairo has a get_current_point method that is not implemented here. I need it to implement a QuadraticCurveTo method, which does not exist in Cairo. It's trivial to create, but you need to factor in that initial point you are drawing from. I've done it in cairo-rs and would like to do the same here.

    Was there a reason you chose not to implement that method?

    opened by bit101 5
  • Unable to build project

    Unable to build project

    System specs:

    • Centos6
    • Go 1.4.2
    • cairo.x86_64 - 1.8.8-6.el6_6
    • cairo-devel.x86_64 - 1.8.8-6.el6_6

    when I run go-cairo-example I get the following output:

    could not determine kind of name for C.cairo_pdf_version_t
    could not determine kind of name for C.cairo_pdf_version_to_string
    
    opened by ARolek 5
  • Add support for linear and radial gradients

    Add support for linear and radial gradients

    • added CreateLinearGradient
    • added CreateRadialGradient
    • added AddColorStopRGB
    • added AddColorStopRGBA
    • removed some returns that the linter was complaining about as unreachable code.

    Sample Code:

    surface := cairo.NewSurface(cairo.FORMAT_ARGB32, 400, 200)
    pattern := cairo.CreateLinearGradient(0, 0, 200, 200)
    pattern.AddColorStopRGB(0, 1, 1, 1)
    pattern.AddColorStopRGB(1, 0, 0, 0)
    surface.SetSource(pattern)
    surface.Rectangle(0, 0, 200, 200)
    surface.Fill()
    
    pattern = cairo.CreateRadialGradient(300, 100, 0, 300, 100, 100)
    pattern.AddColorStopRGB(0, 1, 0, 0)
    pattern.AddColorStopRGB(1, 0, 0, 1)
    surface.SetSource(pattern)
    surface.Rectangle(200, 0, 200, 200)
    surface.Fill()
    
    opened by bit101 4
  • NewSurfaceFromImage panics every time

    NewSurfaceFromImage panics every time

    Hi,

    the last call to panic in surface.go seems to be misplaced, resulting in a runtime panic everytime cairo.NewSurfaceFromImage is called. This patch fixes the issue:

    diff --git a/surface.go b/surface.go
    index 3409279..9e1d655 100644
    --- a/surface.go
    +++ b/surface.go
    @@ -724,6 +724,8 @@ func (self *Surface) SetImage(img image.Image) {
    
        case FORMAT_INVALID:
            panic("Invalid surface format")
    +
    +   default:
    +       panic("Unknown surface format")
        }
    -   panic("Unknown surface format")
     }
    
    opened by farhaven 3
  • NewSurfaceFromC issue

    NewSurfaceFromC issue

    I am trying to use https://github.com/cheggaaa/go-poppler to extract images from pdf, but I am getting this during build: golang/src/github.com/cheggaaa/go-poppler/image.go:24: cannot use ci (type *C.struct__cairo_surface) as type *cairo.C.struct__cairo_surface in argument to cairo.NewSurfaceFromC golang/src/github.com/cheggaaa/go-poppler/image.go:24: cannot use ctx (type *C.struct__cairo) as type *cairo.C.struct__cairo in argument to cairo.NewSurfaceFromC

    Do you have and idea how it can be fixed? I also filled issue there https://github.com/cheggaaa/go-poppler/issues/1 .

    opened by gen2brain 2
  • context should be destroyed in surface.Destroy

    context should be destroyed in surface.Destroy

    Without this change surface reference count remains > 0.

    func (self *Surface) Destroy() {
    +        C.cairo_destroy(self.context)
            C.cairo_surface_destroy(self.surface)
    }
    
    opened by thepigs 1
  • Add support for cairo_surface_write_to_png_stream

    Add support for cairo_surface_write_to_png_stream

    This change adds support for cairo_surface_write_to_png_stream, which allows a Surface to be written as a PNG to a byte buffer. Previously the only option for converting a Surface to a PNG was to write it to a file.

    opened by charlievieth 1
  • [surface.go] fix GetImage() for FORMAT_ARGB32 and FORMAT_RGB24

    [surface.go] fix GetImage() for FORMAT_ARGB32 and FORMAT_RGB24

    In function: GetImage()

    The colors and alpha mask were reversed in FORMAT_ARGB32

    FORMAT_RGB24 is actually 32 bit with 8 bits unused (and also in reverse order, just like FORMAT_ARGB32)

    opened by pebbe 1
  • Support for cairo_image_surface_create_from_data

    Support for cairo_image_surface_create_from_data

    Pass in an unsafe.Pointer to the surface data. This allows for surfaces to be created e.g. from an SDL surface (would address #3):

    package main
    
    import (
    	"time"
    	"github.com/veandco/go-sdl2/sdl"
    	"github.com/ungerik/go-cairo"
    )
    
    func main() {
    	sdl.Init(sdl.INIT_EVERYTHING);
    	defer sdl.Quit()
    
    	window, _ := sdl.CreateWindow("test", sdl.WINDOWPOS_UNDEFINED, sdl.WINDOWPOS_UNDEFINED,
    		800, 600, sdl.WINDOW_SHOWN)
    	sdlSurface, _ := window.GetSurface()
    	sdlSurface.FillRect(nil, 0)
    
    	cairoSurface := cairo.NewSurfaceFromData(sdlSurface.Data(),
    		cairo.FORMAT_ARGB32, int(sdlSurface.W), int(sdlSurface.H),
    		int(sdlSurface.Pitch))
    	cairoSurface.SelectFontFace("serif", cairo.FONT_SLANT_NORMAL, cairo.FONT_WEIGHT_BOLD)
    	cairoSurface.SetFontSize(32.0)
    	cairoSurface.SetSourceRGB(0.0, 0.0, 1.0)
    	cairoSurface.MoveTo(10.0, 50.0)
    	cairoSurface.ShowText("Hello World")
    	cairoSurface.Finish()
    
    	window.UpdateSurface()
    
    	time.Sleep(5 * time.Second)
    }
    
    opened by usedbytes 0
  • add GetCurrentPoint and HasCurrentPoint

    add GetCurrentPoint and HasCurrentPoint

    This adds hooks to C.cairo_get_current_point and C.cairo_has_current_point. These are vital for creating certain paths that are calculated from the current point, such as QuadraticCurveTo, which is not natively included in cairo.

    opened by bit101 0
  • Fix example

    Fix example

    The example/draw.go has two problems. The first, as outlined in another pull request, is the use of incorrect constants. The second problem is that it attempts to finish a surface before writing it out to a PNG. This is an invalid sequence of operations.

    This patch fixes both of those issues.

    opened by gkelly 0
  • build failing while cross compilation.

    build failing while cross compilation.

    i am building my project using below cmd. CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o handlerBuild cmd/handler/main.go Error generated: imports github.com/ungerik/go-cairo: build constraints exclude all Go files in /home/oem/go/pkg/mod/github.com/ungerik/[email protected] can someone explain me, what is happening over here ?

    my system details on which i am try to build.

    GO111MODULE="auto"
    GOARCH="amd64"
    GOBIN="/home/oem/go/bin"
    GOCACHE="/home/oem/.cache/go-build"
    GOENV="/home/oem/.config/go/env"
    GOEXE=""
    GOEXPERIMENT=""
    GOFLAGS=""
    GOHOSTARCH="amd64"
    GOHOSTOS="linux"
    GOINSECURE=""
    GOMODCACHE="/home/oem/go/pkg/mod"
    GONOPROXY=""
    GONOSUMDB=""
    GOOS="linux"
    GOPATH="/home/oem/go"
    GOPRIVATE=""
    GOPROXY="https://proxy.golang.org,direct"
    GOROOT="/usr/local/go"
    GOSUMDB="sum.golang.org"
    GOTMPDIR=""
    GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
    GOVCS=""
    GOVERSION="go1.19.3"
    GCCGO="gccgo"
    GOAMD64="v1"
    AR="ar"
    CC="gcc"
    CXX="g++"
    CGO_ENABLED="1"
    GOMOD="/home/oem/go/src/file-core/go.mod"
    GOWORK=""
    CGO_CFLAGS="-g -O2"
    CGO_CPPFLAGS=""
    CGO_CXXFLAGS="-g -O2"
    CGO_FFLAGS="-g -O2"
    CGO_LDFLAGS="-g -O2"
    PKG_CONFIG="pkg-config"
    GOGCCFLAGS="-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build2645311516=/tmp/go-build -gno-record-gcc-switches"
    
    opened by patabhu 0
Owner
Erik Unger
CTO & Co-Founder DOMONDA GmbH, Software & Aerospace Enthusiast
Erik Unger
Cairo in Go: vector to SVG, PDF, EPS, raster, HTML Canvas, etc.

Canvas is a common vector drawing target that can output SVG, PDF, EPS, raster images (PNG, JPG, GIF, ...), HTML Canvas through WASM, and OpenGL. It h

Taco de Wolff 1.2k Dec 25, 2022
This is old and unmaintained code, ignore it. starfish is a simple, SDL based, 2D graphics and user input library for Go. If you intend to work on it, please fork from the 'devel' branch, not 'master'. Current release: 0.12.0

What is starfish? What starfish is: starfish is a simple 2D graphics and user input library for Go built on SDL. What starfish is not: While it is bui

Gary Talent 12 Jun 4, 2019
A Grid based 2D Graphics library

gridder Built on top of Go Graphics github.com/fogleman/gg with the idea to simplify visualizing Grids using 2D Graphics. Dependencies gg github.com/f

Raed Shomali 59 Dec 1, 2022
Go Graphics - 2D rendering in Go with a simple API.

Go Graphics gg is a library for rendering 2D graphics in pure Go. Installation go get -u github.com/fogleman/gg Alternatively, you may use gopkg.in t

Michael Fogleman 3.7k Dec 29, 2022
a tool to output images as RGB ANSI graphics on the terminal

imgcat Tool to output images in the terminal. Built with bubbletea install homebrew brew install trashhalo/homebrew-brews/imgcat prebuilt packages Pr

Stephen Solka 469 Dec 28, 2022
Simple tool for changing graphics in dbd

Config changer for Dead By Deaylight For now only for epic store version And if only installed under C:\ further updates will include support for vers

null 0 May 3, 2022
A Go skia binding based on skia C library through cgo

go-skia is a Go skia binding based on skia C library through cgo. Note: the project is still in early stage, and it only supports Linux-amd64 now. The

Go101 23 Nov 7, 2022
Go OpenCL (GOCL) Binding

gocl Go OpenCL (GOCL) Binding (http://www.gocl.org) Library documentation: http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/ http://www.khron

Rain Liu 85 Jan 25, 2022
OpenGL binding generator for Go

GoGL GoGL is an OpenGL binding generator for Go. No external dependencies like GLEW are needed. Install the OpenGL bindings For example, OpenGL 2.1 bi

Christoph Schunk 139 Dec 25, 2022
Go binding to ImageMagick's MagickWand C API

Go Imagick Go Imagick is a Go bind to ImageMagick's MagickWand C API. We support two compatibility branches: master (tag v2.x.x): 6.9.1-7 <= ImageMagi

Go Graphics community 1.5k Jan 6, 2023
geoserver is a Go library for manipulating a GeoServer instance via the GeoServer REST API.

Geoserver geoserver Is a Go Package For Manipulating a GeoServer Instance via the GeoServer REST API. How to install: go get -v gopkg.in/hishamkaram/g

Hisham waleed karam 78 Dec 22, 2022
General purpose library for reading, writing and working with OpenStreetMap data

osm This package is a general purpose library for reading, writing and working with OpenStreetMap data in Go (golang). It has the ability to read OSM

Paul Mach 246 Dec 30, 2022
S2 geometry library in Go

Overview S2 is a library for spherical geometry that aims to have the same robustness, flexibility, and performance as the best planar geometry librar

Go 1.5k Jan 8, 2023
Go package for fast high-level image processing powered by libvips C library

bimg Small Go package for fast high-level image processing using libvips via C bindings, providing a simple programmatic API. bimg was designed to be

Tom 2.1k Jan 2, 2023
Image processing library and rendering toolkit for Go.

blend Image processing library and rendering toolkit for Go. (WIP) Installation: This library is compatible with Go1. go get github.com/phrozen/blend

Guillermo Estrada 61 Nov 11, 2022
Go bindings to OpenGL Utility Library

GLU This package offers minimal bindings for GLU functions. Usage go get github.com/go-gl-legacy/glu License Copyright 2012 The go-gl Authors. All ri

go-gl legacy 21 Aug 18, 2018
A library for playing with colors in go (golang).

go-colorful A library for playing with colors in Go. Supports Go 1.13 onwards. Why? I love games. I make games. I love detail and I get lost in detail

Lucas Beyer 1k Dec 30, 2022
A lightning fast image processing and resizing library for Go

govips A lightning fast image processing and resizing library for Go This package wraps the core functionality of libvips image processing library by

David Byttow 816 Jan 8, 2023
A library to read, write, and transform Stereolithography (.stl) files in Go.

stl A library to read, write, and transform Stereolithography (.stl) files in Go. It is used in the command line STL manipulation tool stltool. Featur

Hagen Schendel 65 Sep 26, 2022