MCPcopy
hub / github.com/ArtifexSoftware/pdf2docx / Stroke

Class Stroke

pdf2docx/shape/Shape.py:140–265  ·  view source on GitHub ↗

Horizontal or vertical stroke of a path. The semantic meaning may be table border, or text style line like underline and strike-through.

Source from the content-addressed store, hash-verified

138
139
140class Stroke(Shape):
141 ''' Horizontal or vertical stroke of a path.
142 The semantic meaning may be table border, or text style line like underline and strike-through.
143 '''
144 def __init__(self, raw:dict=None):
145 raw = raw or {}
146 # NOTE: real page CS
147 self._start = fitz.Point(raw.get('start', (0.0, 0.0)))
148 self._end = fitz.Point(raw.get('end', (0.0, 0.0)))
149
150 if self._start.x > self._end.x or self._start.y > self._end.y:
151 self._start, self._end = self._end, self._start
152
153 # width, color
154 super().__init__(raw) # type, color
155 self.width = raw.get('width', 0.0) # Note this "width" is actually the height of stroke
156
157 # update bbox
158 super().update_bbox(self._to_rect())
159
160
161 @property
162 def horizontal(self): return abs(self._start[1]-self._end[1])<1e-3
163
164 @property
165 def vertical(self): return abs(self._start[0]-self._end[0])<1e-3
166
167 @property
168 def x0(self): return self._start.x
169
170 @property
171 def x1(self): return self._end.x
172
173 @property
174 def y0(self): return self._start.y
175
176 @property
177 def y1(self): return self._end.y
178
179
180 def update_bbox(self, rect):
181 ''&#x27;Update stroke bbox (related to real page CS).
182
183 * Update start/end points if ``rect.area==0``.
184 * Ppdate bbox directly if ``rect.area!=0``.
185
186 Args:
187 rect (fitz.Rect, tuple): ``(x0, y0, x1, y1)`` like data.
188
189 Returns:
190 Stroke: self
191 ''&#x27;
192 rect = fitz.Rect(rect)
193
194 # an empty area line
195 if rect.get_area()==0.0:
196 self._start = fitz.Point(rect[0:2])
197 self._end = fitz.Point(rect[2:])

Callers 6

_get_border_strokeMethod · 0.90
_check_outer_strokesMethod · 0.90
restoreMethod · 0.90
to_strokeMethod · 0.85
finalizeMethod · 0.85
to_strokeMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…