From f7dc650faac269ace419111c0aad1150d07b678f Mon Sep 17 00:00:00 2001 From: Laurent Le Goff Date: Mon, 28 May 2012 09:52:49 +0200 Subject: [PATCH] add Painter Arg --- draw2d/doc.go | 4 ++-- draw2d/image.go | 22 ++++++++++++++++++++-- draw2d/path.go | 2 +- draw2d/rgba_interpolation.go | 2 +- 4 files changed, 24 insertions(+), 6 deletions(-) diff --git a/draw2d/doc.go b/draw2d/doc.go index 9184d66..3dbff82 100644 --- a/draw2d/doc.go +++ b/draw2d/doc.go @@ -1,5 +1,5 @@ // Copyright 2010 The draw2d Authors. All rights reserved. // created: 13/12/2010 by Laurent Le Goff - + // The package draw2d provide a Graphic Context that can draw vectorial figure on surface. -package draw2d \ No newline at end of file +package draw2d diff --git a/draw2d/image.go b/draw2d/image.go index 1ff136d..eca4830 100644 --- a/draw2d/image.go +++ b/draw2d/image.go @@ -39,8 +39,6 @@ func NewGraphicContext(img draw.Image) *ImageGraphicContext { switch selectImage := img.(type) { case *image.RGBA: painter = raster.NewRGBAPainter(selectImage) - //case *image.NRGBA: - // painter = NewNRGBAPainter(selectImage) default: panic("Image type not supported") } @@ -62,6 +60,26 @@ func NewGraphicContext(img draw.Image) *ImageGraphicContext { return gc } +// Create a new Graphic context from an image and a Painter (see Freetype-go) +func NewGraphicContextWithPainter(img draw.Image, painter Painter) *ImageGraphicContext { + width, height := img.Bounds().Dx(), img.Bounds().Dy() + dpi := 92 + ftContext := freetype.NewContext() + ftContext.SetDPI(dpi) + ftContext.SetClip(img.Bounds()) + ftContext.SetDst(img) + gc := &ImageGraphicContext{ + NewStackGraphicContext(), + img, + painter, + raster.NewRasterizer(width, height), + raster.NewRasterizer(width, height), + ftContext, + dpi, + } + return gc +} + func (gc *ImageGraphicContext) SetDPI(dpi int) { gc.DPI = dpi gc.freetype.SetDPI(dpi) diff --git a/draw2d/path.go b/draw2d/path.go index ab51810..b82910e 100644 --- a/draw2d/path.go +++ b/draw2d/path.go @@ -16,7 +16,7 @@ type Path interface { // Add a line to the current subpath // relative to the current point RLineTo(dx, dy float64) - + QuadCurveTo(cx, cy, x, y float64) RQuadCurveTo(dcx, dcy, dx, dy float64) CubicCurveTo(cx1, cy1, cx2, cy2, x, y float64) diff --git a/draw2d/rgba_interpolation.go b/draw2d/rgba_interpolation.go index 39fd3d1..92534e7 100644 --- a/draw2d/rgba_interpolation.go +++ b/draw2d/rgba_interpolation.go @@ -116,7 +116,7 @@ func DrawImage(src image.Image, dest draw.Image, tr MatrixTransform, op draw.Op, u = x v = y tr.InverseTransform(&u, &v) - if bounds.Min.X <= int(u) && bounds.Max.X > int(u) && bounds.Min.Y <= int(v) && bounds.Max.Y > int(v) { + if bounds.Min.X <= int(u) && bounds.Max.X > int(u) && bounds.Min.Y <= int(v) && bounds.Max.Y > int(v) { c1 = dest.At(int(x), int(y)) switch filter { case LinearFilter: