Bitbybit Docs
    Preparing search index...

    Class Svg

    Writes SVG drawings from the same path parts DXF files are made of: lines, arcs, circles, bulged polylines, splines and ellipses, kept exact wherever SVG can draw them. Reads SVG files back into those parts, by layer, color and line type.

    Index

    Constructors

    svg

    • Writes an SVG file from path parts, each layer an Inkscape layer.

      Arcs, circles, ellipses and bulges stay exact arcs, unweighted splines up to degree 3 exact Beziers, others cubics within tolerance (at least a millionth of the drawing). Y points up, Z is dropped and unit gives the true size. A drawing too large to write throws.

      Parameters

      • inputs: SvgModelDto

        The path parts, the unit, the line width, the border and the curve tolerance

      Returns string

      The SVG file as text

      const square = bitbybit.io.drawing.polylineSegment({ points: [[0, 0], [40, 0], [40, 30], [0, 30]], closed: true });
      const hole = bitbybit.io.drawing.circleSegment({ center: [20, 15], radius: 6 });
      const part = bitbybit.io.drawing.part({ layer: "cut", color: "#ff0000", paths: [{ segments: [square] }, { segments: [hole] }] });
      const svg = bitbybit.io.svg.svgCreate({ parts: [part], unit: Bit.Inputs.Base.unitOfLengthEnum.millimetre });
    • Writes one drawing path as SVG path data, the text of a path element's d attribute.

      Segments that meet are drawn as one stroke, reversed where a segment ends where the stroke is, and a stroke that returns to its start is closed. Curves are kept exact as svgCreate keeps them.

      Parameters

      • inputs: SvgPathDataDto

        The path, whether Y is negated, and the curve tolerance

      Returns string

      SVG path data

      const slot = bitbybit.io.drawing.polylineSegment({ points: [[0, 0], [30, 0], [30, 10], [0, 10]], closed: true, bulges: [0, 1, 0, 1] });
      const data = bitbybit.io.svg.pathData({ path: { segments: [slot] }, flipY: false });
    • Reads an SVG file into path parts by layer, color and line type, the model svgCreate writes.

      Lines, arcs and Bezier curves are read exactly, transforms applied and Y turned up. Inkscape layers are layers, each stroke color (else fill) a color, each dash pattern a line type. Text and images are left out and named in warnings.

      Parameters

      • inputs: SvgReadDto

        The SVG text, the unit to read it in and whether hidden elements are read

      Returns SvgDrawingDto

      The drawing's parts, unit, view box and warnings

      const drawing = bitbybit.io.svg.svgRead({ svg: svgText, unit: Bit.Inputs.Base.unitOfLengthEnum.millimetre });
      const dxf = bitbybit.io.dxf.dxfCreate({ dxfPathsParts: drawing.parts, unit: drawing.unit });