Пример #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
// destroy is a wrapper around cairo_destroy().
func (v *Context) destroy() {
	C.cairo_destroy(v.native())
}
Пример #5
0
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
}