Ejemplo n.º 1
0
 def draw_text(
     self,
     text: str,
     transform: Matrix44,
     properties: Properties,
     cap_height: float,
 ):
     if not text.strip():
         return  # no point rendering empty strings
     font_properties = self.get_font_properties(properties.font)
     assert self.current_entity is not None
     text = prepare_string_for_rendering(text,
                                         self.current_entity.dxftype())
     x, y, _, _ = transform.get_row(3)
     rotation = transform.transform_direction(X_AXIS).angle_deg
     self.ax.text(
         x,
         y,
         text.replace("$", "\\$"),
         color=properties.color,
         size=cap_height * self._text_size_scale,
         rotation=rotation,
         in_layout=True,
         fontproperties=font_properties,
         transform_rotates_text=True,
         zorder=self._get_z(),
     )
Ejemplo n.º 2
0
 def draw_text(
     self,
     text: str,
     transform: Matrix44,
     properties: Properties,
     cap_height: float,
 ):
     if not text.strip():
         return  # no point rendering empty strings
     font_properties = self.get_font_properties(properties.font)
     assert self.current_entity is not None
     text = prepare_string_for_rendering(text,
                                         self.current_entity.dxftype())
     transformed_path = _transform_path(
         self._text_renderer.get_text_path(text, font_properties),
         Matrix44.scale(
             self._text_renderer.get_scale(cap_height, font_properties))
         @ transform,
     )
     self.ax.add_patch(
         PathPatch(
             transformed_path,
             facecolor=properties.color,
             linewidth=0,
             zorder=self._get_z(),
         ))
Ejemplo n.º 3
0
 def get_text_line_width(self, text: str, cap_height: float,
                         font: str = None) -> float:
     if not text.strip():
         return 0
     dxftype = self.current_entity.dxftype() if self.current_entity else 'TEXT'
     text = prepare_string_for_rendering(text, dxftype)
     font_properties = self.get_font_properties(font)
     path = self._text_renderer.get_text_path(text, font_properties)
     return max(x for x, y in path.vertices) * self._text_renderer.get_scale(
         cap_height, font_properties)
Ejemplo n.º 4
0
    def get_text_line_width(self, text: str, cap_height: float,
                            font: fonts.FontFace = None) -> float:
        if not text.strip():
            return 0

        dxftype = self.current_entity.dxftype() if self.current_entity else 'TEXT'
        text = prepare_string_for_rendering(text, dxftype)
        qfont = self.get_qfont(font)
        scale = self._text_renderer.get_scale(cap_height, qfont)
        return self._text_renderer.get_text_rect(text, qfont).right() * scale
Ejemplo n.º 5
0
 def get_text_line_width(self,
                         text: str,
                         cap_height: float,
                         font: str = None) -> float:
     if not text:
         return 0
     text = prepare_string_for_rendering(text,
                                         self.current_entity.dxftype())
     path = _text_path(text, self.font)
     scale = cap_height / self._font_measurements.cap_height
     return max(x for x, y in path.vertices) * scale
Ejemplo n.º 6
0
    def get_text_line_width(self,
                            text: str,
                            cap_height: float,
                            font: str = None) -> float:
        if not text:
            return 0

        dxftype = self.current_entity.dxftype(
        ) if self.current_entity else 'TEXT'
        text = prepare_string_for_rendering(text, dxftype)
        scale = cap_height / self._font_measurements.cap_height
        return _get_text_rect(self._font, text).right() * scale
Ejemplo n.º 7
0
    def draw_text(self, text: str, transform: Matrix44, properties: Properties, cap_height: float) -> None:
        if not text:
            return  # no point rendering empty strings
        text = prepare_string_for_rendering(text, self.current_entity.dxftype())

        scale = cap_height / self._font_measurements.cap_height
        transform = Matrix44.scale(scale, -scale, 0) @ transform

        path = qg.QPainterPath()
        path.addText(0, 0, self._font, text)
        path = _matrix_to_qtransform(transform).map(path)
        item = self.scene.addPath(path, self._no_line, self._get_color(properties.color))
        self._set_item_data(item)
Ejemplo n.º 8
0
    def draw_text(self, text: str, transform: Matrix44, properties: Properties,
                  cap_height: float) -> None:
        if not text.strip():
            return  # no point rendering empty strings
        text = prepare_string_for_rendering(text, self.current_entity.dxftype())
        qfont = self.get_qfont(properties.font)
        scale = self._text_renderer.get_scale(cap_height, qfont)
        transform = Matrix44.scale(scale, -scale, 0) @ transform

        path = self._text_renderer.get_text_path(text, qfont)
        path = _matrix_to_qtransform(transform).map(path)
        item = self._scene.addPath(path, self._no_line,
                                   self._get_color(properties.color))
        self._set_item_data(item)
Ejemplo n.º 9
0
 def draw_text(self, text: str, transform: Matrix44, properties: Properties,
               cap_height: float):
     if not text:
         return  # no point rendering empty strings
     text = prepare_string_for_rendering(text,
                                         self.current_entity.dxftype())
     scale = cap_height / self._font_measurements.cap_height
     path = _text_path(text, self.font)
     transformed_path = _transform_path(path,
                                        Matrix44.scale(scale) @ transform)
     self.ax.add_patch(
         PathPatch(transformed_path,
                   facecolor=properties.color,
                   linewidth=0,
                   zorder=self._get_z()))