示例#1
0
// void cairo_set_dash (cairo_t *cr, const double *dashes, int num_dashes, double offset);
func (self *Surface) SetDash(dashes []float64, offset float64) {
	var dashesp *C.double
	num_dashes := len(dashes)
	if dashes != nil && num_dashes > 0 {
		dashesp = (*C.double)(&dashes[0])
	} else {
		dashesp = nil
	}

	C.cairo_set_dash(self.context, dashesp, C.int(num_dashes), C.double(offset))
}
示例#2
0
//SetDash sets the dash pattern to be used by Stroke.
//
//A dash pattern is specified by a sequence of positive float64s.
//
//Each float64 represents the length of alternating "on" and "off"
//portions of the stroke.
//
//The offset specifies an offset into the pattern at which the stroke begins.
//
//Each "on" segment will have caps applied as if the segment were a separate
//sub-path.
//It is valid to use an "on" length of 0 with LineCapRound or LineCapSquare
//in order to distribute dots or squares along a path.
//
//Note
//
//The length values are in user-space units as evaluated
//at the time of stroking, which is not necessarily the same as the user space
//at the time SetDash is called.
//
//Special Cases
//
//If the length of dashes is 0, dashing is disabled.
//
//If the length of dashes is 1, a symmetric pattern is assumed,
//where the alternating off and on portions are of the single length provided.
//That is
//	SetDash(0, .5)
//and
//	SetDash(0, .5, .5)
//are equivalent.
//
//Errors
//
//If any of the elements of dashes is negative or all are zero,
//ErrInvalidDash is returned and the dash is not set.
//This differs from libcairo, which puts c into an error mode.
//
//Originally cairo_set_dash.
func (c *Context) SetDash(offset float64, dashes ...float64) error {
	off := C.double(offset)
	nd := len(dashes)

	arr := make([]C.double, nd)
	allZero := true
	for i, d := range dashes {
		if d < 0 {
			return ErrInvalidDash
		}
		if d > 0 {
			allZero = false
		}
		arr[i] = C.double(d)
	}
	if allZero {
		return ErrInvalidDash
	}

	C.cairo_set_dash(c.c, &arr[0], C.int(nd), off)
	return nil
}
示例#3
0
func (self *Surface) SetDash(dashes []float64, num_dashes int, offset float64) {
	dashesp := (*C.double)(&dashes[0])
	C.cairo_set_dash(self.context, dashesp, C.int(num_dashes), C.double(offset))
}
示例#4
0
文件: cairo.go 项目: raichu/gotk3
// SetDash is a wrapper around cairo_set_dash().
func (v *Context) SetDash(dashes []float64, offset float64) {
	header := (*reflect.SliceHeader)(unsafe.Pointer(&dashes))
	cdashes := (*C.double)(unsafe.Pointer(header.Data))
	C.cairo_set_dash(v.native(), cdashes, C.int(header.Len),
		C.double(offset))
}
示例#5
0
func (self *Surface) ClearDash() {
	C.cairo_set_dash(self.context, nil, C.int(0), C.double(0.0))
}
示例#6
0
func (self *Surface) SetDash(width float64) {
	x := C.double(width)
	C.cairo_set_dash(self.context, &x, C.int(1), C.double(0.0))
}