1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198
|
from pathlib import Path
import fpdf
from test.conftest import assert_pdf_equal
HERE = Path(__file__).resolve().parent
def next_row(pdf):
pdf.ln()
pdf.set_y(pdf.get_y() + size + margin)
size = 50
start_angle, end_angle = 30, 130
margin = 10
def test_solid_arc_not_circle(tmp_path):
pdf = fpdf.FPDF(unit="mm")
pdf.add_page()
for counter, style in enumerate(["F", "FD", "DF", None]):
pdf.solid_arc(
x=pdf.get_x(),
y=pdf.get_y(),
a=size / 2,
b=size,
start_angle=start_angle,
end_angle=end_angle,
style=style,
)
pdf.set_x(pdf.get_x() + (size / 2) + margin)
if counter % 3 == 0:
next_row(pdf)
assert_pdf_equal(pdf, HERE / "class_solid_arc_not_circle.pdf", tmp_path)
def test_solid_arc_style(tmp_path):
pdf = fpdf.FPDF(unit="mm")
pdf.add_page()
for counter, style in enumerate(["F", "FD", "DF", None]):
pdf.solid_arc(
x=pdf.get_x(),
y=pdf.get_y(),
a=size,
b=size,
start_angle=start_angle,
end_angle=end_angle,
style=style,
)
pdf.set_x(pdf.get_x() + size + margin)
if counter % 3 == 0:
next_row(pdf)
assert_pdf_equal(pdf, HERE / "class_solid_arc_style.pdf", tmp_path)
def test_solid_arc_line_width(tmp_path):
pdf = fpdf.FPDF(unit="mm")
pdf.add_page()
size_1 = size
for line_width in [1, 2, 3]:
pdf.set_line_width(line_width)
pdf.solid_arc(
x=pdf.get_x(),
y=pdf.get_y(),
# A workaround to avoid warning of pylint triggering duplicate code
# with test_arc.py
a=size_1,
b=size_1,
start_angle=start_angle,
end_angle=end_angle,
style=None,
)
pdf.set_x(pdf.get_x() + size + margin)
next_row(pdf)
for line_width in [4, 5, 6]:
pdf.set_line_width(line_width)
pdf.solid_arc(
x=pdf.get_x(),
y=pdf.get_y(),
a=size,
b=size,
start_angle=start_angle,
end_angle=end_angle,
style=None,
)
pdf.set_x(pdf.get_x() + size + margin)
pdf.set_line_width(0.2) # reset
assert_pdf_equal(pdf, HERE / "class_solid_arc_line_width.pdf", tmp_path)
def test_solid_arc_draw_color(tmp_path):
pdf = fpdf.FPDF(unit="mm")
pdf.add_page()
pdf.set_line_width(0.5)
for gray in [70, 140, 210]:
pdf.set_draw_color(gray)
pdf.solid_arc(
x=pdf.get_x(),
y=pdf.get_y(),
a=size,
b=size,
start_angle=start_angle,
end_angle=end_angle,
style=None,
)
pdf.set_x(pdf.get_x() + size + margin)
assert_pdf_equal(pdf, HERE / "class_solid_arc_draw_color.pdf", tmp_path)
def test_solid_arc_fill_color(tmp_path):
pdf = fpdf.FPDF(unit="mm")
pdf.add_page()
pdf.set_fill_color(240)
for color in [[230, 30, 180], [30, 180, 30], [30, 30, 70]]:
pdf.set_draw_color(*color)
pdf.solid_arc(
x=pdf.get_x(),
y=pdf.get_y(),
a=size,
b=size,
start_angle=start_angle,
end_angle=end_angle,
style="FD",
)
pdf.set_x(pdf.get_x() + size + margin)
next_row(pdf)
assert_pdf_equal(pdf, HERE / "class_solid_arc_fill_color.pdf", tmp_path)
def test_solid_arc_inclination(tmp_path):
pdf = fpdf.FPDF(unit="mm")
pdf.add_page()
size_1 = size
for counter, inclination in enumerate([0, 30, 90, 120]):
pdf.solid_arc(
x=pdf.get_x(),
y=pdf.get_y(),
# A workaround to avoid warning of pylint triggering duplicate code
# with test_arc.py
a=size_1,
b=size_1,
start_angle=start_angle,
end_angle=end_angle,
inclination=inclination,
style=None,
)
pdf.set_x(pdf.get_x() + size + margin)
if counter % 3 == 0:
next_row(pdf)
assert_pdf_equal(pdf, HERE / "class_solid_arc_inclination.pdf", tmp_path)
def test_arc_clockwise(tmp_path):
pdf = fpdf.FPDF(unit="mm")
pdf.add_page()
for inclination in [0, 30, 90, 120]:
pdf.solid_arc(
x=pdf.get_x(),
y=pdf.get_y(),
a=size,
b=size,
start_angle=start_angle,
end_angle=end_angle,
inclination=inclination,
style=None,
)
pdf.set_x(pdf.get_x() + size + margin)
pdf.solid_arc(
x=pdf.get_x(),
y=pdf.get_y(),
a=size,
b=size,
start_angle=start_angle,
end_angle=end_angle,
inclination=inclination,
clockwise=True,
style=None,
)
next_row(pdf)
assert_pdf_equal(pdf, HERE / "class_solid_arc_clockwise.pdf", tmp_path)
|