Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions stl/geometry/text.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,19 @@ type textRenderConfig struct {
contextWidth int
contextHeight int
fontSize float64
alignment gg.Align
}

// ImageConfig holds parameters for image rendering
type imageRenderConfig struct {
renderConfig
imagePath string
height float64
width float64
}

const (
imagePosition = 0.025
usernameOffset = -0.01
yearPosition = 0.77
imagePosition = 0.025
gap = 0.05 // 5%

defaultContextWidth = 800
defaultContextHeight = 200
Expand All @@ -56,7 +56,7 @@ const (
yearFontSize = 56.0
yearZOffset = 0.4

defaultImageHeight = 9.0
defaultImageWidth = 9.2
defaultImageScale = 0.8
imageLeftMargin = 10.0
)
Expand All @@ -69,7 +69,7 @@ func Create3DText(username string, year string, innerWidth, baseHeight float64)

usernameConfig := textRenderConfig{
renderConfig: renderConfig{
startX: innerWidth * usernameOffset,
startX: innerWidth*(2*gap) + defaultImageWidth*defaultImageScale,
startY: -textDepthOffset / 2,
startZ: baseHeight * usernameZOffset,
voxelScale: textVoxelSize,
Expand All @@ -79,11 +79,13 @@ func Create3DText(username string, year string, innerWidth, baseHeight float64)
contextWidth: usernameContextWidth,
contextHeight: usernameContextHeight,
fontSize: usernameFontSize,
alignment: gg.AlignLeft,
}

yearStartX := innerWidth*(1-gap) - (yearContextWidth*textVoxelSize*0.75/8)
yearConfig := textRenderConfig{
renderConfig: renderConfig{
startX: innerWidth * yearPosition,
startX: yearStartX,
startY: -textDepthOffset / 2,
startZ: baseHeight * yearZOffset,
voxelScale: textVoxelSize * 0.75,
Expand All @@ -93,6 +95,7 @@ func Create3DText(username string, year string, innerWidth, baseHeight float64)
contextWidth: yearContextWidth,
contextHeight: yearContextHeight,
fontSize: yearFontSize,
alignment: gg.AlignRight,
}

usernameTriangles, err := renderText(usernameConfig)
Expand Down Expand Up @@ -129,7 +132,7 @@ func renderText(config textRenderConfig) ([]types.Triangle, error) {
dc.SetRGB(0, 0, 0)
dc.Clear()
dc.SetRGB(1, 1, 1)
dc.DrawStringAnchored(config.text, float64(config.contextWidth)/8, float64(config.contextHeight)/2, 0.0, 0.5)
dc.DrawStringWrapped(config.text, 0, float64(config.contextHeight)/2, 0.0, 0.5, float64(config.contextWidth), 1.5, config.alignment)

var triangles []types.Triangle

Expand Down Expand Up @@ -171,14 +174,14 @@ func GenerateImageGeometry(innerWidth, baseHeight float64) ([]types.Triangle, er

config := imageRenderConfig{
renderConfig: renderConfig{
startX: innerWidth * imagePosition,
startX: innerWidth * gap,
startY: -frontEmbedDepth / 2.0,
startZ: -0.85 * baseHeight,
voxelScale: defaultImageScale,
depth: frontEmbedDepth,
},
imagePath: imgPath,
height: defaultImageHeight,
width: defaultImageWidth,
}

defer cleanup()
Expand Down Expand Up @@ -209,7 +212,7 @@ func renderImage(config imageRenderConfig) ([]types.Triangle, error) {
width := bounds.Max.X
height := bounds.Max.Y

scale := config.height / float64(height)
scale := config.width / float64(width)

var triangles []types.Triangle

Expand Down