Skip to content

Commit

Permalink
up: vertical-position-of-text ^^
Browse files Browse the repository at this point in the history
- 最初の 1 行も縦方向中央揃えになるように変更 ^^
  • Loading branch information
taniiicom committed Apr 24, 2024
1 parent 781ac54 commit 5e36050
Showing 1 changed file with 1 addition and 3 deletions.
4 changes: 1 addition & 3 deletions src/domain/TextEmoji/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,13 @@ func drawText(c *freetype.Context, font *truetype.Font, text string, width int)

// fontSize, yPos: y 座標 を定義
var fontSize float64
var yPos float64

// fontSize, yPos を計算
if len(lines) == 0 {
// err
return fmt.Errorf("too few lines")
} else if len(lines) < 4 {
fontSize = (CANVAS_HEIGHT) / float64(len(lines))
yPos = float64(fontSize)
} else {
// err
return fmt.Errorf("too many lines")
Expand All @@ -145,7 +143,7 @@ func drawText(c *freetype.Context, font *truetype.Font, text string, width int)
// スケールに基づいてフォントサイズを調整
c.SetFontSize(fontSize * scale)
// テキストを中央揃えで描画するための開始ポイントを計算
pt := freetype.Pt(int(math.Round((float64(CANVAS_WIDTH)-(float64(txtWidth)*scale))/2)), int(yPos)+i*int(fontSize*scale))
pt := freetype.Pt(int(math.Round((float64(CANVAS_WIDTH)-(float64(txtWidth)*scale))/2)), (i+1)*int(fontSize*scale))
_, err := c.DrawString(line, pt)
if err != nil {
return err
Expand Down

0 comments on commit 5e36050

Please sign in to comment.