當前位置: 首頁>>代碼示例>>Golang>>正文


Golang C.cairo_create函數代碼示例

本文整理匯總了Golang中C.cairo_create函數的典型用法代碼示例。如果您正苦於以下問題:Golang cairo_create函數的具體用法?Golang cairo_create怎麽用?Golang cairo_create使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了cairo_create函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: NewPDFSurface

func NewPDFSurface(filename string, widthInPoints, heightInPoints float64, version PDFVersion) *Surface {
	cs := C.CString(filename)
	defer C.free(unsafe.Pointer(cs))
	s := C.cairo_pdf_surface_create(cs, C.double(widthInPoints), C.double(heightInPoints))
	C.cairo_pdf_surface_restrict_to_version(s, C.cairo_pdf_version_t(version))
	return &Surface{surface: s, context: C.cairo_create(s)}
}
開發者ID:ungerik,項目名稱:go-cairo,代碼行數:7,代碼來源:surface.go

示例2: NewPSSurface

func NewPSSurface(filename string, widthInPoints, heightInPoints float64, level PSLevel) *Surface {
	cs := C.CString(filename)
	defer C.free(unsafe.Pointer(cs))
	s := C.cairo_ps_surface_create(cs, C.double(widthInPoints), C.double(heightInPoints))
	C.cairo_ps_surface_restrict_to_level(s, C.cairo_ps_level_t(level))
	return &Surface{surface: s, context: C.cairo_create(s)}
}
開發者ID:ungerik,項目名稱:go-cairo,代碼行數:7,代碼來源:surface.go

示例3: NewSurfaceFromPNG

func NewSurfaceFromPNG(filename string) *Surface {
	surface := new(Surface)
	p := C.CString(filename)
	surface.surface = C.cairo_image_surface_create_from_png(p)
	C.free(unsafe.Pointer(p))
	surface.context = C.cairo_create(surface.surface)
	return surface
}
開發者ID:zvin,項目名稱:gocairo,代碼行數:8,代碼來源:cairo.go

示例4: CairoCreateContext

func CairoCreateContext(surface CairoSurface) (CairoContext, error) {
	context := C.cairo_create(surface.nativePointer())
	c := CairoContext(unsafe.Pointer(context))
	if err := c.status(); err != nil {
		return 0, err
	}
	return c, nil
}
開發者ID:tryandbuy,項目名稱:cups-connector,代碼行數:8,代碼來源:cairo.go

示例5: Create

// Format is determined from filename extension
// Supported formats: eps, jpeg, pdf, png, ps, svg
//
// Width and height are in pts for eps, pdf, ps, and svg; pixels for jpeg and png.
// Pixel measures will be truncated into integers
//
// Close the graphic to write the file
func Create(filename string, width float64, height float64) (*Graphic, error) {
	g := &Graphic{}

	var err error
	filename = filepath.Clean(filename)
	g.filename, err = filepath.Abs(filename)
	if err != nil {
		return nil, err
	}

	g.format = filepath.Ext(filename)[1:]

	// create the surface
	switch g.format {
	case "pdf":
		g.surface = C.cairo_pdf_surface_create(
			C.CString(filename),
			C.double(width),
			C.double(height),
		)
	case "png", "jpeg":
		g.surface = C.cairo_image_surface_create(
			C.CAIRO_FORMAT_ARGB32,
			C.int(width),
			C.int(height),
		)
	case "ps", "eps":
		g.surface = C.cairo_ps_surface_create(
			C.CString(filename),
			C.double(width),
			C.double(height),
		)
		if g.format == "eps" {
			C.cairo_ps_surface_set_eps(g.surface, 1)
		}
	case "svg":
		g.surface = C.cairo_svg_surface_create(
			C.CString(filename),
			C.double(width),
			C.double(height),
		)
	default:
		return nil, errors.New("cairo: unsupported format: " + g.format)
	}
	err = g.cairoSurfaceStatus()
	if err != nil {
		return nil, err
	}

	// create the cairo context
	g.cr = C.cairo_create(g.surface)
	err = g.cairoStatus()
	if err != nil {
		return nil, err
	}

	return g, nil
}
開發者ID:nathankerr,項目名稱:graphics,代碼行數:65,代碼來源:graphics.go

