Draw the image in the calculated (w, h). Because we need to use the image by scale transform, all other measure (position, lineWidth) are scaled back to their original proportions. If stroke is defined, then use that to draw a frame around the image. Note that the (s
(self, view, origin=ORIGIN, **kwargs)
| 423 | e.prepare(view) |
| 424 | |
| 425 | def build(self, view, origin=ORIGIN, **kwargs): |
| 426 | """Draw the image in the calculated (w, h). Because we need to use the |
| 427 | image by scale transform, all other measure (position, lineWidth) are |
| 428 | scaled back to their original proportions. |
| 429 | |
| 430 | If stroke is defined, then use that to draw a frame around the image. |
| 431 | Note that the (sx, sy) is already scaled to fit the padding position |
| 432 | and size.""" |
| 433 | p = pointOffset(self.origin, origin) |
| 434 | ox, oy = point2D(p) |
| 435 | p = self._applyScale(view, p) |
| 436 | # Ignore z-axis for now. |
| 437 | px, py, _ = p = self._applyAlignment(p) |
| 438 | |
| 439 | self._applyRotation(view, p) |
| 440 | |
| 441 | # Let the view draw frame info for debugging, in case view.showFrame == True |
| 442 | # and self.isPage or if self.showFrame. Mark that we are drawing background here. |
| 443 | view.drawPageMetaInfoBackground(self, p) |
| 444 | |
| 445 | if self.path is None or not os.path.exists(self.path) or not self.iw or not self.ih: |
| 446 | # Missing image, show as framed grey rectangles and cross. |
| 447 | if self.path is not None and not os.path.exists(self.path): |
| 448 | print('Warning: cannot find image file %s' % self.path) |
| 449 | |
| 450 | # Draw missing element as cross |
| 451 | xpt, ypt, wpt, hpt = upt(px, py, self.w, self.h) |
| 452 | self.context.stroke(0.5) |
| 453 | self.context.strokeWidth(0.5) |
| 454 | self.context.fill(None) |
| 455 | self.context.rect(xpt, ypt, wpt, hpt) |
| 456 | self.context.line((xpt, ypt), (xpt+wpt, ypt+hpt)) |
| 457 | self.context.line((xpt+wpt, ypt), (xpt, ypt+hpt)) |
| 458 | |
| 459 | else: # There is a valid image path, |
| 460 | self.context.save() |
| 461 | # Check if scaling exceeds limit, then generate a cached file and |
| 462 | # update the path and (self.iw, self.ih) accordingly. |
| 463 | |
| 464 | clipPath = self.clipPath |
| 465 | |
| 466 | if clipPath is not None: |
| 467 | clipPath.translate(origin[0], origin[1]) |
| 468 | |
| 469 | if self.imo is not None: |
| 470 | with self.imo: |
| 471 | self.context.image(self.path, p=(0, 0), pageNumber=1, alpha=self._getAlpha(), |
| 472 | w=self.w, h=self.h, scaleType=self.scaleType) |
| 473 | self.context.image(self.imo, p=(px, py), pageNumber=self.index, |
| 474 | alpha=self._getAlpha(), w=self.w, h=self.h, |
| 475 | scaleType=self.scaleType, clipPath=clipPath) |
| 476 | else: |
| 477 | self.context.image(self.path, p=(px, py), pageNumber=self.index, |
| 478 | alpha=self._getAlpha(), w=self.w, h=self.h, |
| 479 | scaleType=self.scaleType, clipPath=clipPath) |
| 480 | |
| 481 | # TODO: Draw optional (transparent) forground color? |
| 482 | self.context.restore() |
nothing calls this directly
no test coverage detected