コード例 #1
0
def _get_extra_transform(text: AnyText) -> Matrix44:
    extra_transform = Matrix44()
    if isinstance(text, Text):
        # ALIGNED: scaled to fit in the text box (aspect ratio preserved). Does not have to be handled specially.
        # FIT: scaled to fit in the text box (aspect ratio *not* preserved). Handled by dxf.width
        scale_x = text.dxf.width  # 'width' is the width *scale factor* so 1.0 by default
        scale_y = 1
        if text.dxf.text_generation_flag & DXFConstants.MIRROR_X:
            scale_x *= -1
        if text.dxf.text_generation_flag & DXFConstants.MIRROR_Y:
            scale_y *= -1

        # magnitude of extrusion does not have any effect. An extrusion of (0, 0, 0) acts like (0, 0, 1)
        scale_x *= sign(text.dxf.extrusion.z)

        if scale_x != 1 or scale_y != 1:
            extra_transform = Matrix44.scale(scale_x, scale_y)

    elif isinstance(text, MText):
        # not sure about the rationale behind this but it does match AutoCAD behavior...
        scale_y = sign(text.dxf.extrusion.z)
        if scale_y != 1:
            extra_transform = Matrix44.scale(1, scale_y)

    return extra_transform
コード例 #2
0
def transform_thickness_and_extrusion_without_ocs(entity: 'DXFGraphic', m: Matrix44) -> None:
    if entity.dxf.hasattr('thickness'):
        thickness = entity.dxf.thickness
        reflection = sign(thickness)
        thickness = m.transform_direction(entity.dxf.extrusion * thickness)
        entity.dxf.thickness = thickness.magnitude * reflection
        entity.dxf.extrusion = thickness.normalize()
    elif entity.dxf.hasattr('extrusion'):  # without thickness?
        extrusion = m.transform_direction(entity.dxf.extrusion)
        entity.dxf.extrusion = extrusion.normalize()
コード例 #3
0
ファイル: text.py プロジェクト: Rahulghuge94/ezdxf
def _get_extra_transform(text: AnyText, line_width: float) -> Matrix44:
    extra_transform = Matrix44()
    if isinstance(text, Text):  # Attrib and AttDef are sub-classes of Text
        # 'width' is the width *scale factor* so 1.0 by default:
        scale_x = text.dxf.width
        scale_y = 1.0

        # Calculate text stretching for FIT and ALIGNED:
        alignment = text.get_align_enum()
        line_width = abs(line_width)
        if (
            alignment in (TextEntityAlignment.FIT, TextEntityAlignment.ALIGNED)
            and line_width > 1e-9
        ):
            defined_length = (text.dxf.align_point - text.dxf.insert).magnitude
            stretch_factor = defined_length / line_width
            scale_x = stretch_factor
            if alignment == TextEntityAlignment.ALIGNED:
                scale_y = stretch_factor

        if text.dxf.text_generation_flag & DXFConstants.MIRROR_X:
            scale_x *= -1.0
        if text.dxf.text_generation_flag & DXFConstants.MIRROR_Y:
            scale_y *= -1.0

        # Magnitude of extrusion does not have any effect.
        # An extrusion of (0, 0, 0) acts like (0, 0, 1)
        scale_x *= sign(text.dxf.extrusion.z)

        if scale_x != 1.0 or scale_y != 1.0:
            extra_transform = Matrix44.scale(scale_x, scale_y)

    elif isinstance(text, MText):
        # Not sure about the rationale behind this but it does match AutoCAD
        # behavior...
        scale_y = sign(text.dxf.extrusion.z)
        if scale_y != 1.0:
            extra_transform = Matrix44.scale(1.0, scale_y)

    return extra_transform
コード例 #4
0
 def transform_length(self, length: 'Vertex', reflection=1.0) -> float:
     """ Returns magnitude of `length` direction vector transformed from
     old OCS into new OCS including `reflection` correction applied.
     """
     return self.m.transform_direction(
         self.old_ocs.to_wcs(length)).magnitude * sign(reflection)