draw2d icon indicating copy to clipboard operation
draw2d copied to clipboard

Font path

Open llgcode opened this issue 10 years ago • 5 comments

Specify the font to use specifying a path or a font object

llgcode avatar Apr 22 '15 12:04 llgcode

I just had a problem related to this, that draw2d couldn't find the fonts. I resolved it with this bit of code:

import (
    "go/build"
    "path/filepath"
)

func setupDraw2D() {
    p, err := build.Default.Import("github.com/llgcode/draw2d", "", build.FindOnly)
    if err != nil {
        log.Fatalf("Couldn't find llgcode/draw2d files: %v", err)
    }

    draw2d.SetFontFolder(filepath.Join(p.Dir, "resource", "font"))
}

Perhaps the draw2d could do this itself, to ensure it has the correct path to the fonts directory?

bramp avatar Jul 13 '15 14:07 bramp

Today font could be anywhere. Le 13 juil. 2015 16:20, "Andrew Brampton" [email protected] a écrit :

I just had a problem related to this, that draw2d couldn't find the fonts. I resolved it with this bit of code:

import ( "go/build" "path/filepath" ) func setupDraw2D() { p, err := build.Default.Import("github.com/llgcode/draw2d", "", build.FindOnly) if err != nil { log.Fatalf("Couldn't find llgcode/draw2d files: %v", err) }

draw2d.SetFontFolder(filepath.Join(p.Dir, "resource", "font"))

}

Perhaps the draw2d could do this itself, to ensure it has the correct path to the fonts directory?

— Reply to this email directly or view it on GitHub https://github.com/llgcode/draw2d/issues/40#issuecomment-120943548.

llgcode avatar Jul 13 '15 15:07 llgcode

ah, but the default of "./resources/font/" does not work for anyone who path is outside of your directory. This code makes the path somewhat agnostic, but is still a bit of a hack.

bramp avatar Jul 13 '15 15:07 bramp

Would you accept a pull request that specifies a new type to handle font naming?

type FontNamerFunc func(fontData FontData) string

This would let anyone change how fonts are found.

stephenwithav avatar Aug 09 '15 15:08 stephenwithav

Yes, It's a great idea. Thanks

-- Laurent.

On 9 August 2015 at 17:41, Steven Edwards [email protected] wrote:

Would you accept a pull request that specifies a new type to handle font naming?

type FontNamerFunc func(fontData FontData) string

This would let anyone change how fonts are found.

— Reply to this email directly or view it on GitHub https://github.com/llgcode/draw2d/issues/40#issuecomment-129199598.

llgcode avatar Aug 09 '15 19:08 llgcode