示例#1
0
 def draw_path(self, path: Path, properties: Properties, z=0):
     qt_path = qg.QPainterPath()
     _extend_qt_path(qt_path, path)
     return self.scene.addPath(
         qt_path,
         self.get_pen(properties),
         self.no_fill,
     )
示例#2
0
 def get_text_path(self, text: str, font: qg.QFont) -> qg.QPainterPath:
     # None is the default font
     key = font.key() if font is not None else None
     cache = self._text_path_cache[key]  # defaultdict(dict)
     path = cache.get(text, None)
     if path is None:
         if font is None:
             font = self._default_font
         path = qg.QPainterPath()
         path.addText(0, 0, font, text)
         if self._use_cache:
             cache[text] = path
     return path
示例#3
0
 def draw_path(self, path, properties: Properties, z=0):
     pattern = self.pattern(properties)
     pen = self.get_pen(properties)
     if len(pattern) < 2:
         qt_path = qg.QPainterPath()
         _extend_qt_path(qt_path, path)
         return self.scene.addPath(qt_path, pen, self.no_fill)
     else:
         add_line = self.scene.addLine
         renderer = EzdxfLineTypeRenderer(pattern)
         segments = renderer.line_segments(
             path.flattening(
                 self._config.max_flattening_distance, segments=16
             )
         )
         return [
             add_line(s.x, s.y, e.x, e.y, pen)
             for s, e in segments
             # PyQt has problems with very short lines:
             if not s.isclose(e)
         ]
示例#4
0
 def draw_filled_paths(
     self,
     paths: Iterable[Path],
     holes: Iterable[Path],
     properties: Properties,
 ) -> None:
     qt_path = qg.QPainterPath()
     for path in paths:
         try:
             path = path.counter_clockwise()
         except ValueError:  # cannot detect path orientation
             continue
         _extend_qt_path(qt_path, path)
     for path in holes:
         try:
             path = path.clockwise()
         except ValueError:  # cannot detect path orientation
             continue
         _extend_qt_path(qt_path, path)
     item = _CosmeticPath(qt_path)
     item.setPen(self._get_pen(properties))
     item.setBrush(self._get_brush(properties))
     self._scene.addItem(item)
     self._set_item_data(item)