Beispiel #1
0
func (f *Font) Printf(format string, argv ...interface{}) (*shapes.Group, error) {
	text := shapes.NewGroup()
	str := fmt.Sprintf(format, argv...)
	indices := []rune(str)

	if len(indices) == 0 {
		return nil, nil
	}

	// Runes form display list indices.
	// For this purpose, they need to be offset by -FontConfig.Low
	low := f.config.Low
	x, y := float32(0), float32(0)
	tw, th := f.Metrics(str)
	for i := range indices {
		id := indices[i] - low
		letter := f.listbase[id].Clone()
		letter.MoveTo(x, y)
		text.Append(letter)
		adv := f.config.Glyphs[id].Advance
		x += float32(adv)
	}

	// Recalculate the center of the text group
	verts := text.Vertices()
	text.SetCenter(verts[0]+float32(tw/2), verts[1]+float32(th/2))

	return text, nil
}
Beispiel #2
0
func (t *TestSuite) TestGroup() {
	filename := "expected_group.png"
	t.rlControl.drawFunc <- func() {
		w, h := t.renderState.window.GetSize()
		world := newWorld(w, h)

		// Create first group, 2 small boxes
		group1 := shapes.NewGroup()
		b1 := shapes.NewBox(t.renderState.boxProgram, 20, 20)
		b1.MoveTo(30, 40)
		b2 := shapes.NewBox(t.renderState.boxProgram, 50, 50)
		b2.MoveTo(45, -25)
		b2.Rotate(20.0)
		group1.Append(b1)
		group1.Append(b2)

		// Create the main group
		group := shapes.NewGroup()
		group.Append(group1)
		group.Append(shapes.NewBox(t.renderState.boxProgram, 100, 100))

		// Get the second element of the group
		b3 := group.GetAt(1)
		b3.MoveTo(float32(w/2), 0)

		group.AttachToWorld(world)
		gl.Clear(gl.COLOR_BUFFER_BIT)
		group.Draw()

		t.testDraw <- testlib.Screenshot(t.renderState.window)
		t.renderState.window.SwapBuffers()
	}
	distance, exp, act, err := testlib.TestImage(filename, <-t.testDraw, imagetest.Center)
	if err != nil {
		panic(err)
	}
	t.True(distance < distanceThreshold, distanceError(distance, filename))
	if t.Failed() {
		saveExpAct(t.outputPath, "failed_"+filename, exp, act)
	}
}