From 05af31880498bf60316b85415f9d4c1dfa0d1577 Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Mon, 14 Nov 2016 00:42:23 +0100 Subject: wip --- marks.go | 36 ++++------------------------ media.go | 76 ++++++++++++++++++++++------------------------------------ pic.go | 6 ++--- robo.go | 2 ++ testpattern.go | 2 ++ text.go | 10 ++++---- units.go | 15 ++++++------ 7 files changed, 54 insertions(+), 93 deletions(-) diff --git a/marks.go b/marks.go index 9284693..f388145 100644 --- a/marks.go +++ b/marks.go @@ -1,7 +1,5 @@ package robo -import "bufio" - /* Landscape Portrait +- H -+ +- W -+ |x1 3| |2 1x| @@ -11,41 +9,17 @@ import "bufio" |2 3| +- -+ */ - /* - Type1 - - | | - -+ +- - - - -+ - | + Type1 Type2 - Type2 + | | +-- --+ + --+ +-- | | - +- -+ - | | - - | - +- + --+ | + | +-- */ -func DrawMarks(c *bufio.Writer, offset, size Point, length int) { - Point{600, 3800}.Move(c) - Point{200, 3800}.Draw(c) - Point{200, 3400}.Draw(c) - - Point{200, 600}.Move(c) - Point{200, 200}.Draw(c) - Point{600, 200}.Draw(c) - - Point{4840, 200}.Move(c) - Point{5240, 200}.Draw(c) - Point{5240, 600}.Draw(c) -} - func (r Robo) DrawMarks() { r.Line(Point{600, 3800}, Point{200, 3800}, Point{200, 3400}) r.Line(Point{200, 600}, Point{200, 200}, Point{600, 200}) diff --git a/media.go b/media.go index d30481f..6576e7b 100644 --- a/media.go +++ b/media.go @@ -1,102 +1,84 @@ package robo -import ( - "bufio" - "fmt" -) - // Overcut: depends on blade, 0 for pens type Media struct { Descr string // Description - ID int // FW111 - Speed int // !10 - Force int // FX10,0 - Overcut int // FC ? -} - -var MediaID = make(map[int]Media) - -func init() { - for _, m := range Medias { - MediaID[m.ID] = m - } -} - -func (m Media) String() string { - return fmt.Sprintf("%v: Speed %2d, Force %2d %s", - m.ID, m.Speed, m.Force, m.Descr) + ID Unit // FW111 + Speed Unit // !10 + Force Unit // FX10,0 + Overcut Unit // FC ? } -func (m Media) Apply(c *bufio.Writer) { - Unit(m.ID).Media(c) - Unit(m.Speed).Speed(c) - Unit(m.Force).Force(c) - Unit(m.Overcut).Overcut(c) +func (r Robo) SetMedia(m Media) { + r.Media(m.ID) + r.Speed(m.Speed) + r.Force(m.Force) + r.Overcut(m.Overcut) } -var Medias = []Media{ - { +var ( + MediaCardWithoutCraftPaperBacking = Media{ Descr: "Card without Craft Paper Backing", ID: 100, Speed: 10, Force: 27, Overcut: 18, - }, - { + } + MediaCardWithCraftPaperBacking = Media{ Descr: "Card with Craft Paper Backing", ID: 101, Speed: 10, Force: 27, Overcut: 18, - }, - { + } + MediaVinylSticker = Media{ Descr: "Vinyl Sticker", ID: 102, Speed: 10, Force: 10, Overcut: 18, - }, - { + } + MediaFilmLables = Media{ Descr: "Film Labels", ID: 106, Speed: 10, Force: 14, Overcut: 18, - }, - { + } + MediaMagneticSheet = Media{ Descr: "Magnetic Sheet", ID: 107, Speed: 10, Force: 12, Overcut: 18, - }, - { + } + MediaThick = Media{ Descr: "Thick Media", ID: 111, Speed: 10, Force: 27, Overcut: 18, - }, - { + } + MediaThin = Media{ Descr: "Thin Media", ID: 112, Speed: 10, Force: 2, Overcut: 18, - }, - { + } + MediaPen = Media{ Descr: "Pen", ID: 113, Speed: 10, Force: 10, Overcut: 0, - }, - { + } + MediaCustom = Media{ Descr: "Custom", ID: 300, Speed: 10, Force: 10, Overcut: 18, - }, -} + } +) diff --git a/pic.go b/pic.go index 14cf701..a7c7827 100644 --- a/pic.go +++ b/pic.go @@ -36,9 +36,9 @@ func parsePage() (pa Page) { return pa } -func DrawPic(c *bufio.Writer) { - Landscape.Orientation(c) +func (r Robo) DrawPic() { + //Landscape.Orientation(c) for _, p := range parsePage() { - p.Line(c) + r.Line(p...) } } diff --git a/robo.go b/robo.go index 8623083..889cd6f 100644 --- a/robo.go +++ b/robo.go @@ -1,3 +1,5 @@ +// +build ignore + package robo import ( diff --git a/testpattern.go b/testpattern.go index e9fb235..274ac0f 100644 --- a/testpattern.go +++ b/testpattern.go @@ -1,3 +1,5 @@ +// +build ignore + package robo import "bufio" diff --git a/text.go b/text.go index a925f91..cce7956 100644 --- a/text.go +++ b/text.go @@ -15,19 +15,19 @@ type Glyph struct { type Set []Path -func Print(c *bufio.Writer, in io.Reader, scale Unit) { +func (r Robo) Print(in io.Reader, scale Unit) { var off Point scanner := bufio.NewScanner(in) for scanner.Scan() { - font.putchar(c, scanner.Text(), scale, &off) + font.putchar(r, scanner.Text(), scale, &off) } if err := scanner.Err(); err != nil { log.Fatal(err) } } -func (f Font) putchar(c *bufio.Writer, s string, scale Unit, off *Point) { +func (f Font) putchar(r Robo, s string, scale Unit, off *Point) { for _, ch := range s { gl, ok := f[ch] if ok { @@ -35,9 +35,9 @@ func (f Font) putchar(c *bufio.Writer, s string, scale Unit, off *Point) { off.X += height * scale off.Y = 0 } - off.Offset(c) + r.Offset(*off) for _, p := range gl.S { - p.Scale(scale).Line(c) + r.Line(p.Scale(scale)...) //p.Scale(scale).Curve(c, 0) } off.Y += gl.W * scale diff --git a/units.go b/units.go index 1acd3e1..03026bb 100644 --- a/units.go +++ b/units.go @@ -44,14 +44,15 @@ type Point struct { X, Y Unit } +func (p Point) Swap() Point { return Point{X: p.Y, Y: p.X} } + func (p Point) String() (s string) { switch orientation { case Portrait: - s = fmt.Sprintf("%v,%v", p.X, p.Y) case Landscape: - s = fmt.Sprintf("%v,%v", p.Y, p.X) + p = p.Swap() } - return + return fmt.Sprintf("%v,%v", p.X, p.Y) } func (p Point) Scale(f Unit) Point { @@ -86,10 +87,10 @@ func (p Path) String() string { return strings.Join(pp, ",") } -func (ph Path) Scale(f Unit) Path { - ret := make(Path, len(ph)) - for i, p := range ph { - ret[i] = p.Scale(f) +func (p Path) Scale(f Unit) Path { + ret := make(Path, len(p)) + for i, pt := range p { + ret[i] = pt.Scale(f) } return ret } -- cgit v1.2.3