(EXPERIMENTAL) Drawing SVG paths ================================ Using the ``drawSVG`` function ------------------------------ To import the ``drawSVG`` function: .. literalinclude:: svg/svg_demo.py :language: python :lines: 3 This function takes in 3 compulsory positional arguments: a turtle, the svg file path string, and the height of the SVG. The width can also be passed as a 4th positional argument, and defaults to the same value as the height. The keyword arguments it takes are: - ``fill`` : bool, optional. If True, the SVG will be filled. Default is True. - ``outline`` : bool, optional. If True, the SVG will be outlined. Default is False. - ``full_fill`` : bool, optional. If True, the SVG will be fully filled if set to fill, otherwise it will be partially filled. Default is True. - ``fill_min_y_dist`` : int, optional. The minimum distance between fill points in the y direction. Default is 10 (1mm). - ``fill_min_x_dist`` : int, optional. The minimum distance between fill points in the x direction. Default is 10 (1mm). Here is a sample of it in action: .. literalinclude:: svg/svg_demo.py :language: python :linenos: .. image:: ../../_static/figures/svg/c.png :alt: SVG demo image Debugging the SVG file ---------------------- If you encounter issues with your SVG file, try the following checklist: - If it is fill: check that the fill path does not cross itself - Our fill algorithm may not work if the path of the SVG crosses over - Our fill feature is also very experimental, and there is a high chance of it having errors as of now. Viewing the SVG file as text ---------------------------- To view an SVG file as text, open an SVG file with a basic text editor like Notepad/Notepad++, or draw an SVG file into it. This will show the text of the SVG file, which should look like the below image: .. image:: ../../_static/figures/svg/svg_file_text_sample.png :alt: SVG file text sample ``viewBox`` attribute --------------------- In the ```` tag in the SVG file, there should be a ``viewBox`` attribute, such as the following tag: ```` If the ``viewBox`` attribute does not exist, you should create it yourself; this defines the 0% and 100% positions that the later SVG commands will use. Normally, if an SVG file does not specify the viewBox, you can use its height and width. For example: ```` Can be changed to ```` We have not tested on SVG files with their viewBox starting with anything but ``0 0``, so there might be issues with those SVG files. For those, please raise a GitHub Issue for us to resolve it. ```` tag -------------- In our program, we only draw the paths enclosed in a ```` tag in the SVG file. For example, we can see in the screenshot of what an SVG file looks like that there is a ```` tag that contains a string describing the path that the SVG file takes. First, check that the SVG path you are trying to draw is in a ```` tag. Ensure that the path string ends with a "z" or "Z", which signals the end of the path. If it does not have one, then add it. If nothing works ---------------- Raise a GitHub Issue.