1
1
mirror of https://github.com/Kozea/WeasyPrint.git synced 2024-09-11 20:47:56 +03:00

Give matrix instead of separated values to draw_first_line

This commit is contained in:
Guillaume Ayoub 2023-07-25 14:46:18 +02:00
parent 50710de8e9
commit d001a23ead
2 changed files with 10 additions and 13 deletions

View File

@ -4,7 +4,7 @@ import contextlib
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
@ -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)
@ -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``."""
# Dont draw lines with only invisible characters
if not textbox.text.strip():
@ -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 = ''

View File

@ -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
@ -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