diff --git a/stl/geometry/text.go b/stl/geometry/text.go index 65e83d0..63d3d69 100644 --- a/stl/geometry/text.go +++ b/stl/geometry/text.go @@ -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 @@ -56,7 +56,7 @@ const ( yearFontSize = 56.0 yearZOffset = 0.4 - defaultImageHeight = 9.0 + defaultImageWidth = 9.2 defaultImageScale = 0.8 imageLeftMargin = 10.0 ) @@ -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, @@ -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, @@ -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) @@ -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 @@ -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() @@ -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