Compare commits

..

No commits in common. "e3566f7fc4b0e228a3766f0b4aa81d323558449a" and "f52c8a71aff06ab8df41843d33ab167b36c971cd" have entirely different histories.

31 changed files with 97 additions and 118 deletions

View file

@ -4,7 +4,7 @@
package draw2dbase package draw2dbase
import ( import (
"git.fromouter.space/crunchy-rocks/draw2d" "github.com/llgcode/draw2d"
) )
// Liner receive segment definition // Liner receive segment definition

View file

@ -8,9 +8,9 @@ import (
"image" "image"
"image/color" "image/color"
"git.fromouter.space/crunchy-rocks/draw2d" "github.com/llgcode/draw2d"
"git.fromouter.space/crunchy-rocks/freetype/truetype" "github.com/golang/freetype/truetype"
) )
var DefaultFontData = draw2d.FontData{Name: "luxi", Family: draw2d.FontFamilySans, Style: draw2d.FontStyleNormal} var DefaultFontData = draw2d.FontData{Name: "luxi", Family: draw2d.FontFamilySans, Style: draw2d.FontStyleNormal}
@ -47,6 +47,7 @@ func (cs *ContextStack) GetFontName() string {
return fmt.Sprintf("%s:%d:%d:%9.2f", fontData.Name, fontData.Family, fontData.Style, cs.FontSize) return fmt.Sprintf("%s:%d:%d:%9.2f", fontData.Name, fontData.Family, fontData.Style, cs.FontSize)
} }
/** /**
* Create a new Graphic context from an image * Create a new Graphic context from an image
*/ */

View file

