Skip to content

Commit

Permalink
Give matrix instead of separated values to draw_first_line
Browse files Browse the repository at this point in the history
  • Loading branch information
liZe committed Jul 25, 2023
1 parent 50710de commit d001a23
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
13 changes: 3 additions & 10 deletions weasyprint/draw.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import operator
from colorsys import hsv_to_rgb, rgb_to_hsv
from io import BytesIO
from math import ceil, cos, floor, pi, sin, sqrt, tan
from math import ceil, floor, pi, sqrt, tan
from xml.etree import ElementTree

from PIL import Image
Expand Down Expand Up @@ -1073,7 +1073,7 @@ def draw_text(stream, textbox, offset_x, text_overflow, block_ellipsis):
textbox.pango_layout.reactivate(textbox.style)
stream.begin_text()
emojis = draw_first_line(
stream, textbox, text_overflow, block_ellipsis, x, y)
stream, textbox, text_overflow, block_ellipsis, Matrix(d=-1, e=x, f=y))
stream.end_text()

draw_emojis(stream, textbox.style['font_size'], x, y, emojis)
Expand All @@ -1097,8 +1097,7 @@ def draw_emojis(stream, font_size, x, y, emojis):
stream.pop_state()


def draw_first_line(stream, textbox, text_overflow, block_ellipsis, x, y,
angle=0, scale_x=1):
def draw_first_line(stream, textbox, text_overflow, block_ellipsis, matrix):
"""Draw the given ``textbox`` line to the document ``stream``."""
# Don’t draw lines with only invisible characters
if not textbox.text.strip():
Expand Down Expand Up @@ -1152,12 +1151,6 @@ def draw_first_line(stream, textbox, text_overflow, block_ellipsis, x, y,

utf8_text = textbox.pango_layout.text.encode()
previous_utf8_position = 0

matrix = Matrix(scale_x, 0, 0, -1, x, y)
if angle:
a, c = cos(angle), sin(angle)
b, d = -c, a
matrix = Matrix(a, b, c, d) @ matrix
stream.text_matrix(*matrix.values)
last_font = None
string = ''
Expand Down
10 changes: 7 additions & 3 deletions weasyprint/svg/text.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
"""Draw text."""

from math import inf, radians
from math import cos, inf, radians, sin

from ..matrix import Matrix
from .bounding_box import EMPTY_BOUNDING_BOX, extend_bounding_box
from .utils import normalize, size

Expand Down Expand Up @@ -187,9 +188,12 @@ def text(svg, node, font_size):

layout.reactivate(style)
svg.fill_stroke(node, font_size, text=True)
matrix = Matrix(a=scale_x, d=-1, e=x_position, f=y_position)
if angle:
a, c = cos(angle), sin(angle)
matrix = Matrix(a, -c, c, a) @ matrix
emojis = draw_first_line(
svg.stream, TextBox(layout, style), 'none', 'none',
x_position, y_position, angle, scale_x)
svg.stream, TextBox(layout, style), 'none', 'none', matrix)
emoji_lines.append((font_size, x, y, emojis))
svg.cursor_position = cursor_position

Expand Down

0 comments on commit d001a23

Please sign in to comment.