Skip to content

Commit

Permalink
release v2.0.15
Browse files Browse the repository at this point in the history
  • Loading branch information
jorisschellekens committed Nov 17, 2021
1 parent 710eb5d commit 0963979
Show file tree
Hide file tree
Showing 265 changed files with 217 additions and 113 deletions.
2 changes: 1 addition & 1 deletion borb/io/write/ascii_art/ascii_logo.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
borb version 2.0.14
borb version 2.0.15
Joris Schellekens
2 changes: 1 addition & 1 deletion borb/pdf/canvas/event/chunk_of_text_render_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class ChunkOfTextRenderEvent(Event, ChunkOfText):
def __init__(self, graphics_state: CanvasGraphicsState, raw_bytes: String):
assert graphics_state.font is not None
assert isinstance(graphics_state.font, Font)
self._glyph_line: GlyphLine = GlyphLine(
self._glyph_line: GlyphLine = GlyphLine.from_bytes(
raw_bytes.get_value_bytes(),
graphics_state.font,
graphics_state.font_size,
Expand Down
91 changes: 74 additions & 17 deletions borb/pdf/canvas/font/glyph_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,28 +51,37 @@ class GlyphLine:
This class contains utility methods to work with collections of Glyph objects.
"""

def __init__(
self,
text_bytes: bytes,
@staticmethod
def from_bytes(
text: bytes,
font: Font,
font_size: Decimal,
character_spacing: Decimal = Decimal(0),
word_spacing: Decimal = Decimal(0),
horizontal_scaling: Decimal = Decimal(100),
):
assert isinstance(font, Font)
self._glyphs: typing.List[Glyph] = []
) -> "GlyphLine":
"""
This method constructs a new GlyphLine from text (represented as character ids)
:param text: a byte-array containing the character ids
:param font: the font
:param font_size: the font-size
:param character_spacing: the (additional) space between characters
:param word_spacing: the (additional) space between words
:param horizontal_scaling: the horizontal scaling factor (100 represents no zoom)
:return: a GlyphLine
"""
glyphs: typing.List[Glyph] = []
i: int = 0
while i < len(text_bytes):
while i < len(text):
# sometimes, 2 bytes make up 1 unicode char
unicode_chars: typing.Optional[str] = None
if i + 1 < len(text_bytes):
multi_byte_char_code: int = text_bytes[i] * 256 + text_bytes[i + 1]
if i + 1 < len(text):
multi_byte_char_code: int = text[i] * 256 + text[i + 1]
unicode_chars = font.character_identifier_to_unicode(
multi_byte_char_code
)
if unicode_chars is not None:
self._glyphs.append(
glyphs.append(
Glyph(
multi_byte_char_code,
unicode_chars,
Expand All @@ -82,23 +91,71 @@ def __init__(
i += 2
continue
# usually it's 1 byte though
if i < len(text_bytes):
unicode_chars = font.character_identifier_to_unicode(text_bytes[i])
if i < len(text):
unicode_chars = font.character_identifier_to_unicode(text[i])
if unicode_chars is not None:
self._glyphs.append(
glyphs.append(
Glyph(
text_bytes[i],
text[i],
unicode_chars,
font.get_width(text_bytes[i]) or Decimal(0),
font.get_width(text[i]) or Decimal(0),
)
)
i += 1
continue
# no mapping found
if i < len(text_bytes):
self._glyphs.append(Glyph(text_bytes[i], "�", Decimal(250)))
if i < len(text):
glyphs.append(Glyph(text[i], "�", Decimal(250)))
i += 1
return GlyphLine(
glyphs, font, font_size, character_spacing, word_spacing, horizontal_scaling
)

@staticmethod
def from_str(
text: str,
font: Font,
font_size: Decimal,
character_spacing: Decimal = Decimal(0),
word_spacing: Decimal = Decimal(0),
horizontal_scaling: Decimal = Decimal(100),
) -> "GlyphLine":
"""
This method constructs a new GlyphLine from text
:param text: a string which will be decoded into character-ids
:param font: the font
:param font_size: the font-size
:param character_spacing: the (additional) space between characters
:param word_spacing: the (additional) space between words
:param horizontal_scaling: the horizontal scaling factor (100 represents no zoom)
:return: a GlyphLine
"""
character_ids: typing.List[int] = [
font.unicode_to_character_identifier(c) or 0 for c in text
]
glyphs: typing.List[Glyph] = [
Glyph(
cid,
text[i],
font.get_width(cid) or Decimal(0),
)
for i, cid in enumerate(character_ids)
]
return GlyphLine(
glyphs, font, font_size, character_spacing, word_spacing, horizontal_scaling
)

def __init__(
self,
glyphs: typing.List[Glyph],
font: Font,
font_size: Decimal,
character_spacing: Decimal = Decimal(0),
word_spacing: Decimal = Decimal(0),
horizontal_scaling: Decimal = Decimal(100),
):
assert isinstance(font, Font)
self._glyphs: typing.List[Glyph] = glyphs
self._font = font
self._font_size = font_size
self._character_spacing = character_spacing
Expand Down
5 changes: 1 addition & 4 deletions borb/pdf/canvas/layout/text/chunk_of_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,15 +225,12 @@ def _do_layout_without_padding(self, page: Page, bounding_box: Rectangle):
self._write_text_bytes(), # Tj
)
self._append_to_content_stream(page, content)
encoded_bytes: bytes = [
self._font.unicode_to_character_identifier(c) or 0 for c in self._text
]

# fmt: off
layout_rect = Rectangle(
bounding_box.x,
bounding_box.y + bounding_box.height - line_height,
GlyphLine(encoded_bytes, self._font, self._font_size).get_width_in_text_space(),
GlyphLine.from_str(self._text, self._font, self._font_size).get_width_in_text_space(),
line_height,
)
# fmt: on
Expand Down
23 changes: 6 additions & 17 deletions borb/pdf/canvas/layout/text/paragraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,7 @@ def _split_text(self, bounding_box: Rectangle) -> typing.List[str]:
# checking with 0 is not a great idea due to rounding errors
# so, as a pre-emptive measure, we round the number to 2 digits
# fmt: off
encoded_bytes: bytes = [self._font.unicode_to_character_identifier(c) or 0 for c in potential_text]
potential_width = GlyphLine(encoded_bytes, self._font, self._font_size).get_width_in_text_space()
potential_width = GlyphLine.from_str(potential_text, self._font, self._font_size).get_width_in_text_space()
remaining_space_in_box: Decimal = round(bounding_box.width - potential_width, 2)
# fmt: on

Expand Down Expand Up @@ -192,8 +191,7 @@ def _split_text(self, bounding_box: Rectangle) -> typing.List[str]:
for i in range(1, len(hyphenated_word_parts)):
# fmt: off
potential_text_after_hyphenation = potential_text + "".join([x for x in hyphenated_word_parts[0:i]]) + "-"
encoded_bytes = bytes([self._font.unicode_to_character_identifier(c) or 0 for c in potential_text_after_hyphenation])
potential_width = GlyphLine(encoded_bytes, self._font, self._font_size).get_width_in_text_space()
potential_width = GlyphLine.from_str(potential_text_after_hyphenation, self._font, self._font_size).get_width_in_text_space()
remaining_space_in_box = round(bounding_box.width - potential_width, 2)
# fmt: on
if remaining_space_in_box > Decimal(0):
Expand Down Expand Up @@ -329,14 +327,8 @@ def _do_layout_without_padding_text_alignment_justified(
max_y = max(last_line_rectangle.y + last_line_rectangle.height, max_y)
continue

encoded_bytes: bytes = bytes(
[
self._font.unicode_to_character_identifier(c) or 0
for c in line_of_text
]
)
estimated_width: Decimal = GlyphLine(
encoded_bytes, self._font, self._font_size
estimated_width: Decimal = GlyphLine.from_str(
line_of_text, self._font, self._font_size
).get_width_in_text_space()
remaining_space: Decimal = bounding_box.width - estimated_width

Expand Down Expand Up @@ -377,11 +369,8 @@ def _do_layout_without_padding_text_alignment_justified(
max_y = max(r.y + r.height, max_y)

# line up our next x
encoded_bytes = bytes(
[self._font.unicode_to_character_identifier(c) or 0 for c in s]
)
word_size = GlyphLine(
encoded_bytes, self._font, self._font_size
word_size = GlyphLine.from_str(
s, self._font, self._font_size
).get_width_in_text_space()
x += word_size
x += space_per_space
Expand Down
2 changes: 1 addition & 1 deletion release_notes.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# :mega: borb release 2.0.14
# :mega: borb release 2.0.15

This is a bugfix release.
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ git+git://github.com/ojii/pymaging.git
python-barcode>=0.13.1
qrcode[pil]>=6.1
requests>=2.24.0
setuptools~=51.1.1
setuptools>=51.1.1
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

setuptools.setup(
name="borb",
version="2.0.14",
version="2.0.15",
author="Joris Schellekens",
author_email="[email protected]",
description="borb is a library for reading, creating and manipulating PDF files in python.",
Expand Down
2 changes: 1 addition & 1 deletion tests/corpus/test_copy_document_compare_size.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def __init__(self, methodName="runTest"):
self.number_of_fails: int = 0
self.memory_stats_per_document: typing.Dict[str, typing.Tuple[int, int]] = {}

#@unittest.skip
@unittest.skip
def test_against_entire_corpus(self):
pdf_file_names = os.listdir(self.corpus_dir)
pdfs = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def __init__(self, methodName="runTest"):
self.number_of_fails: int = 0
self.memory_stats_per_document: typing.Dict[str, typing.Tuple[int, int]] = {}

#@unittest.skip
@unittest.skip
def test_against_entire_corpus(self):
pdf_file_names = os.listdir(self.corpus_dir)
pdfs = [
Expand Down
3 changes: 2 additions & 1 deletion tests/corpus/test_extract_text_expect_ground_truth.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import time
import traceback
import typing
import unittest
from datetime import datetime
Expand Down Expand Up @@ -46,7 +47,7 @@ def __init__(self, methodName="runTest"):
self.time_per_document: typing.Dict[str, float] = {}
self.fails_per_document: typing.Dict[str, int] = []

#@unittest.skip
@unittest.skip
def test_against_entire_corpus(self):
pdf_file_names = os.listdir(self.corpus_dir)
pdfs = [
Expand Down
2 changes: 1 addition & 1 deletion tests/corpus/test_open_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def __init__(self, methodName="runTest"):
self.time_per_document: typing.Dict[str, float] = {}
self.memory_stats_per_document: typing.Dict[str, typing.Tuple[int, int]] = {}

#@unittest.skip
@unittest.skip
def test_against_entire_corpus(self):
pdf_file_names = os.listdir(self.corpus_dir)
pdfs = [
Expand Down
Binary file modified tests/output/test_add_all_rubber_stamp_annotations/output.pdf
Binary file not shown.
Binary file modified tests/output/test_add_circle_annotation/output.pdf
Binary file not shown.
Binary file modified tests/output/test_add_free_text_annotation/output_001.pdf
Binary file not shown.
Binary file modified tests/output/test_add_free_text_annotation/output_002.pdf
Binary file not shown.
Binary file modified tests/output/test_add_highlight_annotation/output_001.pdf
Binary file not shown.
Binary file modified tests/output/test_add_highlight_annotation/output_002.pdf
Binary file not shown.
Binary file modified tests/output/test_add_line_annotation/output_001.pdf
Binary file not shown.
Binary file modified tests/output/test_add_line_annotation/output_002.pdf
Binary file not shown.
Binary file modified tests/output/test_add_outline/output_001.pdf
Binary file not shown.
Binary file modified tests/output/test_add_outline/output_002.pdf
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified tests/output/test_add_redact_annotation/output_001.pdf
Binary file not shown.
Binary file modified tests/output/test_add_redact_annotation/output_002.pdf
Binary file not shown.
Binary file modified tests/output/test_add_redact_annotation/output_003.pdf
Binary file not shown.
Binary file modified tests/output/test_add_redact_annotation/output_004.pdf
Binary file not shown.
Binary file modified tests/output/test_add_redact_annotation/output_005.pdf
Binary file not shown.
Binary file modified tests/output/test_add_remote_go_to_annotation/output_001.pdf
Binary file not shown.
Binary file modified tests/output/test_add_remote_go_to_annotation/output_002.pdf
Binary file not shown.
Binary file modified tests/output/test_add_square_annotation/output.pdf
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified tests/output/test_add_squiggle_annotation/output_001.pdf
Binary file not shown.
Binary file modified tests/output/test_add_squiggle_annotation/output_002.pdf
Binary file not shown.
Binary file modified tests/output/test_add_strikeout_annotation/output_001.pdf
Binary file not shown.
Binary file modified tests/output/test_add_strikeout_annotation/output_002.pdf
Binary file not shown.
Binary file modified tests/output/test_add_super_mario_annotation/output.pdf
Binary file not shown.
Binary file modified tests/output/test_add_text_annotation/output_001.pdf
Binary file not shown.
Binary file modified tests/output/test_add_text_annotation/output_002.pdf
Binary file not shown.
Binary file modified tests/output/test_add_underline_annotation/output_001.pdf
Binary file not shown.
Binary file modified tests/output/test_add_underline_annotation/output_002.pdf
Binary file not shown.
Binary file modified tests/output/test_analogous_color_scheme/output.pdf
Binary file not shown.
Binary file modified tests/output/test_append_embedded_file/output_001.pdf
Binary file not shown.
Binary file modified tests/output/test_append_embedded_file/output_002.pdf
Binary file not shown.
Binary file modified tests/output/test_apply_redaction_annotations/output_001.pdf
Binary file not shown.
Binary file modified tests/output/test_apply_redaction_annotations/output_002.pdf
Binary file not shown.
Binary file modified tests/output/test_apply_redaction_annotations/output_003.pdf
Binary file not shown.
Binary file modified tests/output/test_apply_redaction_annotations/output_004.pdf
Binary file not shown.
Binary file modified tests/output/test_apply_redaction_annotations/output_005.pdf
Binary file not shown.
Binary file modified tests/output/test_apply_redaction_annotations/output_006.pdf
Binary file not shown.
Binary file modified tests/output/test_browser_layout_inline_next_line/output.pdf
Binary file not shown.
Binary file modified tests/output/test_change_info_dictionary_author/output_001.pdf
Binary file not shown.
Binary file modified tests/output/test_change_info_dictionary_author/output_002.pdf
Binary file not shown.
Binary file modified tests/output/test_concat_documents/output_000.pdf
Binary file not shown.
Binary file modified tests/output/test_concat_documents/output_001.pdf
Binary file not shown.
Binary file modified tests/output/test_concat_documents/output_002.pdf
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified tests/output/test_copy_document_compare_size/output.pdf
Binary file not shown.
Binary file not shown.
Binary file modified tests/output/test_count_annotations/output_001.pdf
Binary file not shown.
Binary file modified tests/output/test_count_annotations/output_002.pdf
Binary file not shown.
Binary file not shown.
Binary file modified tests/output/test_detect_table/input_000.pdf
Binary file not shown.
Binary file modified tests/output/test_detect_table/input_001.pdf
Binary file not shown.
Binary file modified tests/output/test_detect_table/input_002.pdf
Binary file not shown.
Binary file modified tests/output/test_detect_table/input_003.pdf
Binary file not shown.
Binary file modified tests/output/test_detect_table/input_004.pdf
Binary file not shown.
Binary file modified tests/output/test_detect_table/input_005.pdf
Binary file not shown.
Binary file modified tests/output/test_detect_table/input_006.pdf
Binary file not shown.
Binary file modified tests/output/test_detect_table/output_000.pdf
Binary file not shown.
Binary file modified tests/output/test_detect_table/output_001.pdf
Binary file not shown.
Binary file modified tests/output/test_detect_table/output_002.pdf
Binary file not shown.
Binary file modified tests/output/test_detect_table/output_003.pdf
Binary file not shown.
Binary file modified tests/output/test_detect_table/output_004.pdf
Binary file not shown.
Binary file modified tests/output/test_detect_table/output_005.pdf
Binary file not shown.
Binary file modified tests/output/test_detect_table/output_006.pdf
Binary file not shown.
Binary file modified tests/output/test_digit_placement_ubuntu_font/output_001.pdf
Binary file not shown.
Binary file modified tests/output/test_digit_placement_ubuntu_font/output_001.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/output/test_export_html_to_pdf/example_html_input_000.pdf
Binary file not shown.
Binary file modified tests/output/test_export_html_to_pdf/example_html_input_001.pdf
Binary file not shown.
Binary file modified tests/output/test_export_html_to_pdf/example_html_input_002.pdf
Binary file not shown.
Binary file modified tests/output/test_export_html_to_pdf/example_html_input_003.pdf
Binary file not shown.
Binary file modified tests/output/test_export_html_to_pdf/example_html_input_004.pdf
Binary file not shown.
Binary file modified tests/output/test_export_html_to_pdf/example_html_input_005.pdf
Binary file not shown.
Binary file modified tests/output/test_export_html_to_pdf/example_html_input_006.pdf
Binary file not shown.
Binary file modified tests/output/test_export_html_to_pdf/example_html_input_007.pdf
Binary file not shown.
Binary file modified tests/output/test_export_html_to_pdf/example_html_input_008.pdf
Binary file not shown.
Binary file modified tests/output/test_export_html_to_pdf/example_html_input_009.pdf
Binary file not shown.
Binary file modified tests/output/test_export_html_to_pdf/example_html_input_010.pdf
Binary file not shown.
Binary file modified tests/output/test_export_html_to_pdf/example_html_input_011.pdf
Binary file not shown.
Binary file modified tests/output/test_export_html_to_pdf/example_html_input_012.pdf
Binary file not shown.
Binary file modified tests/output/test_export_html_to_pdf/example_html_input_013.pdf
Binary file not shown.
Binary file modified tests/output/test_export_html_to_pdf/example_html_input_014.pdf
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified tests/output/test_export_to_mp3/output.mp3
Binary file not shown.
Binary file modified tests/output/test_extract_colors/output_001.pdf
Binary file not shown.
Binary file modified tests/output/test_extract_colors/output_002.pdf
Binary file not shown.
Binary file modified tests/output/test_extract_colors/output_002.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/output/test_extract_courier_text/output_001.pdf
Binary file not shown.
Binary file modified tests/output/test_extract_font_names/output_001.pdf
Binary file not shown.
Binary file modified tests/output/test_extract_font_names/output_002.pdf
Binary file not shown.
Binary file modified tests/output/test_extract_keywords/output_001.pdf
Binary file not shown.
Binary file modified tests/output/test_extract_keywords/output_002.pdf
Binary file not shown.
Binary file modified tests/output/test_extract_keywords/output_003.pdf
Binary file not shown.
Binary file modified tests/output/test_extract_red_text/output_001.pdf
Binary file not shown.
Binary file modified tests/output/test_extract_regex/output_001.pdf
Binary file not shown.
Binary file modified tests/output/test_extract_regex/output_002.pdf
Binary file not shown.
Binary file modified tests/output/test_extract_text/output_001.pdf
Binary file not shown.
Binary file modified tests/output/test_extract_text/output_002.pdf
Binary file not shown.
Binary file modified tests/output/test_extract_text_expect_ground_truth/output.pdf
Binary file not shown.
Binary file modified tests/output/test_extract_text_from_self_made_invoice/output.pdf
Binary file not shown.
Binary file modified tests/output/test_margin_and_padding/output_001.pdf
Binary file not shown.
Binary file modified tests/output/test_margin_and_padding/output_002.pdf
Binary file not shown.
Binary file modified tests/output/test_modify_image/output_001.pdf
Binary file not shown.
Binary file modified tests/output/test_modify_image/output_002.pdf
Binary file not shown.
Binary file modified tests/output/test_open_document/output.pdf
Binary file not shown.
Binary file modified tests/output/test_open_encrypted_document/output.pdf
Binary file not shown.
Binary file modified tests/output/test_optimize_images/output_001.pdf
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified tests/output/test_remove_annotation/output_001.pdf
Binary file not shown.
Binary file modified tests/output/test_remove_annotation/output_002.pdf
Binary file not shown.
Binary file modified tests/output/test_remove_annotation/output_003.pdf
Binary file not shown.
Binary file modified tests/output/test_remove_page/output_001.pdf
Binary file not shown.
Binary file modified tests/output/test_remove_page/output_002.pdf
Binary file not shown.
Binary file modified tests/output/test_remove_page/output_003.pdf
Binary file not shown.
Binary file modified tests/output/test_remove_page/output_004.pdf
Binary file not shown.
Binary file modified tests/output/test_rotate_page/output_001.pdf
Binary file not shown.
Binary file modified tests/output/test_rotate_page/output_002.pdf
Binary file not shown.
Binary file modified tests/output/test_rotate_page/output_003.pdf
Binary file not shown.
Binary file modified tests/output/test_split_complementary_color_scheme/output.pdf
Binary file not shown.
Binary file modified tests/output/test_tetradic_rectangle_color_scheme/output.pdf
Binary file not shown.
Binary file modified tests/output/test_tetradic_square_color_scheme/output.pdf
Binary file not shown.
Binary file modified tests/output/test_triadic_color_scheme/output.pdf
Binary file not shown.
Binary file modified tests/output/test_write_2_scatter_plots/output.pdf
Binary file not shown.
Binary file modified tests/output/test_write_3d_density_chart/output.pdf
Binary file not shown.
Binary file modified tests/output/test_write_3d_surface_plot/output.pdf
Binary file not shown.
Binary file modified tests/output/test_write_all_types_of_barcode/output.pdf
Binary file not shown.
Binary file modified tests/output/test_write_battleship/output.pdf
Binary file not shown.
Binary file modified tests/output/test_write_blobs/output.pdf
Binary file not shown.
Binary file modified tests/output/test_write_check_box/output_001.pdf
Binary file not shown.
Binary file modified tests/output/test_write_check_box/output_002.pdf
Binary file not shown.
Binary file modified tests/output/test_write_chunk_of_text/output.pdf
Binary file not shown.
Binary file modified tests/output/test_write_chunk_of_text_escaped_chars/output.pdf
Binary file not shown.
Binary file not shown.
Binary file modified tests/output/test_write_chunks_of_text/output_001.pdf
Binary file not shown.
Binary file modified tests/output/test_write_chunks_of_text/output_002.pdf
Binary file not shown.
Binary file modified tests/output/test_write_chunks_of_text/output_003.pdf
Binary file not shown.
Binary file modified tests/output/test_write_chunks_of_text/output_004.pdf
Binary file not shown.
Binary file modified tests/output/test_write_chunks_of_text/output_005.pdf
Binary file not shown.
Binary file not shown.
Binary file modified tests/output/test_write_code_128_barcode/output.pdf
Binary file not shown.
Binary file modified tests/output/test_write_code_128_barcode_in_color/output.pdf
Binary file not shown.
Binary file modified tests/output/test_write_codeblock/output.pdf
Binary file not shown.
Binary file modified tests/output/test_write_dragon_curve/output.pdf
Binary file not shown.
Binary file modified tests/output/test_write_drop_down_list/output_001.pdf
Binary file not shown.
Binary file modified tests/output/test_write_drop_down_list/output_002.pdf
Binary file not shown.
Binary file modified tests/output/test_write_emoji/output.pdf
Binary file not shown.
Binary file modified tests/output/test_write_empty_document/output.pdf
Binary file not shown.
Binary file modified tests/output/test_write_fixed_column_width_table/output_001.pdf
Binary file not shown.
Binary file modified tests/output/test_write_fixed_column_width_table/output_002.pdf
Binary file not shown.
Binary file modified tests/output/test_write_fixed_column_width_table/output_003.pdf
Binary file not shown.
Binary file modified tests/output/test_write_fixed_column_width_table/output_004.pdf
Binary file not shown.
Binary file modified tests/output/test_write_fixed_column_width_table/output_005.pdf
Binary file not shown.
Binary file modified tests/output/test_write_flexi_table/output_001.pdf
Binary file not shown.
Binary file modified tests/output/test_write_flexi_table/output_002.pdf
Binary file not shown.
Binary file modified tests/output/test_write_flexi_table/output_003.pdf
Binary file not shown.
Binary file modified tests/output/test_write_flexi_table/output_004.pdf
Binary file not shown.
Binary file modified tests/output/test_write_flexi_table/output_005.pdf
Binary file not shown.
Binary file not shown.
Binary file modified tests/output/test_write_flowchart_line_art/output.pdf
Binary file not shown.
Binary file modified tests/output/test_write_flyer/output.pdf
Binary file not shown.
Binary file modified tests/output/test_write_grayscale_image/output.pdf
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified tests/output/test_write_hyphenated_paragraph/output.pdf
Binary file not shown.
Binary file modified tests/output/test_write_image_aligned_center/output.pdf
Binary file not shown.
Binary file modified tests/output/test_write_image_by_url/output.pdf
Binary file not shown.
Binary file modified tests/output/test_write_incomplete_table/output.pdf
Binary file not shown.
Binary file modified tests/output/test_write_line_of_text_justified_center/output.pdf
Binary file not shown.
Binary file modified tests/output/test_write_line_of_text_justified_full/output.pdf
Binary file not shown.
Binary file modified tests/output/test_write_line_of_text_justified_right/output.pdf
Binary file not shown.
Binary file modified tests/output/test_write_lissajours_line_art/output.pdf
Binary file not shown.
Binary file modified tests/output/test_write_long_unordered_list/output.pdf
Binary file not shown.
Binary file modified tests/output/test_write_multiple_pages/output.pdf
Binary file not shown.
Binary file modified tests/output/test_write_nested_ordered_list/output.pdf
Binary file not shown.
Binary file modified tests/output/test_write_nested_unordered_list/output.pdf
Binary file not shown.
Binary file modified tests/output/test_write_nested_unordered_list/output.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/output/test_write_ordered_list/output_001.pdf
Binary file not shown.
Binary file modified tests/output/test_write_ordered_list/output_002.pdf
Binary file not shown.
Binary file modified tests/output/test_write_paragraph/output.pdf
Binary file not shown.
Binary file modified tests/output/test_write_paragraph_alignment/output.pdf
Binary file not shown.
Binary file modified tests/output/test_write_paragraph_border_left/output.pdf
Binary file not shown.
Binary file modified tests/output/test_write_paragraph_force_split/output.pdf
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified tests/output/test_write_paragraph_justified_full/output.pdf
Binary file not shown.
Binary file modified tests/output/test_write_paragraph_justified_right/output.pdf
Binary file not shown.
Binary file modified tests/output/test_write_paragraph_preserve_space/output.pdf
Binary file not shown.
Binary file modified tests/output/test_write_paragraph_save_twice/output_001.pdf
Binary file not shown.
Binary file modified tests/output/test_write_paragraph_save_twice/output_002.pdf
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified tests/output/test_write_paragraphs_with_headings/output.pdf
Binary file not shown.
Binary file modified tests/output/test_write_pdf_a_1b/output_001.pdf
Binary file not shown.
Binary file modified tests/output/test_write_pdf_a_1b/output_002.pdf
Binary file not shown.
Binary file modified tests/output/test_write_pil_image/output.pdf
Binary file not shown.
Binary file modified tests/output/test_write_png_image_by_url/output.pdf
Binary file not shown.
Binary file modified tests/output/test_write_radar_plot/output.pdf
Binary file not shown.
Binary file modified tests/output/test_write_table_with_col_span/output.pdf
Binary file not shown.
Binary file modified tests/output/test_write_table_with_image/output.pdf
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified tests/output/test_write_table_with_row_span/output.pdf
Binary file not shown.
Binary file not shown.
Binary file modified tests/output/test_write_tents_and_trees/output.pdf
Binary file not shown.
Binary file modified tests/output/test_write_text_area/output_001.pdf
Binary file not shown.
Binary file modified tests/output/test_write_text_area/output_002.pdf
Binary file not shown.
Binary file modified tests/output/test_write_text_field/output_001.pdf
Binary file not shown.
Binary file modified tests/output/test_write_text_field/output_002.pdf
Binary file not shown.
Binary file modified tests/output/test_write_unordered_list/output.pdf
Binary file not shown.
Binary file modified tests/output/test_write_using_low_level_instructions/output.pdf
Binary file not shown.
Binary file modified tests/output/test_write_with_truetype_font/output_001.pdf
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/output/test_write_with_truetype_font/output_002.pdf
Binary file not shown.
Binary file modified tests/output/test_write_with_truetype_font/output_002.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/output/test_write_with_truetype_font/output_003.pdf
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/output/test_write_xl_image/output.pdf
Binary file not shown.
55 changes: 55 additions & 0 deletions tests/pdf/canvas/font/test_write_with_truetype_font.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
from pathlib import Path

from borb.io.read.types import Decimal
from borb.pdf.canvas.color.color import HexColor
from borb.pdf.canvas.font.simple_font.true_type_font import TrueTypeFont
from borb.pdf.canvas.layout.page_layout.multi_column_layout import SingleColumnLayout
from borb.pdf.canvas.layout.page_layout.page_layout import PageLayout
from borb.pdf.canvas.layout.table.fixed_column_width_table import (
FixedColumnWidthTable as Table,
)
from borb.pdf.canvas.layout.text.paragraph import Paragraph
from borb.pdf.canvas.line_art.line_art_factory import LineArtFactory
from borb.pdf.document import Document
from borb.pdf.page.page import Page
from borb.pdf.pdf import PDF
Expand All @@ -33,6 +35,59 @@ def __init__(self, methodName="runTest"):
if not self.output_dir.exists():
self.output_dir.mkdir()

def test_write_document_004(self):

# create document
pdf = Document()

# add page
page = Page()
pdf.append_page(page)

# layout
layout: PageLayout = SingleColumnLayout(page)

# add test information
layout.add(
Table(number_of_columns=2, number_of_rows=3)
.add(Paragraph("Date", font="Helvetica-Bold"))
.add(Paragraph(datetime.now().strftime("%d/%m/%Y, %H:%M:%S")))
.add(Paragraph("Test", font="Helvetica-Bold"))
.add(Paragraph(Path(__file__).stem))
.add(Paragraph("Description", font="Helvetica-Bold"))
.add(
Paragraph(
"This test loads a truetype _font from a .ttf file and attempts to use it to write the text A <space> B. The bounding box of the text is then drawn."
)
)
.set_padding_on_all_cells(Decimal(2), Decimal(2), Decimal(2), Decimal(2))
)

# path to _font
font_path: Path = Path(__file__).parent / "Pacifico-Regular.ttf"
assert font_path.exists()

# add paragraph
p: Paragraph = Paragraph(
"A B", font=TrueTypeFont.true_type_font_from_file(font_path)
)
layout.add(p)

# add box
page.append_polygon_annotation(
LineArtFactory.rectangle(p.get_bounding_box()),
stroke_color=HexColor("ff0000"),
)

# determine output location
out_file = self.output_dir / "output_004.pdf"

# attempt to store PDF
with open(out_file, "wb") as in_file_handle:
PDF.dumps(in_file_handle, pdf)

compare_visually_to_ground_truth(out_file)

def test_write_document_001(self):

# create document
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@

from borb.pdf.canvas.color.color import X11Color
from borb.pdf.canvas.geometry.rectangle import Rectangle
from borb.pdf.canvas.layout.page_layout.multi_column_layout import \
SingleColumnLayout
from borb.pdf.canvas.layout.table.fixed_column_width_table import \
FixedColumnWidthTable as Table
from borb.pdf.canvas.layout.page_layout.multi_column_layout import SingleColumnLayout
from borb.pdf.canvas.layout.table.fixed_column_width_table import (
FixedColumnWidthTable as Table,
)
from borb.pdf.canvas.layout.text.paragraph import Paragraph
from borb.pdf.document import Document
from borb.pdf.page.page import Page, RubberStampAnnotationIconType
Expand Down
8 changes: 4 additions & 4 deletions tests/pdf/page/annotations/test_add_circle_annotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@

from borb.pdf.canvas.color.color import HexColor
from borb.pdf.canvas.geometry.rectangle import Rectangle
from borb.pdf.canvas.layout.page_layout.multi_column_layout import \
SingleColumnLayout
from borb.pdf.canvas.layout.table.fixed_column_width_table import \
FixedColumnWidthTable as Table
from borb.pdf.canvas.layout.page_layout.multi_column_layout import SingleColumnLayout
from borb.pdf.canvas.layout.table.fixed_column_width_table import (
FixedColumnWidthTable as Table,
)
from borb.pdf.canvas.layout.text.paragraph import Paragraph
from borb.pdf.document import Document
from borb.pdf.page.page import Page
Expand Down
Loading

0 comments on commit 0963979

Please sign in to comment.