Compare commits
2 commits
f52c8a71af
...
e3566f7fc4
Author | SHA1 | Date | |
---|---|---|---|
e3566f7fc4 | |||
219501b99b |
31 changed files with 118 additions and 97 deletions
|
@ -4,7 +4,7 @@
|
|||
package draw2dbase
|
||||
|
||||
import (
|
||||
"github.com/llgcode/draw2d"
|
||||
"git.fromouter.space/crunchy-rocks/draw2d"
|
||||
)
|
||||
|
||||
// Liner receive segment definition
|
||||
|
|
|
@ -8,9 +8,9 @@ import (
|
|||
"image"
|
||||
"image/color"
|
||||
|
||||
"github.com/llgcode/draw2d"
|
||||
"git.fromouter.space/crunchy-rocks/draw2d"
|
||||
|
||||
"github.com/golang/freetype/truetype"
|
||||
"git.fromouter.space/crunchy-rocks/freetype/truetype"
|
||||
)
|
||||
|
||||
var DefaultFontData = draw2d.FontData{Name: "luxi", Family: draw2d.FontFamilySans, Style: draw2d.FontStyleNormal}
|
||||
|
@ -47,7 +47,6 @@ 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
|
||||
*/
|
||||
|
|
|
@ -6,7 +6,7 @@ package draw2dbase
|
|||
import (
|
||||
"math"
|
||||
|
||||
"github.com/llgcode/draw2d"
|
||||
"git.fromouter.space/crunchy-rocks/draw2d"
|
||||
)
|
||||
|
||||
type LineStroker struct {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package draw2dbase
|
||||
|
||||
import "github.com/llgcode/draw2d"
|
||||
import "git.fromouter.space/crunchy-rocks/draw2d"
|
||||
|
||||
// GlyphCache manage a cache of glyphs
|
||||
type GlyphCache interface {
|
||||
|
@ -13,11 +13,10 @@ 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,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package draw2dgl
|
||||
|
||||
import (
|
||||
"github.com/golang/freetype/truetype"
|
||||
"github.com/llgcode/draw2d"
|
||||
"git.fromouter.space/crunchy-rocks/draw2d"
|
||||
"git.fromouter.space/crunchy-rocks/freetype/truetype"
|
||||
|
||||
"golang.org/x/image/math/fixed"
|
||||
)
|
||||
|
|
|
@ -2,13 +2,14 @@ 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
|
||||
|
|
|
@ -9,11 +9,12 @@ import (
|
|||
"log"
|
||||
"math"
|
||||
|
||||
"github.com/llgcode/draw2d"
|
||||
"github.com/llgcode/draw2d/draw2dbase"
|
||||
"git.fromouter.space/crunchy-rocks/draw2d"
|
||||
"git.fromouter.space/crunchy-rocks/draw2d/draw2dbase"
|
||||
"git.fromouter.space/crunchy-rocks/emoji"
|
||||
|
||||
"github.com/golang/freetype/raster"
|
||||
"github.com/golang/freetype/truetype"
|
||||
"git.fromouter.space/crunchy-rocks/freetype/raster"
|
||||
"git.fromouter.space/crunchy-rocks/freetype/truetype"
|
||||
|
||||
"golang.org/x/image/draw"
|
||||
"golang.org/x/image/font"
|
||||
|
@ -38,6 +39,7 @@ type GraphicContext struct {
|
|||
glyphCache draw2dbase.GlyphCache
|
||||
glyphBuf *truetype.GlyphBuf
|
||||
DPI int
|
||||
Emojis emoji.Table
|
||||
}
|
||||
|
||||
// ImageFilter defines the type of filter to use
|
||||
|
@ -54,7 +56,6 @@ 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:
|
||||
|
@ -79,6 +80,7 @@ func NewGraphicContextWithPainter(img draw.Image, painter Painter) *GraphicConte
|
|||
draw2dbase.NewGlyphCache(),
|
||||
&truetype.GlyphBuf{},
|
||||
dpi,
|
||||
make(emoji.Table),
|
||||
}
|
||||
return gc
|
||||
}
|
||||
|
@ -124,6 +126,9 @@ 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()
|
||||
|
@ -134,12 +139,25 @@ func (gc *GraphicContext) FillStringAt(text string, x, y float64) (width float64
|
|||
startx := x
|
||||
prev, hasPrev := truetype.Index(0), false
|
||||
fontName := gc.GetFontName()
|
||||
for _, r := range text {
|
||||
index := f.Index(r)
|
||||
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)
|
||||
if hasPrev {
|
||||
x += fUnitsToFloat64(f.Kern(fixed.Int26_6(gc.Current.Scale), prev, index))
|
||||
}
|
||||
glyph := gc.glyphCache.Fetch(gc, fontName, r)
|
||||
glyph := gc.glyphCache.Fetch(gc, fontName, fragment.Rune)
|
||||
x += glyph.Fill(gc, x, y)
|
||||
prev, hasPrev = index, true
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
package draw2dimg
|
||||
|
||||
import (
|
||||
"github.com/golang/freetype/raster"
|
||||
"git.fromouter.space/crunchy-rocks/freetype/raster"
|
||||
"golang.org/x/image/math/fixed"
|
||||
)
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package draw2dimg
|
||||
|
||||
import (
|
||||
"github.com/golang/freetype/truetype"
|
||||
"github.com/llgcode/draw2d"
|
||||
"git.fromouter.space/crunchy-rocks/draw2d"
|
||||
"git.fromouter.space/crunchy-rocks/freetype/truetype"
|
||||
|
||||
"golang.org/x/image/math/fixed"
|
||||
)
|
||||
|
|
|
@ -14,7 +14,7 @@ import (
|
|||
"os"
|
||||
"strconv"
|
||||
|
||||
"github.com/golang/freetype/truetype"
|
||||
"git.fromouter.space/crunchy-rocks/freetype/truetype"
|
||||
|
||||
"github.com/jung-kurt/gofpdf"
|
||||
"github.com/llgcode/draw2d"
|
||||
|
|
|
@ -7,13 +7,14 @@ 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 {
|
||||
|
|
|
@ -4,16 +4,17 @@
|
|||
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
|
||||
|
|
|
@ -7,16 +7,16 @@ package draw2dsvg_test
|
|||
import (
|
||||
"testing"
|
||||
|
||||
"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"
|
||||
"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"
|
||||
)
|
||||
|
||||
func TestSampleAndroid(t *testing.T) {
|
||||
|
|
|
@ -9,8 +9,8 @@ package draw2dsvg_test
|
|||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/llgcode/draw2d"
|
||||
"github.com/llgcode/draw2d/draw2dsvg"
|
||||
"git.fromouter.space/crunchy-rocks/draw2d"
|
||||
"git.fromouter.space/crunchy-rocks/draw2d/draw2dsvg"
|
||||
)
|
||||
|
||||
type sample func(gc draw2d.GraphicContext, ext string) (string, error)
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
package draw2dsvg
|
||||
|
||||
import (
|
||||
"github.com/golang/freetype/truetype"
|
||||
"github.com/llgcode/draw2d"
|
||||
"git.fromouter.space/crunchy-rocks/draw2d"
|
||||
"git.fromouter.space/crunchy-rocks/freetype/truetype"
|
||||
"golang.org/x/image/math/fixed"
|
||||
)
|
||||
|
||||
|
|
3
font.go
3
font.go
|
@ -8,8 +8,9 @@ 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
|
||||
|
|
|
@ -8,9 +8,9 @@ import (
|
|||
"image/color"
|
||||
"math"
|
||||
|
||||
"github.com/llgcode/draw2d"
|
||||
"github.com/llgcode/draw2d/draw2dkit"
|
||||
"github.com/llgcode/draw2d/samples"
|
||||
"git.fromouter.space/crunchy-rocks/draw2d"
|
||||
"git.fromouter.space/crunchy-rocks/draw2d/draw2dkit"
|
||||
"git.fromouter.space/crunchy-rocks/draw2d/samples"
|
||||
)
|
||||
|
||||
// Main draws a droid and returns the filename. This should only be
|
||||
|
|
|
@ -9,9 +9,9 @@ import (
|
|||
"image/png"
|
||||
"net/http"
|
||||
|
||||
"github.com/llgcode/draw2d/draw2dimg"
|
||||
"github.com/llgcode/draw2d/draw2dpdf"
|
||||
"github.com/llgcode/draw2d/samples/android"
|
||||
"git.fromouter.space/crunchy-rocks/draw2d/draw2dimg"
|
||||
"git.fromouter.space/crunchy-rocks/draw2d/draw2dpdf"
|
||||
"git.fromouter.space/crunchy-rocks/draw2d/samples/android"
|
||||
|
||||
"appengine"
|
||||
)
|
||||
|
|
|
@ -7,10 +7,10 @@ package frameimage
|
|||
import (
|
||||
"math"
|
||||
|
||||
"github.com/llgcode/draw2d"
|
||||
"github.com/llgcode/draw2d/draw2dimg"
|
||||
"github.com/llgcode/draw2d/draw2dkit"
|
||||
"github.com/llgcode/draw2d/samples"
|
||||
"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"
|
||||
)
|
||||
|
||||
// Main draws the image frame and returns the filename.
|
||||
|
|
|
@ -9,10 +9,10 @@ import (
|
|||
"image/color"
|
||||
"math"
|
||||
|
||||
"github.com/llgcode/draw2d"
|
||||
"github.com/llgcode/draw2d/draw2dkit"
|
||||
"github.com/llgcode/draw2d/samples"
|
||||
"github.com/llgcode/draw2d/samples/gopher2"
|
||||
"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"
|
||||
)
|
||||
|
||||
// Main draws geometry and returns the filename. This should only be
|
||||
|
|
|
@ -8,8 +8,8 @@ package gopher
|
|||
import (
|
||||
"image/color"
|
||||
|
||||
"github.com/llgcode/draw2d"
|
||||
"github.com/llgcode/draw2d/samples"
|
||||
"git.fromouter.space/crunchy-rocks/draw2d"
|
||||
"git.fromouter.space/crunchy-rocks/draw2d/samples"
|
||||
)
|
||||
|
||||
// Main draws a left hand and ear of a gopher. Afterwards it returns
|
||||
|
|
|
@ -10,9 +10,9 @@ import (
|
|||
"image/color"
|
||||
"math"
|
||||
|
||||
"github.com/llgcode/draw2d"
|
||||
"github.com/llgcode/draw2d/draw2dkit"
|
||||
"github.com/llgcode/draw2d/samples"
|
||||
"git.fromouter.space/crunchy-rocks/draw2d"
|
||||
"git.fromouter.space/crunchy-rocks/draw2d/draw2dkit"
|
||||
"git.fromouter.space/crunchy-rocks/draw2d/samples"
|
||||
)
|
||||
|
||||
// Main draws a rotated face of the gopher. Afterwards it returns
|
||||
|
|
|
@ -9,9 +9,9 @@ import (
|
|||
"fmt"
|
||||
"image"
|
||||
|
||||
"github.com/llgcode/draw2d"
|
||||
"github.com/llgcode/draw2d/draw2dkit"
|
||||
"github.com/llgcode/draw2d/samples"
|
||||
"git.fromouter.space/crunchy-rocks/draw2d"
|
||||
"git.fromouter.space/crunchy-rocks/draw2d/draw2dkit"
|
||||
"git.fromouter.space/crunchy-rocks/draw2d/samples"
|
||||
)
|
||||
|
||||
// Main draws "Hello World" and returns the filename. This should only be
|
||||
|
|
|
@ -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 (
|
||||
|
|
|
@ -7,9 +7,9 @@ package line
|
|||
import (
|
||||
"image/color"
|
||||
|
||||
"github.com/llgcode/draw2d"
|
||||
"github.com/llgcode/draw2d/draw2dkit"
|
||||
"github.com/llgcode/draw2d/samples"
|
||||
"git.fromouter.space/crunchy-rocks/draw2d"
|
||||
"git.fromouter.space/crunchy-rocks/draw2d/draw2dkit"
|
||||
"git.fromouter.space/crunchy-rocks/draw2d/samples"
|
||||
)
|
||||
|
||||
// Main draws vertically spaced lines and returns the filename.
|
||||
|
|
|
@ -7,8 +7,8 @@ package linecapjoin
|
|||
import (
|
||||
"image/color"
|
||||
|
||||
"github.com/llgcode/draw2d"
|
||||
"github.com/llgcode/draw2d/samples"
|
||||
"git.fromouter.space/crunchy-rocks/draw2d"
|
||||
"git.fromouter.space/crunchy-rocks/draw2d/samples"
|
||||
)
|
||||
|
||||
// Main draws the different line caps and joins.
|
||||
|
|
|
@ -8,8 +8,8 @@ import (
|
|||
|
||||
"github.com/llgcode/ps"
|
||||
|
||||
"github.com/llgcode/draw2d"
|
||||
"github.com/llgcode/draw2d/samples"
|
||||
"git.fromouter.space/crunchy-rocks/draw2d"
|
||||
"git.fromouter.space/crunchy-rocks/draw2d/samples"
|
||||
)
|
||||
|
||||
// Main draws the tiger
|
||||
|
|
|
@ -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"
|
||||
)
|
||||
|
||||
|
|
|
@ -5,16 +5,16 @@ package draw2d_test
|
|||
import (
|
||||
"testing"
|
||||
|
||||
"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"
|
||||
"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"
|
||||
)
|
||||
|
||||
func TestSampleAndroid(t *testing.T) {
|
||||
|
|
|
@ -4,11 +4,12 @@ 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) {
|
||||
|
|
Loading…
Reference in a new issue