示例#1
0
//Close destroys c.
//
//Originally cairo_destroy.
func (c *Context) Close() error {
	if c == nil || c.c == nil {
		return nil
	}
	runtime.SetFinalizer(c, nil)
	err := c.Err()
	C.cairo_destroy(c.c)
	c.c = nil
	c.s = nil
	return err
}
示例#2
0
文件: icon.go 项目: sqp/godock
func (o *dockIcon) SetIcon(str string) error {
	if o.Ptr.image.pSurface == nil {
		return errors.New("icon has no image.pSurface")
	}

	var cstr *C.gchar
	if str != "" {
		cstr = (*C.gchar)(C.CString(str))
		defer C.free(unsafe.Pointer((*C.char)(cstr)))
	}
	ctx := C.cairo_create(o.Ptr.image.pSurface)
	C.cairo_dock_set_image_on_icon(ctx, cstr, o.Ptr, o.GetContainer().Ptr) // returns gboolean
	C.cairo_destroy(ctx)

	return nil
}
示例#3
0
func (self *Surface) Destroy() {
	C.cairo_destroy(self.context)
	C.cairo_surface_destroy(self.surface)
}
示例#4
0
文件: cairo.go 项目: raichu/gotk3
// destroy is a wrapper around cairo_destroy().
func (v *Context) destroy() {
	C.cairo_destroy(v.native())
}
示例#5
0
文件: cairo.go 项目: zvin/gocairo
func (self *Surface) Finish() { C.cairo_destroy(self.context) }
示例#6
0
// completes and closes the file being written to
func (g *Graphic) Close() error {
	// destroy the context
	err := g.cairoStatus()
	if err != nil {
		return err
	}
	C.cairo_destroy(g.cr)

	// finishing the surface writes pdf, ps, and svg files
	C.cairo_surface_finish(g.surface)
	err = g.cairoSurfaceStatus()
	if err != nil {
		return err
	}

	// write other formats
	switch g.format {
	case "eps", "pdf", "ps", "svg":
		// cairo_surface_finish writes the surface to file
	case "png":
		img, err := g.Image()
		if err != nil {
			return err
		}

		file, err := os.Create(g.filename)
		if err != nil {
			return err
		}
		defer file.Close()

		err = png.Encode(file, img)
		if err != nil {
			return err
		}
	case "jpeg":
		img, err := g.Image()
		if err != nil {
			return err
		}

		file, err := os.Create(g.filename)
		if err != nil {
			return err
		}
		defer file.Close()

		err = jpeg.Encode(file, img, nil)
		if err != nil {
			return err
		}
	default:
		panic("unsupported format: " + g.format)
	}

	// destroy the surface
	C.cairo_surface_destroy(g.surface)
	err = g.cairoSurfaceStatus()
	if err != nil {
		return err
	}

	return nil
}
示例#7
0
func (self *Surface) ContextDestroy() { C.cairo_destroy(self.context) }
示例#8
0
func (t *PDFStreamTextObject) Close() {
	C.cairo_destroy(t.context)
	C.cairo_surface_destroy(t.surface)
	t.context = nil
	t.surface = nil
}
示例#9
0
func (c *CairoContext) Destroy() error {
	C.cairo_destroy(c.nativePointer())

	*c = 0
	return nil
}