Skip to content

Commit bb93555

Browse files
committed
fix(hyphen): fix hypen added if the lyrics IS the end of margin
1 parent 4918888 commit bb93555

1 file changed

Lines changed: 19 additions & 14 deletions

File tree

internal/lyric/hypen.go

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,17 @@ func (li *lyricInteractor) CalculateHypen(ctx context.Context, prevLyric, curren
2424
startPosition := prevLyric.Coordinate.X + li.CalculateLyricWidth(lyricText)
2525
endPostion := currentLyric.Coordinate.X
2626
distance := endPostion - startPosition
27-
if distance < 4 { // because the current length of the - is 5.47
27+
if distance < 4 {
28+
29+
// force add hyphen at the end if the lyric near the end margin
30+
if endPostion == float64(constant.LAYOUT_WIDTH-constant.LAYOUT_INDENT_LENGTH) {
31+
return []entity.Coordinate{
32+
entity.Coordinate{
33+
X: startPosition,
34+
Y: currentLyric.Coordinate.Y,
35+
},
36+
}
37+
}
2838
return nil
2939
}
3040

@@ -64,14 +74,16 @@ func (li *lyricInteractor) RenderHypen(ctx context.Context, canv canvas.Canvas,
6474

6575
// for tracking the pair of begin to end
6676
hs := NewHypenStack()
67-
lastYPos := float64(0)
77+
baseYPos := float64(0)
78+
var lastLyric []entity.Lyric
6879
hypenLocation := []entity.Coordinate{}
6980
for _, n := range measure {
7081

7182
if len(n.Lyric) == 0 {
7283
continue
7384
}
7485

86+
lastLyric = n.Lyric
7587
for i, l := range n.Lyric {
7688
hs.Process(ctx, l.Syllabic)
7789
if len(pos[i]) == 0 {
@@ -121,7 +133,6 @@ func (li *lyricInteractor) RenderHypen(ctx context.Context, canv canvas.Canvas,
121133
Lyrics: l,
122134
}
123135
pos[i] = pair
124-
lastYPos = float64(n.PositionY) + 25 + float64(i*20)
125136
continue
126137
}
127138
if pair[1] == nil {
@@ -140,28 +151,22 @@ func (li *lyricInteractor) RenderHypen(ctx context.Context, canv canvas.Canvas,
140151
}
141152
}
142153
pos[i] = pair
143-
lastYPos = float64(n.PositionY) + 25 + float64(i*20)
154+
baseYPos = float64(n.PositionY) + 25
144155
}
145156

146157
}
147158

148159
if len(pos) > 0 { // add unpaired syllable before move on to next staff
149-
for _, p := range pos {
160+
for i, p := range pos {
150161
if p[0] != nil && p[1] == nil { // append to end of file
151162
lastXHypen := float64(constant.LAYOUT_WIDTH - constant.LAYOUT_INDENT_LENGTH)
152163

153-
lastNote := measure[len(measure)-1]
154-
if lastNote.Articulation != nil && lastNote.Articulation.BreathMark != nil {
155-
lastNote = measure[len(measure)-2]
156-
}
157-
158-
lyricWidth := li.CalculateWholeLyricGroupLength(lastNote.Lyric)
159164
pEnd := LyricPosition{
160165
Coordinate: entity.Coordinate{
161-
X: lastXHypen + lyricWidth,
162-
Y: lastYPos,
166+
X: lastXHypen,
167+
Y: baseYPos + float64(i*20),
163168
},
164-
Lyrics: entity.Lyric{},
169+
Lyrics: lastLyric[i],
165170
}
166171
hypenLocation = append(li.CalculateHypen(ctx, p[0], &pEnd), hypenLocation...)
167172

0 commit comments

Comments
 (0)