added additional corners coordinates for coordinate transformation tests
This commit is contained in:
parent
2ee36dcb54
commit
b4b0058475
@ -23,7 +23,21 @@ def coordinate_test_fpdf():
|
|||||||
return pdf
|
return pdf
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(params=["top_left", "bottom_left", "bottom_right", "top_right"])
|
||||||
|
def corner(request):
|
||||||
|
return request.param
|
||||||
|
|
||||||
|
|
||||||
def get_fpdf_coordinates(corner):
|
def get_fpdf_coordinates(corner):
|
||||||
|
"""Origin top left, y1 <= y2; all coords on page are positive
|
||||||
|
(0,0)--+--(2,0)--+
|
||||||
|
|////| |////|
|
||||||
|
+--(1,1) +--(3,1)
|
||||||
|
|
||||||
|
(0,2)--+ (2,2)--+
|
||||||
|
|////| |////|
|
||||||
|
+--(1,3) +--(3,3)
|
||||||
|
"""
|
||||||
metadata = base_position_metadata()
|
metadata = base_position_metadata()
|
||||||
|
|
||||||
if corner == "top_left":
|
if corner == "top_left":
|
||||||
@ -32,22 +46,32 @@ def get_fpdf_coordinates(corner):
|
|||||||
elif corner == "bottom_left":
|
elif corner == "bottom_left":
|
||||||
metadata.update({Info.X1: 0, Info.Y1: 200, Info.X2: 100, Info.Y2: 300})
|
metadata.update({Info.X1: 0, Info.Y1: 200, Info.X2: 100, Info.Y2: 300})
|
||||||
|
|
||||||
|
elif corner == "bottom_right":
|
||||||
|
metadata.update({Info.X1: 200, Info.Y1: 200, Info.X2: 300, Info.Y2: 300})
|
||||||
|
|
||||||
|
elif corner == "top_right":
|
||||||
|
metadata.update({Info.X1: 200, Info.Y1: 0, Info.X2: 300, Info.Y2: 100})
|
||||||
|
|
||||||
|
else:
|
||||||
|
raise ValueError(f"No coordinates specified for corner {corner}.")
|
||||||
|
|
||||||
return metadata
|
return metadata
|
||||||
|
|
||||||
|
|
||||||
def get_fitz_coordinates(corner):
|
def get_fitz_coordinates(corner):
|
||||||
metadata = base_position_metadata()
|
return get_fpdf_coordinates(corner)
|
||||||
|
|
||||||
if corner == "top_left":
|
|
||||||
metadata.update({Info.X1: 0, Info.Y1: 0, Info.X2: 100, Info.Y2: 100})
|
|
||||||
|
|
||||||
elif corner == "bottom_left":
|
|
||||||
metadata.update({Info.X1: 0, Info.Y1: 200, Info.X2: 100, Info.Y2: 300})
|
|
||||||
|
|
||||||
return metadata
|
|
||||||
|
|
||||||
|
|
||||||
def get_pdfnet_coordinates(corner):
|
def get_pdfnet_coordinates(corner):
|
||||||
|
"""Origin bottom left, y1 <= y2; all coords on page are positive
|
||||||
|
+---(1,3) +--(3,3)
|
||||||
|
|////| |////|
|
||||||
|
(0,2)--+ (2,2)--+
|
||||||
|
|
||||||
|
+--(1,1) +--(3,1)
|
||||||
|
|////| |////|
|
||||||
|
(0,0)--+ (2,0)--+
|
||||||
|
"""
|
||||||
metadata = base_position_metadata()
|
metadata = base_position_metadata()
|
||||||
|
|
||||||
if corner == "top_left":
|
if corner == "top_left":
|
||||||
@ -56,6 +80,15 @@ def get_pdfnet_coordinates(corner):
|
|||||||
elif corner == "bottom_left":
|
elif corner == "bottom_left":
|
||||||
metadata.update({Info.X1: 0, Info.Y1: 0, Info.X2: 100, Info.Y2: 100})
|
metadata.update({Info.X1: 0, Info.Y1: 0, Info.X2: 100, Info.Y2: 100})
|
||||||
|
|
||||||
|
elif corner == "bottom_right":
|
||||||
|
metadata.update({Info.X1: 200, Info.Y1: 0, Info.X2: 300, Info.Y2: 100})
|
||||||
|
|
||||||
|
elif corner == "top_right":
|
||||||
|
metadata.update({Info.X1: 200, Info.Y1: 200, Info.X2: 300, Info.Y2: 300})
|
||||||
|
|
||||||
|
else:
|
||||||
|
raise ValueError(f"No coordinates specified for corner {corner}.")
|
||||||
|
|
||||||
return metadata
|
return metadata
|
||||||
|
|
||||||
|
|
||||||
@ -112,7 +145,6 @@ def coordinate_test_page_image(coordinate_test_pdf):
|
|||||||
return pdf2image.convert_from_bytes(coordinate_test_pdf)[0]
|
return pdf2image.convert_from_bytes(coordinate_test_pdf)[0]
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("corner", ["top_left", "bottom_left"])
|
|
||||||
@pytest.mark.parametrize("coordinate_system", ["fpdf"])
|
@pytest.mark.parametrize("coordinate_system", ["fpdf"])
|
||||||
def test_fpdf_coordinate_transformer(position_metadata_in_given_system, position_metadata_in_reference_system):
|
def test_fpdf_coordinate_transformer(position_metadata_in_given_system, position_metadata_in_reference_system):
|
||||||
"""We use FPDF's coordinate system as the reference system (arbitrarily). Hence, FPDFCoordinateTransformer
|
"""We use FPDF's coordinate system as the reference system (arbitrarily). Hence, FPDFCoordinateTransformer
|
||||||
@ -128,7 +160,6 @@ def test_fpdf_coordinate_transformer(position_metadata_in_given_system, position
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("corner", ["top_left", "bottom_left"])
|
|
||||||
@pytest.mark.parametrize("coordinate_system", ["fitz"])
|
@pytest.mark.parametrize("coordinate_system", ["fitz"])
|
||||||
def test_fitz_coordinate_transformer(position_metadata_in_given_system, position_metadata_in_reference_system):
|
def test_fitz_coordinate_transformer(position_metadata_in_given_system, position_metadata_in_reference_system):
|
||||||
"""How I inferred the transformation:
|
"""How I inferred the transformation:
|
||||||
@ -147,7 +178,6 @@ def test_fitz_coordinate_transformer(position_metadata_in_given_system, position
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("corner", ["top_left", "bottom_left"])
|
|
||||||
@pytest.mark.parametrize("coordinate_system", ["pdfnet"])
|
@pytest.mark.parametrize("coordinate_system", ["pdfnet"])
|
||||||
def test_pdfnet_coordinate_transformer(position_metadata_in_given_system, position_metadata_in_reference_system):
|
def test_pdfnet_coordinate_transformer(position_metadata_in_given_system, position_metadata_in_reference_system):
|
||||||
"""How I inferred the transformation:
|
"""How I inferred the transformation:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user