Esempio n. 1
0
func (ts *TextSymbolizer) Draw(gc draw2d.GraphicContext, shape geom.Shape) {
	if !ts.Applies(shape) {
		return
	}
	if name := shape.Attribute(ts.s.Attr); name != "" {
		gc.SetFontSize(ts.s.Size)
		l, t, r, b := gc.GetStringBounds(name)
		bb := shape.Bbox()
		dx := math.Abs(bb[2] - bb[0])
		dy := math.Abs(bb[3] - bb[1])
		ox, oy := dx/2, dy/2

		x, y := ts.r.matrix.TransformPoint(bb[0]+ox, bb[1]-oy)
		gc.SetFillColor(ts.s.Fill)
		gc.FillStringAt(name, x-(r-l)/2, y-(t-b)/2)
	}
}
Esempio n. 2
0
func doesExpr(part string, shape geom.Shape) bool {
	var name string
	var value string

	if strings.Contains(part, " = ") {
		parts := strings.Split(part, " = ")
		fmt.Sscanf(parts[0], "%s", &name)
		value = strings.TrimSpace(parts[1])
		return shape.Attribute(name) == value
	} else if strings.Contains(part, " contains ") {
		parts := strings.Split(part, " contains ")
		fmt.Sscanf(parts[0], "%s", &name)
		value = strings.TrimSpace(parts[1])
		attr := shape.Attribute(name)
		return strings.Contains(attr, value)
	} else {
		fmt.Sscanf(part, "%s", &name)
		return shape.Attribute(name) != ""
	}
	return false
}