@@ -44,8 +44,6 @@ def text(svg, node, font_size):
44
44
45
45
layout , _ , _ , width , height , _ = split_first_line (
46
46
node .text , style , svg .context , inf , 0 )
47
- # TODO: get real values
48
- x_bearing , y_bearing = 0 , 0
49
47
50
48
# Get rotations and translations
51
49
x , y , dx , dy , rotate = [], [], [], [], [0 ]
@@ -89,19 +87,8 @@ def text(svg, node, font_size):
89
87
letter_spacing = (text_length - width ) / spaces_count
90
88
width = text_length
91
89
92
- # Align text box horizontally
93
- x_align = 0
94
- text_anchor = node .get ('text-anchor' )
95
90
# TODO: use real values
96
91
ascent , descent = font_size * .8 , font_size * .2
97
- if text_anchor == 'middle' :
98
- x_align = - (width / 2 + x_bearing )
99
- if letter_spacing and node .text :
100
- x_align -= (len (node .text ) - 1 ) * letter_spacing / 2
101
- elif text_anchor == 'end' :
102
- x_align = - (width + x_bearing )
103
- if letter_spacing and node .text :
104
- x_align -= (len (node .text ) - 1 ) * letter_spacing
105
92
106
93
# Align text box vertically
107
94
# TODO: This is a hack. Other baseline alignment tags are not supported.
@@ -111,11 +98,11 @@ def text(svg, node, font_size):
111
98
alignment_baseline = node .get (
112
99
'dominant-baseline' , node .get ('alignment-baseline' ))
113
100
if display_anchor == 'middle' :
114
- y_align = - height / 2 - y_bearing
101
+ y_align = - height / 2
115
102
elif display_anchor == 'top' :
116
- y_align = - y_bearing
103
+ pass
117
104
elif display_anchor == 'bottom' :
118
- y_align = - height - y_bearing
105
+ y_align = - height
119
106
elif alignment_baseline in ('central' , 'middle' ):
120
107
# TODO: This is wrong, we use font top-to-bottom
121
108
y_align = (ascent + descent ) / 2 - descent
@@ -157,16 +144,14 @@ def text(svg, node, font_size):
157
144
width *= scale_x
158
145
if i :
159
146
x += letter_spacing
147
+ svg .cursor_position = x + width , y
160
148
161
- x_position = x + svg .cursor_d_position [0 ] + x_align
149
+ x_position = x + svg .cursor_d_position [0 ]
162
150
y_position = y + svg .cursor_d_position [1 ] + y_align
163
- cursor_position = x + width , y
164
151
angle = last_r if r is None else r
165
152
points = (
166
- (cursor_position [0 ] + x_align + svg .cursor_d_position [0 ],
167
- cursor_position [1 ] + y_align + svg .cursor_d_position [1 ]),
168
- (cursor_position [0 ] + x_align + width + svg .cursor_d_position [0 ],
169
- cursor_position [1 ] + y_align + height + svg .cursor_d_position [1 ]))
153
+ (x_position , y_position ),
154
+ (x_position + width , y_position - height ))
170
155
node .text_bounding_box = extend_bounding_box (
171
156
node .text_bounding_box , points )
172
157
@@ -179,7 +164,6 @@ def text(svg, node, font_size):
179
164
emojis = draw_first_line (
180
165
svg .stream , TextBox (layout , style ), 'none' , 'none' , matrix )
181
166
emoji_lines .append ((font_size , x , y , emojis ))
182
- svg .cursor_position = cursor_position
183
167
184
168
svg .stream .end_text ()
185
169
svg .stream .pop_state ()
0 commit comments