Rectangular (bbox) filling area of a closed path. The semantic meaning may be table shading, or text style like highlight.
| 266 | |
| 267 | |
| 268 | class Fill(Shape): |
| 269 | ''' Rectangular (bbox) filling area of a closed path. |
| 270 | The semantic meaning may be table shading, or text style like highlight. |
| 271 | ''' |
| 272 | |
| 273 | def to_stroke(self, max_border_width:float): |
| 274 | '''Convert to Stroke instance based on width criterion. |
| 275 | |
| 276 | Args: |
| 277 | max_border_width (float): Stroke width must less than this value. |
| 278 | |
| 279 | Returns: |
| 280 | Stroke: Stroke instance. |
| 281 | |
| 282 | .. note:: |
| 283 | A Fill from shape point of view may be a Stroke from content point of view. |
| 284 | The criterion here is whether the width is smaller than defined ``max_border_width``. |
| 285 | ''' |
| 286 | w = min(self.bbox.width, self.bbox.height) |
| 287 | |
| 288 | # not a stroke if exceed max border width |
| 289 | if w > max_border_width: |
| 290 | return None |
| 291 | else: |
| 292 | return Stroke({'width': w, 'color': self.color}).update_bbox(self.bbox) |
| 293 | |
| 294 | |
| 295 | @property |
| 296 | def default_type(self): |
| 297 | '''Default semantic type for a Fill shape: table shading or text highlight.''' |
| 298 | return RectType.SHADING.value | RectType.HIGHLIGHT.value |
| 299 | |
| 300 | def _semantic_type(self, line): |
| 301 | '''Override. Check semantic type based on the position to a text line. Along the main dimension, |
| 302 | text highlight never exceeds text line. |
| 303 | |
| 304 | Args: |
| 305 | line (Line): A text line. |
| 306 | |
| 307 | Returns: |
| 308 | RectType: Semantic type of this shape. |
| 309 | |
| 310 | .. note:: |
| 311 | Generally, table shading always contains at least one line, while text highlight never |
| 312 | contains any lines. But in real cases, with margin exists, table shading may not 100% |
| 313 | contain a line. |
| 314 | ''' |
| 315 | # check main dimension |
| 316 | h_shape = self.bbox.width>self.bbox.height |
| 317 | w_shape = self.bbox.width if h_shape else self.bbox.height |
| 318 | |
| 319 | # check orientation |
| 320 | h_line = line.is_horizontal_text |
| 321 | if h_shape != h_line: |
| 322 | return self.default_type |
| 323 | |
| 324 | if not self.get_main_bbox(line, threshold=constants.FACTOR_MAJOR): |
| 325 | return self.default_type |
no outgoing calls
no test coverage detected
searching dependent graphs…