Skip to content

Commit

Permalink
Merge pull request #17 from goccy/feature/support-dash-line
Browse files Browse the repository at this point in the history
Supports dashed ( and dotted ) line
  • Loading branch information
goccy authored Feb 22, 2020
2 parents fe87c3f + f0923a6 commit e96524e
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion gvc/image_renderer.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,18 @@ func (r *ImageRenderer) saveJPG(path string) error {
return r.encodeJPG(file)
}

func (r *ImageRenderer) setPenStyle(job *Job) {
o := job.Obj()
switch o.Pen() {
case ccall.PEN_DASHED:
r.ctx.SetDash(4.0)
case ccall.PEN_DOTTED:
r.ctx.SetDash(2.0, 4.0)
case ccall.PEN_SOLID, ccall.PEN_NONE:
}
r.ctx.SetLineWidth(o.PenWidth())
}

func (r *ImageRenderer) EndPage(job *Job) error {
if r.isRenderDataMode(job) {
var buf bytes.Buffer
Expand Down Expand Up @@ -104,7 +116,8 @@ func (r *ImageRenderer) TextSpan(job *Job, p Pointf, span *TextSpan) error {
r.ctx.Push()
defer r.ctx.Pop()

r.ctx.SetRGB(0, 0, 0)
c := job.Obj().PenColor()
r.ctx.SetRGB(float64(c.R)/255.0, float64(c.G)/255.0, float64(c.B)/255.0)

face, err := r.fontFace(span.Font().Size())
if err != nil {
Expand All @@ -127,6 +140,7 @@ func (r *ImageRenderer) TextSpan(job *Job, p Pointf, span *TextSpan) error {
func (r *ImageRenderer) Ellipse(job *Job, a0, a1 Pointf, filled int) error {
r.ctx.Push()
defer r.ctx.Pop()
r.setPenStyle(job)
rx := a1.X - a0.X
ry := a1.Y - a0.Y
var c ccall.GVColor
Expand All @@ -149,6 +163,7 @@ func (r *ImageRenderer) Ellipse(job *Job, a0, a1 Pointf, filled int) error {
func (r *ImageRenderer) Polygon(job *Job, a []Pointf, filled int) error {
r.ctx.Push()
defer r.ctx.Pop()
r.setPenStyle(job)
var c ccall.GVColor
if filled > 0 {
c = job.Obj().FillColor()
Expand All @@ -172,6 +187,7 @@ func (r *ImageRenderer) Polygon(job *Job, a []Pointf, filled int) error {
func (r *ImageRenderer) Polyline(job *Job, a []Pointf) error {
r.ctx.Push()
defer r.ctx.Pop()
r.setPenStyle(job)
c := job.Obj().PenColor()
r.ctx.SetRGB(float64(c.R)/255.0, float64(c.G)/255.0, float64(c.B)/255.0)
r.ctx.MoveTo(a[0].X, -a[0].Y)
Expand All @@ -185,6 +201,7 @@ func (r *ImageRenderer) Polyline(job *Job, a []Pointf) error {
func (r *ImageRenderer) BezierCurve(job *Job, a []Pointf, arrowAtStart, arrowAtEnd int) error {
r.ctx.Push()
defer r.ctx.Pop()
r.setPenStyle(job)
c := job.Obj().PenColor()
r.ctx.SetRGB(float64(c.R)/255.0, float64(c.G)/255.0, float64(c.B)/255.0)
r.ctx.MoveTo(a[0].X, -a[0].Y)
Expand Down

0 comments on commit e96524e

Please sign in to comment.