示例6: New

//New creates a new drawing context that draws on the target surface.
//
//Originally cairo_create.
func New(target Surface) (*Context, error) {
	s := target.XtensionRaw()
	c := &Context{
		c: C.cairo_create(s),
		s: target,
	}
	runtime.SetFinalizer(c, (*Context).Close)
	return c, c.Err()
}
開發者ID:jimmyfrasche,項目名稱:cairo,代碼行數:12,代碼來源:cairo.go

示例7: SetIcon

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
}
開發者ID:sqp,項目名稱:godock,代碼行數:16,代碼來源:icon.go

示例8: NewSurfaceFromXCB

func NewSurfaceFromXCB(xcb_drawable xproto.Drawable, xcb_VI xproto.VisualInfo, width, height int) *Surface {

	var xcb_visualtype C.xcb_visualtype_t
	xcb_visualtype.visual_id = C.xcb_visualid_t(xcb_VI.VisualId)
	xcb_visualtype._class = C.uint8_t(xcb_VI.Class)
	xcb_visualtype.bits_per_rgb_value = C.uint8_t(xcb_VI.BitsPerRgbValue)
	xcb_visualtype.colormap_entries = C.uint16_t(xcb_VI.ColormapEntries)
	xcb_visualtype.red_mask = C.uint32_t(xcb_VI.RedMask)
	xcb_visualtype.green_mask = C.uint32_t(xcb_VI.GreenMask)
	xcb_visualtype.blue_mask = C.uint32_t(xcb_VI.BlueMask)

	var connect_xcb (*C.xcb_connection_t) = C.xcb_connect(nil, nil)

	s := C.cairo_xcb_surface_create(connect_xcb, C.xcb_drawable_t(xcb_drawable), &xcb_visualtype, C.int(width), C.int(height))
	return &Surface{surface: s, context: C.cairo_create(s)}
}
開發者ID:Joker,項目名稱:go-cairo,代碼行數:16,代碼來源:surface_xcb.go

示例9: Create

// Create an image of the given size
func Create(w, h int, mode ColorSpace) *Image {
	var img Image
	var format C.cairo_format_t
	switch mode {
	case MODE_RGB, MODE_G8:
		format = C.CAIRO_FORMAT_RGB24
	case MODE_RGBA:
		format = C.CAIRO_FORMAT_ARGB32
	default:
		format = C.CAIRO_FORMAT_A8
	}
	img.ColorSpace = mode
	img.Surf = C.cairo_image_surface_create(format, C.int(w), C.int(h))
	img.Ctx = C.cairo_create(img.Surf)
	img.W, img.H = w, h
	return &img
}
開發者ID:akiross,項目名稱:gogp,代碼行數:18,代碼來源:imgops.go

示例10: CreateXWindow

func CreateXWindow(width, height int) (*XWindow, error) {
	C.XInitThreads()

	W := &XWindow{}

	W.Display = C.XOpenDisplay(nil)
	if W.Display == nil {
		return &XWindow{}, errors.New("Can't open display")
	}
	W.Window = C.XCreateSimpleWindow(W.Display, C.XDefaultRootWindow(W.Display), 0, 0, C.uint(width), C.uint(height), 0, 0, 0xFF151515)
	C.XSetWindowBackgroundPixmap(W.Display, W.Window, 0) // This avoids flickering on resize
	C.XMapWindow(W.Display, W.Window)
	C.XStoreName(W.Display, W.Window, C.CString("gowitt"))

	C.XSelectInput(W.Display, W.Window, C.ExposureMask|C.KeyPressMask|C.ButtonPressMask)
	C.XFlush(W.Display)

	// Cairo
	W.Surface = C.cairo_xlib_surface_create(W.Display, C.Drawable(W.Window), C.XDefaultVisual(W.Display, 0), C.int(width), C.int(height))
	C.cairo_xlib_surface_set_size(W.Surface, C.int(width), C.int(height))
	W.Cairo = C.cairo_create(W.Surface)

	// Pango
	InitLayoutsCache(W.Cairo)
	W.PangoContext = C.pango_cairo_create_context(W.Cairo)
	W.FontDesc = C.pango_font_description_from_string(C.CString("Sans 10"))

	W.AttrList = C.pango_attr_list_new()

	placeholderImage = C.cairo_image_surface_create_from_png(C.CString("test.png"))

	W.UserImages = NewImageCache(func() {
		var ev C.XEvent
		exev := (*C.XExposeEvent)(unsafe.Pointer(&ev))
		exev._type = C.Expose
		exev.count = 0
		exev.window = W.Window
		exev.send_event = 1
		exev.display = W.Display

		C.XSendEvent(W.Display, W.Window, 0, C.ExposureMask, &ev)
		C.XFlush(W.Display)
	})
	return W, nil
}
開發者ID:jonvaldes,項目名稱:gowitt,代碼行數:45,代碼來源:gowitt.go

