Check whether the last 3 path items represent a rectangle. Returns 1 if we have modified the path, otherwise 0.
(dev)
| 22729 | |
| 22730 | |
| 22731 | def jm_checkrect(dev): |
| 22732 | ''' |
| 22733 | Check whether the last 3 path items represent a rectangle. |
| 22734 | Returns 1 if we have modified the path, otherwise 0. |
| 22735 | ''' |
| 22736 | #log(f'{getattr(dev, "pathdict", None)=}') |
| 22737 | dev.linecount = 0 # reset line count |
| 22738 | orientation = 0 # area orientation of rectangle |
| 22739 | items = dev.pathdict[ dictkey_items] |
| 22740 | len_ = len(items) |
| 22741 | |
| 22742 | line0 = items[ len_ - 3] |
| 22743 | ll = JM_point_from_py( line0[ 1]) |
| 22744 | lr = JM_point_from_py( line0[ 2]) |
| 22745 | |
| 22746 | # no need to extract "line1"! |
| 22747 | line2 = items[ len_ - 1] |
| 22748 | ur = JM_point_from_py( line2[ 1]) |
| 22749 | ul = JM_point_from_py( line2[ 2]) |
| 22750 | |
| 22751 | # Assumption: |
| 22752 | # When decomposing rects, MuPDF always starts with a horizontal line, |
| 22753 | # followed by a vertical line, followed by a horizontal line. |
| 22754 | # First line: (ll, lr), third line: (ul, ur). |
| 22755 | # If 1st line is below 3rd line, we record anti-clockwise (+1), else |
| 22756 | # clockwise (-1) orientation. |
| 22757 | |
| 22758 | if (0 |
| 22759 | or ll.y != lr.y |
| 22760 | or ll.x != ul.x |
| 22761 | or ur.y != ul.y |
| 22762 | or ur.x != lr.x |
| 22763 | ): |
| 22764 | return 0 # not a rectangle |
| 22765 | |
| 22766 | # we have a rect, replace last 3 "l" items by one "re" item. |
| 22767 | if ul.y < lr.y: |
| 22768 | r = mupdf.fz_make_rect(ul.x, ul.y, lr.x, lr.y) |
| 22769 | orientation = 1 |
| 22770 | else: |
| 22771 | r = mupdf.fz_make_rect(ll.x, ll.y, ur.x, ur.y) |
| 22772 | orientation = -1 |
| 22773 | |
| 22774 | rect = ( 're', JM_py_from_rect(r), orientation) |
| 22775 | items[ len_ - 3] = rect # replace item -3 by rect |
| 22776 | del items[ len_ - 2 : len_] # delete remaining 2 items |
| 22777 | return 1 |
| 22778 | |
| 22779 | |
| 22780 | def jm_trace_text( dev, text, type_, ctm, colorspace, color, alpha, seqno): |
no test coverage detected
searching dependent graphs…