|
6 | 6 | import codecs |
7 | 7 | import collections |
8 | 8 | from datetime import datetime |
| 9 | +from enum import Enum |
9 | 10 | from functools import total_ordering |
10 | 11 | from io import BytesIO |
11 | 12 | import itertools |
@@ -398,44 +399,67 @@ def pdfRepr(self): |
398 | 399 |
|
399 | 400 |
|
400 | 401 | # PDF operators (not an exhaustive list) |
401 | | -_pdfops = dict( |
402 | | - close_fill_stroke=b'b', fill_stroke=b'B', fill=b'f', closepath=b'h', |
403 | | - close_stroke=b's', stroke=b'S', endpath=b'n', begin_text=b'BT', |
404 | | - end_text=b'ET', curveto=b'c', rectangle=b're', lineto=b'l', moveto=b'm', |
405 | | - concat_matrix=b'cm', use_xobject=b'Do', setgray_stroke=b'G', |
406 | | - setgray_nonstroke=b'g', setrgb_stroke=b'RG', setrgb_nonstroke=b'rg', |
407 | | - setcolorspace_stroke=b'CS', setcolorspace_nonstroke=b'cs', |
408 | | - setcolor_stroke=b'SCN', setcolor_nonstroke=b'scn', setdash=b'd', |
409 | | - setlinejoin=b'j', setlinecap=b'J', setgstate=b'gs', gsave=b'q', |
410 | | - grestore=b'Q', textpos=b'Td', selectfont=b'Tf', textmatrix=b'Tm', |
411 | | - show=b'Tj', showkern=b'TJ', setlinewidth=b'w', clip=b'W', shading=b'sh') |
412 | | - |
413 | | -Op = types.SimpleNamespace(**{name: Operator(value) |
414 | | - for name, value in _pdfops.items()}) |
415 | | - |
416 | | - |
417 | | -def _paint_path(fill, stroke): |
418 | | - """ |
419 | | - Return the PDF operator to paint a path. |
| 402 | +class Op(Operator, Enum): |
| 403 | + close_fill_stroke = b'b' |
| 404 | + fill_stroke = b'B' |
| 405 | + fill = b'f' |
| 406 | + closepath = b'h', |
| 407 | + close_stroke = b's' |
| 408 | + stroke = b'S' |
| 409 | + endpath = b'n' |
| 410 | + begin_text = b'BT', |
| 411 | + end_text = b'ET' |
| 412 | + curveto = b'c' |
| 413 | + rectangle = b're' |
| 414 | + lineto = b'l' |
| 415 | + moveto = b'm', |
| 416 | + concat_matrix = b'cm' |
| 417 | + use_xobject = b'Do' |
| 418 | + setgray_stroke = b'G', |
| 419 | + setgray_nonstroke = b'g' |
| 420 | + setrgb_stroke = b'RG' |
| 421 | + setrgb_nonstroke = b'rg', |
| 422 | + setcolorspace_stroke = b'CS' |
| 423 | + setcolorspace_nonstroke = b'cs', |
| 424 | + setcolor_stroke = b'SCN' |
| 425 | + setcolor_nonstroke = b'scn' |
| 426 | + setdash = b'd', |
| 427 | + setlinejoin = b'j' |
| 428 | + setlinecap = b'J' |
| 429 | + setgstate = b'gs' |
| 430 | + gsave = b'q', |
| 431 | + grestore = b'Q' |
| 432 | + textpos = b'Td' |
| 433 | + selectfont = b'Tf' |
| 434 | + textmatrix = b'Tm', |
| 435 | + show = b'Tj' |
| 436 | + showkern = b'TJ' |
| 437 | + setlinewidth = b'w' |
| 438 | + clip = b'W' |
| 439 | + shading = b'sh' |
| 440 | + |
| 441 | + @classmethod |
| 442 | + def paint_path(cls, fill, stroke): |
| 443 | + """ |
| 444 | + Return the PDF operator to paint a path. |
420 | 445 |
|
421 | | - Parameters |
422 | | - ---------- |
423 | | - fill: bool |
424 | | - Fill the path with the fill color. |
425 | | - stroke: bool |
426 | | - Stroke the outline of the path with the line color. |
427 | | - """ |
428 | | - if stroke: |
429 | | - if fill: |
430 | | - return Op.fill_stroke |
431 | | - else: |
432 | | - return Op.stroke |
433 | | - else: |
434 | | - if fill: |
435 | | - return Op.fill |
| 446 | + Parameters |
| 447 | + ---------- |
| 448 | + fill: bool |
| 449 | + Fill the path with the fill color. |
| 450 | + stroke: bool |
| 451 | + Stroke the outline of the path with the line color. |
| 452 | + """ |
| 453 | + if stroke: |
| 454 | + if fill: |
| 455 | + return cls.fill_stroke |
| 456 | + else: |
| 457 | + return cls.stroke |
436 | 458 | else: |
437 | | - return Op.endpath |
438 | | -Op.paint_path = _paint_path |
| 459 | + if fill: |
| 460 | + return cls.fill |
| 461 | + else: |
| 462 | + return cls.endpath |
439 | 463 |
|
440 | 464 |
|
441 | 465 | class Stream: |
|
0 commit comments