示例11: Load

// Load an image from a PNG file
func Load(path string) (*Image, error) {
	var img Image

	img.Surf = C.cairo_image_surface_create_from_png(C.CString(path))
	switch C.cairo_image_surface_get_format(img.Surf) {
	case C.CAIRO_FORMAT_A8:
		img.ColorSpace = MODE_A8
	case C.CAIRO_FORMAT_RGB24:
		img.ColorSpace = MODE_RGB
	case C.CAIRO_FORMAT_ARGB32:
		img.ColorSpace = MODE_RGBA
	default:
		fmt.Println("ERROR: Format not supported")
		return nil, error("Format not supported")
	}
	img.W = int(C.cairo_image_surface_get_width(img.Surf))
	img.H = int(C.cairo_image_surface_get_height(img.Surf))
	img.Ctx = C.cairo_create(img.Surf)
	return &img, nil
}
開發者ID:akiross,項目名稱:gogp,代碼行數:21,代碼來源:imgops.go

示例12: NewSurfaceFromPNG

func NewSurfaceFromPNG(filename string) (*Surface, Status) {

	cstr := C.CString(filename)
	defer C.free(unsafe.Pointer(cstr))

	surfaceNative := C.cairo_image_surface_create_from_png(cstr)
	status := Status(C.cairo_surface_status(surfaceNative))
	if status != STATUS_SUCCESS {
		return nil, status
	}

	contextNative := C.cairo_create(surfaceNative)
	status = Status(C.cairo_status(contextNative))
	if status != STATUS_SUCCESS {
		return nil, status
	}

	surface := &Surface{
		surface: surfaceNative,
		context: contextNative,
	}

	return surface, STATUS_SUCCESS
}
開發者ID:ungerik,項目名稱:go-cairo,代碼行數:24,代碼來源:surface.go

示例13: NewSurface

func NewSurface(format Format, width, height int) *Surface {
	s := C.cairo_image_surface_create(C.cairo_format_t(format), C.int(width), C.int(height))
	return &Surface{surface: s, context: C.cairo_create(s)}
}
開發者ID:ungerik,項目名稱:go-cairo,代碼行數:4,代碼來源:surface.go

示例14: Create

// Create is a wrapper around cairo_create().
func Create(target *Surface) *Context {
	c := C.cairo_create(target.native())
	ctx := wrapContext(c)
	runtime.SetFinalizer(ctx, (*Context).destroy)
	return ctx
}
開發者ID:raichu,項目名稱:gotk3,代碼行數:7,代碼來源:cairo.go

示例15: NewSurface

func NewSurface(format Format, width, height int) *Surface {
	surface := new(Surface)
	surface.surface = C.cairo_image_surface_create(C.cairo_format_t(format), C.int(width), C.int(height))
	surface.context = C.cairo_create(surface.surface)
	return surface
}
開發者ID:zvin,項目名稱:gocairo,代碼行數:6,代碼來源:cairo.go


注:本文中的C.cairo_create函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。