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
import (
"git.fromouter.space/crunchy-rocks/draw2d"
"github.com/llgcode/draw2d"
)
// Liner receive segment definition

View file

@ -8,9 +8,9 @@ import (
"image"
"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}
@ -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)
}
/**
* Create a new Graphic context from an image
*/

View file

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

View file

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

View file

@ -8,12 +8,12 @@ import (
"math"
"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/golang/freetype/raster"
"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/math/fixed"

View file

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

View file

@ -2,14 +2,13 @@ package draw2dimg
import (
"fmt"
"github.com/golang/freetype/truetype"
"github.com/llgcode/draw2d"
"github.com/llgcode/draw2d/draw2dkit"
"golang.org/x/image/font/gofont/goregular"
"image"
"image/color"
"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

View file

@ -9,12 +9,11 @@ import (
"log"
"math"
"git.fromouter.space/crunchy-rocks/draw2d"
"git.fromouter.space/crunchy-rocks/draw2d/draw2dbase"
"git.fromouter.space/crunchy-rocks/emoji"
"github.com/llgcode/draw2d"
"github.com/llgcode/draw2d/draw2dbase"
"git.fromouter.space/crunchy-rocks/freetype/raster"
"git.fromouter.space/crunchy-rocks/freetype/truetype"
"github.com/golang/freetype/raster"
"github.com/golang/freetype/truetype"
"golang.org/x/image/draw"
"golang.org/x/image/font"
@ -35,11 +34,10 @@ type GraphicContext struct {
painter Painter
fillRasterizer *raster.Rasterizer
strokeRasterizer *raster.Rasterizer
FontCache draw2d.FontCache
FontCache draw2d.FontCache
glyphCache draw2dbase.GlyphCache
glyphBuf *truetype.GlyphBuf
DPI int
Emojis emoji.Table
}
// ImageFilter defines the type of filter to use
@ -56,6 +54,7 @@ const (
// NewGraphicContext creates a new Graphic context from an image.
func NewGraphicContext(img draw.Image) *GraphicContext {
var painter Painter
switch selectImage := img.(type) {
case *image.RGBA:
@ -80,7 +79,6 @@ func NewGraphicContextWithPainter(img draw.Image, painter Painter) *GraphicConte
draw2dbase.NewGlyphCache(),
&truetype.GlyphBuf{},
dpi,
make(emoji.Table),
}
return gc
}
@ -126,9 +124,6 @@ func (gc *GraphicContext) FillString(text string) (width float64) {
return gc.FillStringAt(text, 0, 0)
}
const emojiSpacing = 10
const emojiScale = 110
// FillStringAt draws the text at the specified point (x, y)
func (gc *GraphicContext) FillStringAt(text string, x, y float64) (width float64) {
f, err := gc.loadCurrentFont()
@ -139,25 +134,12 @@ func (gc *GraphicContext) FillStringAt(text string, x, y float64) (width float64
startx := x
prev, hasPrev := truetype.Index(0), false
fontName := gc.GetFontName()
for fragment := range gc.Emojis.Iterate(text) {
if fragment.IsEmoji {
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)
for _, r := range text {
index := f.Index(r)
if hasPrev {
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)
prev, hasPrev = index, true
}

View file

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

View file

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

View file

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

View file

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

View file

@ -4,17 +4,16 @@
package draw2dsvg
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"
"log"
"math"
"strconv"
"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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -6,11 +6,11 @@ import (
"log"
"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/glfw/v3.1/glfw"
"github.com/llgcode/draw2d"
"github.com/llgcode/draw2d/draw2dgl"
"github.com/llgcode/draw2d/draw2dkit"
)
var (

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -4,12 +4,11 @@ package draw2d_test
import (
"fmt"
"github.com/llgcode/draw2d"
"github.com/llgcode/draw2d/draw2dimg"
"github.com/llgcode/draw2d/draw2dkit"
"image"
"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) {