Ejemplo n.º 1
0
func TestIntersectFalse(t *testing.T) {
	r0 := fixed.R(0, 0, 1, 1)
	r1 := fixed.R(0, 2, 3, 3)

	if intersect(r0, r1) {
		t.Errorf("%v and %v shouldn't intersect", r0, r1)
	}
}
Ejemplo n.º 2
0
func TestIntersectTrue(t *testing.T) {
	r0 := fixed.R(0, 0, 2, 2)
	r1 := fixed.R(1, 1, 3, 3)

	if !intersect(r0, r1) {
		t.Errorf("%v and %v should intersect", r0, r1)
	}
}
Ejemplo n.º 3
0
func TestNormalizeDenormalizedRectangle(t *testing.T) {
	r0 := fixed.R(0, 0, -1, -1)
	r1 := normalize(r0)

	if r1 != fixed.R(-1, -1, 0, 0) {
		t.Errorf("invalid rectangle found after normalizing %v: %v", r0, r1)
	}
}
Ejemplo n.º 4
0
func TestFixedLayout(t *testing.T) {
	layout := NewFixedLayout(fixed.R(0, 0, 10, 10))

	if r, ok := layout.NextBounds(); !ok {
		t.Error("no bounds returned by the fixed layout")
	} else if r != fixed.R(0, 0, 10, 10) {
		t.Error("invalid bounds returned by the fixed layout:", r)
	}

	if _, ok := layout.NextBounds(); ok {
		t.Error("incomplete fixed layout")
	}
}
Ejemplo n.º 5
0
func TestHorizontalLayout(t *testing.T) {
	layout := NewHorizontalLayout(fixed.P(10, 10), fixed.P(100, 100))

	if r, ok := layout.NextBounds(); !ok {
		t.Error("no bounds returned by the horizontal layout")
	} else if r != fixed.R(10, 10, 110, 110) {
		t.Error("invalid bounds returned by the horizontal layout:", r)
	}

	if r, ok := layout.NextBounds(); !ok {
		t.Error("no bounds returned by the horizontal layout")
	} else if r != fixed.R(110, 10, 210, 110) {
		t.Error("invalid bounds returned by the horizontal layout:", r)
	}
}
Ejemplo n.º 6
0
func TestNormailzeNormalizedRectangle(t *testing.T) {
	r0 := fixed.R(0, 0, 1, 1)
	r1 := normalize(r0)

	if r1 != r0 {
		t.Errorf("invalid rectangle found after normalizing %v: %v", r0, r1)
	}
}
Ejemplo n.º 7
0
func TestVerticalLayout(t *testing.T) {
	layout := NewVerticalLayout(fixed.P(10, 10), fixed.I(100))

	if r, ok := layout.NextBounds(); !ok {
		t.Error("no bounds returned by the vertical layout")
	} else if r != fixed.R(10, 10, 110, 33554431) {
		t.Error("invalid bounds returned by the vertical layout:", r)
	}

	if _, ok := layout.NextBounds(); ok {
		t.Error("incomplete vertical layout")
	}
}
Ejemplo n.º 8
0
func (f *subface) GlyphBounds(r rune) (bounds fixed.Rectangle26_6, advance fixed.Int26_6, ok bool) {
	r -= f.firstRune
	if r < 0 || f.n <= int(r) {
		return fixed.Rectangle26_6{}, 0, false
	}
	i := &f.fontchars[r+0]
	j := &f.fontchars[r+1]

	bounds = fixed.R(
		int(i.left),
		int(i.top)-f.ascent,
		int(i.left)+int(j.x-i.x),
		int(i.bottom)-f.ascent,
	)
	return bounds, fixed.Int26_6(i.width) << 6, true
}
Ejemplo n.º 9
0
func TestRenderEmptyText(t *testing.T) {
	f := truetype.NewFace(clearSans, nil)
	defer f.Close()

	c := NewReader(strings.NewReader(""),
		Style{Offset: 0, Face: f, Foreground: image.Black, Background: image.White},
	)

	view, err := Render(c, NewFixedLayout(fixed.R(1, 1, 600, 600)))

	if err != nil {
		t.Error(err)
	}

	if !reflect.DeepEqual(view, View{}) {
		t.Error("invalid view rendered from empty string:", view)
	}
}
Ejemplo n.º 10
0
func (f *Face) GlyphBounds(r rune) (bounds fixed.Rectangle26_6, advance fixed.Int26_6, ok bool) {
	return fixed.R(0, -f.Ascent, f.Width, -f.Ascent+f.Height), fixed.I(f.Advance), true
}