From bcbf03f432a7346552e9649ccff32451c867fc7d Mon Sep 17 00:00:00 2001 From: Muhammad Khuzaima Umair Date: Sat, 14 Dec 2024 23:13:01 +0500 Subject: [PATCH 1/4] Update text position with alignment --- stl/geometry/text.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/stl/geometry/text.go b/stl/geometry/text.go index 65e83d0..811c9b1 100644 --- a/stl/geometry/text.go +++ b/stl/geometry/text.go @@ -26,6 +26,7 @@ type textRenderConfig struct { contextWidth int contextHeight int fontSize float64 + alignment gg.Align } // ImageConfig holds parameters for image rendering @@ -37,8 +38,7 @@ type imageRenderConfig struct { const ( imagePosition = 0.025 - usernameOffset = -0.01 - yearPosition = 0.77 + textPadding = 0.1 // 10% defaultContextWidth = 800 defaultContextHeight = 200 @@ -69,7 +69,7 @@ func Create3DText(username string, year string, innerWidth, baseHeight float64) usernameConfig := textRenderConfig{ renderConfig: renderConfig{ - startX: innerWidth * usernameOffset, + startX: innerWidth * textPadding, startY: -textDepthOffset / 2, startZ: baseHeight * usernameZOffset, voxelScale: textVoxelSize, @@ -79,11 +79,12 @@ func Create3DText(username string, year string, innerWidth, baseHeight float64) contextWidth: usernameContextWidth, contextHeight: usernameContextHeight, fontSize: usernameFontSize, + alignment: gg.AlignLeft, } yearConfig := textRenderConfig{ renderConfig: renderConfig{ - startX: innerWidth * yearPosition, + startX: innerWidth * (1-textPadding) - 75 , startY: -textDepthOffset / 2, startZ: baseHeight * yearZOffset, voxelScale: textVoxelSize * 0.75, @@ -93,6 +94,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 +131,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 From 4a7815d605895dcf46bbd9ea5fab7ddf2179e29b Mon Sep 17 00:00:00 2001 From: Muhammad Khuzaima Umair Date: Sat, 14 Dec 2024 18:35:21 +0000 Subject: [PATCH 2/4] Fix formatting --- stl/geometry/text.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/stl/geometry/text.go b/stl/geometry/text.go index 811c9b1..008dbd9 100644 --- a/stl/geometry/text.go +++ b/stl/geometry/text.go @@ -37,8 +37,8 @@ type imageRenderConfig struct { } const ( - imagePosition = 0.025 - textPadding = 0.1 // 10% + imagePosition = 0.025 + textPadding = 0.1 // 10% defaultContextWidth = 800 defaultContextHeight = 200 @@ -84,7 +84,7 @@ func Create3DText(username string, year string, innerWidth, baseHeight float64) yearConfig := textRenderConfig{ renderConfig: renderConfig{ - startX: innerWidth * (1-textPadding) - 75 , + startX: innerWidth*(1-textPadding) - 75, startY: -textDepthOffset / 2, startZ: baseHeight * yearZOffset, voxelScale: textVoxelSize * 0.75, From 55b903f1ad16a3059b51bcc0cc12daf4ff96a4dd Mon Sep 17 00:00:00 2001 From: Muhammad Khuzaima Umair Date: Sat, 28 Dec 2024 20:29:08 +0500 Subject: [PATCH 3/4] Refactor image rendering configuration to use width instead of height --- stl/geometry/text.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/stl/geometry/text.go b/stl/geometry/text.go index 008dbd9..1916972 100644 --- a/stl/geometry/text.go +++ b/stl/geometry/text.go @@ -33,7 +33,7 @@ type textRenderConfig struct { type imageRenderConfig struct { renderConfig imagePath string - height float64 + width float64 } const ( @@ -56,7 +56,7 @@ const ( yearFontSize = 56.0 yearZOffset = 0.4 - defaultImageHeight = 9.0 + defaultImageWidth = 9.2 defaultImageScale = 0.8 imageLeftMargin = 10.0 ) @@ -180,7 +180,7 @@ func GenerateImageGeometry(innerWidth, baseHeight float64) ([]types.Triangle, er depth: frontEmbedDepth, }, imagePath: imgPath, - height: defaultImageHeight, + width: defaultImageWidth, } defer cleanup() @@ -211,7 +211,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 From bca9ed9598f744225c9a48a1de1dd8c391d1e7ef Mon Sep 17 00:00:00 2001 From: Muhammad Khuzaima Umair Date: Sat, 28 Dec 2024 20:49:45 +0500 Subject: [PATCH 4/4] arc --- stl/geometry/text.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/stl/geometry/text.go b/stl/geometry/text.go index 1916972..63d3d69 100644 --- a/stl/geometry/text.go +++ b/stl/geometry/text.go @@ -38,7 +38,7 @@ type imageRenderConfig struct { const ( imagePosition = 0.025 - textPadding = 0.1 // 10% + gap = 0.05 // 5% defaultContextWidth = 800 defaultContextHeight = 200 @@ -69,7 +69,7 @@ func Create3DText(username string, year string, innerWidth, baseHeight float64) usernameConfig := textRenderConfig{ renderConfig: renderConfig{ - startX: innerWidth * textPadding, + startX: innerWidth*(2*gap) + defaultImageWidth*defaultImageScale, startY: -textDepthOffset / 2, startZ: baseHeight * usernameZOffset, voxelScale: textVoxelSize, @@ -82,9 +82,10 @@ func Create3DText(username string, year string, innerWidth, baseHeight float64) alignment: gg.AlignLeft, } + yearStartX := innerWidth*(1-gap) - (yearContextWidth*textVoxelSize*0.75/8) yearConfig := textRenderConfig{ renderConfig: renderConfig{ - startX: innerWidth*(1-textPadding) - 75, + startX: yearStartX, startY: -textDepthOffset / 2, startZ: baseHeight * yearZOffset, voxelScale: textVoxelSize * 0.75, @@ -173,7 +174,7 @@ 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,