From 36e4726808b1ad51f67285b30cd7ad905f117345 Mon Sep 17 00:00:00 2001 From: Gaurav Samudra <60246931+gauravsamudra@users.noreply.github.com> Date: Sun, 24 Sep 2023 21:26:06 -0400 Subject: [PATCH 1/4] first attempt --- pyproject.toml | 2 +- weasyprint/draw.py | 24 +++++++++++++++++++++--- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 570aef8af..fe73db7d1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -12,7 +12,7 @@ requires-python = '>=3.7' readme = {file = 'README.rst', content-type = 'text/x-rst'} license = {file = 'LICENSE'} dependencies = [ - 'pydyf >=0.6.0', + 'pydyf >=0.8.0', 'cffi >=0.6', 'html5lib >=1.1', 'tinycss2 >=1.0.0', diff --git a/weasyprint/draw.py b/weasyprint/draw.py index 44d94575f..c832c4880 100644 --- a/weasyprint/draw.py +++ b/weasyprint/draw.py @@ -1179,9 +1179,27 @@ def draw_first_line(stream, textbox, text_overflow, block_ellipsis, matrix): utf8_position = utf8_positions[i] offset = glyph_info.geometry.x_offset / font_size - if offset: - string += f'>{-offset}<' - string += f'{glyph:02x}' if font.bitmap else f'{glyph:04x}' + + offset_y = glyph_info.geometry.y_offset / font_size / textbox.height + if offset_y: + if string[-1] == '<': + string = string[:-1] + else: + string += '>' + stream.show_text(string) + stream.set_rise(-offset_y) + string = '' + if offset: + string = f'{-offset}' + string += f'<{glyph:02x}>' if font.bitmap else f'<{glyph:04x}>' + stream.show_text(string) + stream.set_rise(0) + stream.set_rise(0) + string = '<' + else: + if offset: + string += f'>{-offset}<' + string += f'{glyph:02x}' if font.bitmap else f'{glyph:04x}' # Ink bounding box and logical widths in font if glyph not in font.widths: From 95e935a901f467484e0292e99d7fbe123e0351b7 Mon Sep 17 00:00:00 2001 From: Gaurav Samudra <60246931+gauravsamudra@users.noreply.github.com> Date: Sun, 24 Sep 2023 21:27:44 -0400 Subject: [PATCH 2/4] fix method name - set_text_rise --- weasyprint/draw.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/weasyprint/draw.py b/weasyprint/draw.py index c832c4880..8f4b2c574 100644 --- a/weasyprint/draw.py +++ b/weasyprint/draw.py @@ -1187,14 +1187,14 @@ def draw_first_line(stream, textbox, text_overflow, block_ellipsis, matrix): else: string += '>' stream.show_text(string) - stream.set_rise(-offset_y) + stream.set_text_rise(-offset_y) string = '' if offset: string = f'{-offset}' string += f'<{glyph:02x}>' if font.bitmap else f'<{glyph:04x}>' stream.show_text(string) - stream.set_rise(0) - stream.set_rise(0) + stream.set_text_rise(0) + stream.set_text_rise(0) string = '<' else: if offset: From 50cf365c9debfb4be1d09cfe9478520a5cca7947 Mon Sep 17 00:00:00 2001 From: Gaurav Samudra <60246931+gauravsamudra@users.noreply.github.com> Date: Sun, 24 Sep 2023 21:49:25 -0400 Subject: [PATCH 3/4] removed duplicate line --- weasyprint/draw.py | 1 - 1 file changed, 1 deletion(-) diff --git a/weasyprint/draw.py b/weasyprint/draw.py index 8f4b2c574..a784861ad 100644 --- a/weasyprint/draw.py +++ b/weasyprint/draw.py @@ -1194,7 +1194,6 @@ def draw_first_line(stream, textbox, text_overflow, block_ellipsis, matrix): string += f'<{glyph:02x}>' if font.bitmap else f'<{glyph:04x}>' stream.show_text(string) stream.set_text_rise(0) - stream.set_text_rise(0) string = '<' else: if offset: From d51e211c9fd24782392e0274698b839a9af26770 Mon Sep 17 00:00:00 2001 From: Guillaume Ayoub Date: Mon, 25 Sep 2023 13:43:55 +0200 Subject: [PATCH 4/4] Fix text rise value --- weasyprint/draw.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/weasyprint/draw.py b/weasyprint/draw.py index a784861ad..75be102eb 100644 --- a/weasyprint/draw.py +++ b/weasyprint/draw.py @@ -1179,15 +1179,14 @@ def draw_first_line(stream, textbox, text_overflow, block_ellipsis, matrix): utf8_position = utf8_positions[i] offset = glyph_info.geometry.x_offset / font_size - - offset_y = glyph_info.geometry.y_offset / font_size / textbox.height - if offset_y: + rise = glyph_info.geometry.y_offset / 1000 + if rise: if string[-1] == '<': string = string[:-1] else: string += '>' stream.show_text(string) - stream.set_text_rise(-offset_y) + stream.set_text_rise(-rise) string = '' if offset: string = f'{-offset}'