forked from tdewolff/canvas
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
92 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package canvas | ||
|
||
import ( | ||
"strings" | ||
"testing" | ||
|
||
"github.com/tdewolff/test" | ||
) | ||
|
||
func TestPDF(t *testing.T) { | ||
c := New(10, 10) | ||
c.DrawPath(0, 0, MustParseSVG("L10 0")) | ||
|
||
PDFCompress = false | ||
sb := strings.Builder{} | ||
c.WritePDF(&sb) | ||
test.T(t, sb.String(), `%PDF-1.7 | ||
1 0 obj | ||
<< /Length 38 >> stream | ||
0.00000 0.00000 m 10.00000 0.00000 l f | ||
endstream | ||
endobj | ||
2 0 obj | ||
<< /Type /Page /Contents 1 0 R /Group << /Type /Group /CS /DeviceRGB /I true /S /Transparency >> /MediaBox [0.00000 0.00000 10.00000 10.00000] /Parent 2 0 R /Resources << >> >> | ||
endobj | ||
3 0 obj | ||
<< /Type /Pages /Count 1 /Kids [2 0 R] >> | ||
endobj | ||
4 0 obj | ||
<< /Type /Catalog /Pages 3 0 R >> | ||
endobj | ||
xref | ||
0 5 | ||
0000000000 65535 f | ||
0000000009 00000 n | ||
0000000097 00000 n | ||
0000000289 00000 n | ||
0000000346 00000 n | ||
trailer | ||
<< /Root 4 0 R /Size 4 >> | ||
starxref | ||
395 | ||
%%EOF`) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package canvas | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/tdewolff/test" | ||
) | ||
|
||
func TestPolyline(t *testing.T) { | ||
p := &Polyline{} | ||
p.Add(10, 0) | ||
p.Add(20, 10) | ||
test.T(t, len(p.Coords()), 2) | ||
test.T(t, p.Coords()[0], Point{10, 0}) | ||
test.T(t, p.Coords()[1], Point{20, 10}) | ||
|
||
test.T(t, (&Polyline{}).ToPath(), MustParseSVG("")) | ||
test.T(t, (&Polyline{}).Add(10, 0).ToPath(), MustParseSVG("")) | ||
test.T(t, (&Polyline{}).Add(10, 0).Add(20, 10).ToPath(), MustParseSVG("M10 0L20 10")) | ||
test.T(t, (&Polyline{}).Add(10, 0).Add(20, 10).Add(10, 0).ToPath(), MustParseSVG("M10 0L20 10z")) | ||
|
||
test.That(t, (&Polyline{}).Add(10, 0).Add(20, 10).Add(10, 10).Add(10, 0).Interior(12, 5)) | ||
test.That(t, !(&Polyline{}).Add(10, 0).Add(20, 10).Add(10, 10).Add(10, 0).Interior(5, 5)) | ||
|
||
FillRule = EvenOdd | ||
test.That(t, (&Polyline{}).Add(10, 0).Add(20, 10).Add(10, 10).Add(10, 0).Interior(12, 5)) | ||
test.That(t, !(&Polyline{}).Add(10, 0).Add(20, 10).Add(10, 10).Add(10, 0).Interior(5, 5)) | ||
FillRule = NonZero | ||
} | ||
|
||
func TestPolylineSmoothen(t *testing.T) { | ||
test.T(t, (&Polyline{}).Smoothen(), MustParseSVG("")) | ||
test.T(t, (&Polyline{}).Add(0, 0).Add(10, 0).Smoothen(), MustParseSVG("M0 0L10 0")) | ||
test.T(t, (&Polyline{}).Add(0, 0).Add(5, 10).Add(10, 0).Add(5, -10).Smoothen(), MustParseSVG("M0 0C1.4444 5.1111 2.8889 10.222 5 10C7.1111 9.7778 9.8889 4.2222 10 0C10.111 -4.2222 7.5556 -7.1111 5 -10")) | ||
test.T(t, (&Polyline{}).Add(0, 0).Add(5, 10).Add(10, 0).Add(5, -10).Add(0, 0).Smoothen(), MustParseSVG("M0 0C0 5 2.5 10 5 10C7.5 10 10 5 10 0C10 -5 7.5 -10 5 -10C2.5 -10 0 -5 0 0z")) | ||
} |