@ -6,7 +6,7 @@ package draw2dbase
import ( import (
"math" "math"
"git.fromouter.space/crunchy-rocks/draw2d" "github.com/llgcode/draw2d"
) )
type LineStroker struct { type LineStroker struct {

View file

@ -1,6 +1,6 @@
package draw2dbase package draw2dbase
import "git.fromouter.space/crunchy-rocks/draw2d" import "github.com/llgcode/draw2d"
// GlyphCache manage a cache of glyphs // GlyphCache manage a cache of glyphs
type GlyphCache interface { type GlyphCache interface {
@ -13,10 +13,11 @@ type GlyphCacheImp struct {
glyphs map[string]map[rune]*Glyph glyphs map[string]map[rune]*Glyph
} }
// NewGlyphCache initializes a GlyphCache // NewGlyphCache initializes a GlyphCache
func NewGlyphCache() *GlyphCacheImp { func NewGlyphCache() *GlyphCacheImp {
glyphs := make(map[string]map[rune]*Glyph) glyphs := make(map[string]map[rune]*Glyph)
return &GlyphCacheImp{ return &GlyphCacheImp {
glyphs: glyphs, glyphs: glyphs,
} }
} }

View file

@ -8,12 +8,12 @@ import (
"math" "math"
"runtime" "runtime"
"git.fromouter.space/crunchy-rocks/draw2d"
"git.fromouter.space/crunchy-rocks/draw2d/draw2dbase"
"git.fromouter.space/crunchy-rocks/draw2d/draw2dimg"
"github.com/go-gl/gl/v2.1/gl" "github.com/go-gl/gl/v2.1/gl"
"github.com/golang/freetype/raster" "github.com/golang/freetype/raster"
"github.com/golang/freetype/truetype" "github.com/golang/freetype/truetype"
"github.com/llgcode/draw2d"
"github.com/llgcode/draw2d/draw2dbase"
"github.com/llgcode/draw2d/draw2dimg"
"golang.org/x/image/font" "golang.org/x/image/font"
"golang.org/x/image/math/fixed" "golang.org/x/image/math/fixed"

View file

@ -1,8 +1,8 @@
package draw2dgl package draw2dgl
import ( import (
"git.fromouter.space/crunchy-rocks/draw2d" "github.com/golang/freetype/truetype"
"git.fromouter.space/crunchy-rocks/freetype/truetype" "github.com/llgcode/draw2d"
"golang.org/x/image/math/fixed" "golang.org/x/image/math/fixed"
) )

View file

@ -2,14 +2,13 @@ package draw2dimg
import ( import (
"fmt" "fmt"
"github.com/golang/freetype/truetype"
"github.com/llgcode/draw2d"
"github.com/llgcode/draw2d/draw2dkit"
"golang.org/x/image/font/gofont/goregular"
"image" "image"
"image/color" "image/color"
"testing" "testing"
"git.fromouter.space/crunchy-rocks/draw2d"
"git.fromouter.space/crunchy-rocks/draw2d/draw2dkit"
"git.fromouter.space/crunchy-rocks/freetype/truetype"
"golang.org/x/image/font/gofont/goregular"
) )
// font generated from icomoon.io and converted to go byte slice // font generated from icomoon.io and converted to go byte slice

View file

@ -9,12 +9,11 @@ import (
"log" "log"
"math" "math"
"git.fromouter.space/crunchy-rocks/draw2d" "github.com/llgcode/draw2d"
"git.fromouter.space/crunchy-rocks/draw2d/draw2dbase" "github.com/llgcode/draw2d/draw2dbase"
"git.fromouter.space/crunchy-rocks/emoji"
"git.fromouter.space/crunchy-rocks/freetype/raster" "github.com/golang/freetype/raster"
"git.fromouter.space/crunchy-rocks/freetype/truetype" "github.com/golang/freetype/truetype"
"golang.org/x/image/draw" "golang.org/x/image/draw"
"golang.org/x/image/font" "golang.org/x/image/font"
@ -39,7 +38,6 @@ type GraphicContext struct {
glyphCache draw2dbase.GlyphCache glyphCache draw2dbase.GlyphCache
glyphBuf *truetype.GlyphBuf glyphBuf *truetype.GlyphBuf
DPI int DPI int
Emojis emoji.Table
} }
// ImageFilter defines the type of filter to use // ImageFilter defines the type of filter to use
@ -56,6 +54,7 @@ const (
// NewGraphicContext creates a new Graphic context from an image. // NewGraphicContext creates a new Graphic context from an image.
func NewGraphicContext(img draw.Image) *GraphicContext { func NewGraphicContext(img draw.Image) *GraphicContext {
var painter Painter var painter Painter
switch selectImage := img.(type) { switch selectImage := img.(type) {
case *image.RGBA: case *image.RGBA:
@ -80,7 +79,6 @@ func NewGraphicContextWithPainter(img draw.Image, painter Painter) *GraphicConte
draw2dbase.NewGlyphCache(), draw2dbase.NewGlyphCache(),
&truetype.GlyphBuf{}, &truetype.GlyphBuf{},
dpi, dpi,
make(emoji.Table),
} }
return gc return gc
} }
@ -126,9 +124,6 @@ func (gc *GraphicContext) FillString(text string) (width float64) {
return gc.FillStringAt(text, 0, 0) return gc.FillStringAt(text, 0, 0)
} }
const emojiSpacing = 10
const emojiScale = 110
// FillStringAt draws the text at the specified point (x, y) // FillStringAt draws the text at the specified point (x, y)
func (gc *GraphicContext) FillStringAt(text string, x, y float64) (width float64) { func (gc *GraphicContext) FillStringAt(text string, x, y float64) (width float64) {
f, err := gc.loadCurrentFont() f, err := gc.loadCurrentFont()
@ -139,25 +134,12 @@ func (gc *GraphicContext) FillStringAt(text string, x, y float64) (width float64
startx := x startx := x
prev, hasPrev := truetype.Index(0), false prev, hasPrev := truetype.Index(0), false
fontName := gc.GetFontName() fontName := gc.GetFontName()
for fragment := range gc.Emojis.Iterate(text) { for _, r := range text {
if fragment.IsEmoji { index := f.Index(r)
img, err := LoadFromPngFile(fragment.Emoji.Path)
if err == nil {
gc.Save()
scale := gc.GetFontSize() / 100
gc.Translate(x+scale*emojiSpacing, y-scale*emojiScale)
gc.Scale(scale, scale)
gc.DrawImage(img)
gc.Restore()
x += scale*float64(img.Bounds().Size().X) + scale*emojiSpacing*2
}
continue
}
index := f.Index(fragment.Rune)
if hasPrev { if hasPrev {
x += fUnitsToFloat64(f.Kern(fixed.Int26_6(gc.Current.Scale), prev, index)) x += fUnitsToFloat64(f.Kern(fixed.Int26_6(gc.Current.Scale), prev, index))
} }
glyph := gc.glyphCache.Fetch(gc, fontName, fragment.Rune) glyph := gc.glyphCache.Fetch(gc, fontName, r)
x += glyph.Fill(gc, x, y) x += glyph.Fill(gc, x, y)
prev, hasPrev = index, true prev, hasPrev = index, true
} }

View file

@ -4,7 +4,7 @@
package draw2dimg package draw2dimg
import ( import (
"git.fromouter.space/crunchy-rocks/freetype/raster" "github.com/golang/freetype/raster"
"golang.org/x/image/math/fixed" "golang.org/x/image/math/fixed"
) )

View file

@ -1,8 +1,8 @@
package draw2dimg package draw2dimg
import ( import (
"git.fromouter.space/crunchy-rocks/draw2d" "github.com/golang/freetype/truetype"
"git.fromouter.space/crunchy-rocks/freetype/truetype" "github.com/llgcode/draw2d"
"golang.org/x/image/math/fixed" "golang.org/x/image/math/fixed"
) )

View file

@ -14,7 +14,7 @@ import (
"os" "os"
"strconv" "strconv"
"git.fromouter.space/crunchy-rocks/freetype/truetype" "github.com/golang/freetype/truetype"
"github.com/jung-kurt/gofpdf" "github.com/jung-kurt/gofpdf"
"github.com/llgcode/draw2d" "github.com/llgcode/draw2d"

View file

@ -7,14 +7,13 @@ import (
"bytes" "bytes"
"encoding/base64" "encoding/base64"
"fmt" "fmt"
"github.com/llgcode/draw2d"
"image" "image"
"image/color" "image/color"
"image/png" "image/png"
"math" "math"
"strconv" "strconv"
"strings" "strings"
"git.fromouter.space/crunchy-rocks/draw2d"
) )
func toSvgRGBA(c color.Color) string { func toSvgRGBA(c color.Color) string {

View file

@ -4,17 +4,16 @@
package draw2dsvg package draw2dsvg
import ( import (
"github.com/golang/freetype/truetype"
"github.com/llgcode/draw2d"
"github.com/llgcode/draw2d/draw2dbase"
"golang.org/x/image/font"
"golang.org/x/image/math/fixed"
"image" "image"
"log" "log"
"math" "math"
"strconv" "strconv"
"strings" "strings"
"git.fromouter.space/crunchy-rocks/draw2d"
"git.fromouter.space/crunchy-rocks/draw2d/draw2dbase"
"git.fromouter.space/crunchy-rocks/freetype/truetype"
"golang.org/x/image/font"
"golang.org/x/image/math/fixed"
) )
type drawType int type drawType int

View file

@ -7,16 +7,16 @@ package draw2dsvg_test
import ( import (
"testing" "testing"
"git.fromouter.space/crunchy-rocks/draw2d" "github.com/llgcode/draw2d"
"git.fromouter.space/crunchy-rocks/draw2d/samples/android" "github.com/llgcode/draw2d/samples/android"
"git.fromouter.space/crunchy-rocks/draw2d/samples/frameimage" "github.com/llgcode/draw2d/samples/frameimage"
"git.fromouter.space/crunchy-rocks/draw2d/samples/geometry" "github.com/llgcode/draw2d/samples/geometry"
"git.fromouter.space/crunchy-rocks/draw2d/samples/gopher" "github.com/llgcode/draw2d/samples/gopher"
"git.fromouter.space/crunchy-rocks/draw2d/samples/gopher2" "github.com/llgcode/draw2d/samples/gopher2"
"git.fromouter.space/crunchy-rocks/draw2d/samples/helloworld" "github.com/llgcode/draw2d/samples/helloworld"
"git.fromouter.space/crunchy-rocks/draw2d/samples/line" "github.com/llgcode/draw2d/samples/line"
"git.fromouter.space/crunchy-rocks/draw2d/samples/linecapjoin" "github.com/llgcode/draw2d/samples/linecapjoin"
"git.fromouter.space/crunchy-rocks/draw2d/samples/postscript" "github.com/llgcode/draw2d/samples/postscript"
) )
func TestSampleAndroid(t *testing.T) { func TestSampleAndroid(t *testing.T) {

View file

@ -9,8 +9,8 @@ package draw2dsvg_test
import ( import (
"testing" "testing"
"git.fromouter.space/crunchy-rocks/draw2d" "github.com/llgcode/draw2d"
"git.fromouter.space/crunchy-rocks/draw2d/draw2dsvg" "github.com/llgcode/draw2d/draw2dsvg"
) )
type sample func(gc draw2d.GraphicContext, ext string) (string, error) type sample func(gc draw2d.GraphicContext, ext string) (string, error)

View file

@ -2,8 +2,8 @@
package draw2dsvg package draw2dsvg
import ( import (
"git.fromouter.space/crunchy-rocks/draw2d" "github.com/golang/freetype/truetype"
"git.fromouter.space/crunchy-rocks/freetype/truetype" "github.com/llgcode/draw2d"
"golang.org/x/image/math/fixed" "golang.org/x/image/math/fixed"
) )

View file

@ -8,9 +8,8 @@ import (
"log" "log"
"path/filepath" "path/filepath"
"github.com/golang/freetype/truetype"
"sync" "sync"
"git.fromouter.space/crunchy-rocks/freetype/truetype"
) )
// FontStyle defines bold and italic styles for the font // FontStyle defines bold and italic styles for the font

View file

@ -8,9 +8,9 @@ import (
"image/color" "image/color"
"math" "math"
"git.fromouter.space/crunchy-rocks/draw2d" "github.com/llgcode/draw2d"
"git.fromouter.space/crunchy-rocks/draw2d/draw2dkit" "github.com/llgcode/draw2d/draw2dkit"
"git.fromouter.space/crunchy-rocks/draw2d/samples" "github.com/llgcode/draw2d/samples"
) )
// Main draws a droid and returns the filename. This should only be // Main draws a droid and returns the filename. This should only be

View file

@ -9,9 +9,9 @@ import (
"image/png" "image/png"
"net/http" "net/http"
"git.fromouter.space/crunchy-rocks/draw2d/draw2dimg" "github.com/llgcode/draw2d/draw2dimg"
"git.fromouter.space/crunchy-rocks/draw2d/draw2dpdf" "github.com/llgcode/draw2d/draw2dpdf"
"git.fromouter.space/crunchy-rocks/draw2d/samples/android" "github.com/llgcode/draw2d/samples/android"
"appengine" "appengine"
) )

View file

@ -7,10 +7,10 @@ package frameimage
import ( import (
"math" "math"
"git.fromouter.space/crunchy-rocks/draw2d" "github.com/llgcode/draw2d"
"git.fromouter.space/crunchy-rocks/draw2d/draw2dimg" "github.com/llgcode/draw2d/draw2dimg"
"git.fromouter.space/crunchy-rocks/draw2d/draw2dkit" "github.com/llgcode/draw2d/draw2dkit"
"git.fromouter.space/crunchy-rocks/draw2d/samples" "github.com/llgcode/draw2d/samples"
) )
// Main draws the image frame and returns the filename. // Main draws the image frame and returns the filename.

View file

@ -9,10 +9,10 @@ import (
"image/color" "image/color"
"math" "math"
"git.fromouter.space/crunchy-rocks/draw2d" "github.com/llgcode/draw2d"
"git.fromouter.space/crunchy-rocks/draw2d/draw2dkit" "github.com/llgcode/draw2d/draw2dkit"
"git.fromouter.space/crunchy-rocks/draw2d/samples" "github.com/llgcode/draw2d/samples"
"git.fromouter.space/crunchy-rocks/draw2d/samples/gopher2" "github.com/llgcode/draw2d/samples/gopher2"
) )
// Main draws geometry and returns the filename. This should only be // Main draws geometry and returns the filename. This should only be

View file

@ -8,8 +8,8 @@ package gopher
import ( import (
"image/color" "image/color"
"git.fromouter.space/crunchy-rocks/draw2d" "github.com/llgcode/draw2d"
"git.fromouter.space/crunchy-rocks/draw2d/samples" "github.com/llgcode/draw2d/samples"
) )
// Main draws a left hand and ear of a gopher. Afterwards it returns // Main draws a left hand and ear of a gopher. Afterwards it returns

View file

@ -10,9 +10,9 @@ import (
"image/color" "image/color"
"math" "math"
"git.fromouter.space/crunchy-rocks/draw2d" "github.com/llgcode/draw2d"
"git.fromouter.space/crunchy-rocks/draw2d/draw2dkit" "github.com/llgcode/draw2d/draw2dkit"
"git.fromouter.space/crunchy-rocks/draw2d/samples" "github.com/llgcode/draw2d/samples"
) )
// Main draws a rotated face of the gopher. Afterwards it returns // Main draws a rotated face of the gopher. Afterwards it returns

View file

@ -9,9 +9,9 @@ import (
"fmt" "fmt"
"image" "image"
"git.fromouter.space/crunchy-rocks/draw2d" "github.com/llgcode/draw2d"
"git.fromouter.space/crunchy-rocks/draw2d/draw2dkit" "github.com/llgcode/draw2d/draw2dkit"
"git.fromouter.space/crunchy-rocks/draw2d/samples" "github.com/llgcode/draw2d/samples"
) )
// Main draws "Hello World" and returns the filename. This should only be // Main draws "Hello World" and returns the filename. This should only be

View file

@ -6,11 +6,11 @@ import (
"log" "log"
"runtime" "runtime"
"git.fromouter.space/crunchy-rocks/draw2d"
"git.fromouter.space/crunchy-rocks/draw2d/draw2dgl"
"git.fromouter.space/crunchy-rocks/draw2d/draw2dkit"
"github.com/go-gl/gl/v2.1/gl" "github.com/go-gl/gl/v2.1/gl"
"github.com/go-gl/glfw/v3.1/glfw" "github.com/go-gl/glfw/v3.1/glfw"
"github.com/llgcode/draw2d"
"github.com/llgcode/draw2d/draw2dgl"
"github.com/llgcode/draw2d/draw2dkit"
) )
var ( var (

View file

@ -7,9 +7,9 @@ package line
import ( import (
"image/color" "image/color"
"git.fromouter.space/crunchy-rocks/draw2d" "github.com/llgcode/draw2d"
"git.fromouter.space/crunchy-rocks/draw2d/draw2dkit" "github.com/llgcode/draw2d/draw2dkit"
"git.fromouter.space/crunchy-rocks/draw2d/samples" "github.com/llgcode/draw2d/samples"
) )
// Main draws vertically spaced lines and returns the filename. // Main draws vertically spaced lines and returns the filename.

View file

@ -7,8 +7,8 @@ package linecapjoin
import ( import (
"image/color" "image/color"
"git.fromouter.space/crunchy-rocks/draw2d" "github.com/llgcode/draw2d"
"git.fromouter.space/crunchy-rocks/draw2d/samples" "github.com/llgcode/draw2d/samples"
) )
// Main draws the different line caps and joins. // Main draws the different line caps and joins.

View file

@ -8,8 +8,8 @@ import (
"github.com/llgcode/ps" "github.com/llgcode/ps"
"git.fromouter.space/crunchy-rocks/draw2d" "github.com/llgcode/draw2d"
"git.fromouter.space/crunchy-rocks/draw2d/samples" "github.com/llgcode/draw2d/samples"
) )
// Main draws the tiger // Main draws the tiger

View file

@ -10,9 +10,9 @@ import (
"strings" "strings"
"time" "time"
"git.fromouter.space/crunchy-rocks/draw2d/draw2dgl"
"github.com/go-gl/gl/v2.1/gl" "github.com/go-gl/gl/v2.1/gl"
"github.com/go-gl/glfw/v3.1/glfw" "github.com/go-gl/glfw/v3.1/glfw"
"github.com/llgcode/draw2d/draw2dgl"
"github.com/llgcode/ps" "github.com/llgcode/ps"
) )

View file

@ -5,16 +5,16 @@ package draw2d_test
import ( import (
"testing" "testing"
"git.fromouter.space/crunchy-rocks/draw2d" "github.com/llgcode/draw2d"
"git.fromouter.space/crunchy-rocks/draw2d/samples/android" "github.com/llgcode/draw2d/samples/android"
"git.fromouter.space/crunchy-rocks/draw2d/samples/frameimage" "github.com/llgcode/draw2d/samples/frameimage"
"git.fromouter.space/crunchy-rocks/draw2d/samples/geometry" "github.com/llgcode/draw2d/samples/geometry"
"git.fromouter.space/crunchy-rocks/draw2d/samples/gopher" "github.com/llgcode/draw2d/samples/gopher"
"git.fromouter.space/crunchy-rocks/draw2d/samples/gopher2" "github.com/llgcode/draw2d/samples/gopher2"
"git.fromouter.space/crunchy-rocks/draw2d/samples/helloworld" "github.com/llgcode/draw2d/samples/helloworld"
"git.fromouter.space/crunchy-rocks/draw2d/samples/line" "github.com/llgcode/draw2d/samples/line"
"git.fromouter.space/crunchy-rocks/draw2d/samples/linecapjoin" "github.com/llgcode/draw2d/samples/linecapjoin"
"git.fromouter.space/crunchy-rocks/draw2d/samples/postscript" "github.com/llgcode/draw2d/samples/postscript"
) )
func TestSampleAndroid(t *testing.T) { func TestSampleAndroid(t *testing.T) {

View file

@ -4,12 +4,11 @@ package draw2d_test
import ( import (
"fmt" "fmt"
"github.com/llgcode/draw2d"
"github.com/llgcode/draw2d/draw2dimg"
"github.com/llgcode/draw2d/draw2dkit"
"image" "image"
"testing" "testing"
"git.fromouter.space/crunchy-rocks/draw2d"
"git.fromouter.space/crunchy-rocks/draw2d/draw2dimg"
"git.fromouter.space/crunchy-rocks/draw2d/draw2dkit"
) )
func TestSync(t *testing.T) { func TestSync(t *testing.T) {