Skip to main content

SHX Line Font Parser

Project description

shxparser

Pure Python Parser for SHX Hershey font files.

SHX files are an AutoCad format which can encode single line fonts.

This format is used for many CNC and laser operations.


Progress

Things currently parse, text converts to paths. There may be edge cases and bugs within the code.

Encoding

Calling the parser on a SHX file will parse the file. The glyph data is accessed via the ShxFile.glyphs dictionary which stores the particular commands. These positions are stored (or will be) in segments. Each segment is:

  • (x0,y0) -- Move to Position.
  • ((x0,y0), (x1, y1)) --- Straight Line start->end
  • ((x0,y0), (cx, cy), (x1, y1)) --- Arc start->control->end where control is a point on the arc that starts at start and ends at end.

Usage

See test_parser.py for usage:

    def test_parse(self):
        for f in chain(glob("parse/*.SHX"), glob("parse/*.shx")):
            shx = ShxFont(f)
            paths = ShxPath()
            shx.render(paths, "The quick brown fox jumps over the lazy dog", font_size=50)
            draw(paths, 2000, 100, 50, f"{f}.png")

SCRIPTS8 SHX

Format

For some format descriptions and explanations see:

And:

Primarily the format performs regular (octant direction, distance) and 15 speciality operations.

Regular Command

  • Direction, Length pair. If Length is 0 then direction is special command.

Special Commands

  • END_OF_SHAPE - Ends the shape.
  • PEN_DOWN - Puts the pen down into drawing mode.
  • PEN_UP - Puts the pen up into move mode.
  • DIVIDE_VECTOR - Applies a vector 1/scale
  • MULTIPLY_VECTOR - Applies a vector scale
  • PUSH_STACK - Pushes current position to the stack.
  • POP_STACK - Pops current position from the stack.
  • DRAW_SUBSHAPE - References the glyph data of another glyph.
  • XY_DISPLACEMENT - Moves to a long dx, dy position.
  • POLY_XY_DISPLACEMENT - Performs a sequence of long dx, dy position changes. 0,0 terminates.
  • OCTANT_ARC - Performs an octant_arc operation. Performing an arc across some octants.
  • FRACTIONAL_ARC - Performs an octant_arc operation with fractional value offsets.
  • BULGE_ARC - Performs bulge arc operations with dx, dy, and bulge.
  • POLY_BULGE_ARC - Performs a sequence of bulge arc operations. 0,0 terminates.
  • COND_MODE_2 - Performs the next command conditionally, and only if the current mode is vertical.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

shxparser-0.0.2.tar.gz (12.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

shxparser-0.0.2-py2.py3-none-any.whl (11.3 kB view details)

Uploaded Python 2Python 3

File details

Details for the file shxparser-0.0.2.tar.gz.

File metadata

  • Download URL: shxparser-0.0.2.tar.gz
  • Upload date:
  • Size: 12.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.8.10

File hashes

Hashes for shxparser-0.0.2.tar.gz
Algorithm Hash digest
SHA256 8541e4bce62876822c93f3959e7f6909ef1bf8352691b343bacdaaa9b92ff270
MD5 efa4b91fc53ba60c92510e69ee082253
BLAKE2b-256 1f819cc013c54afaf1bce5ce5f569580d6624e02f9b3f20b41b243556b9247b1

See more details on using hashes here.

File details

Details for the file shxparser-0.0.2-py2.py3-none-any.whl.

File metadata

  • Download URL: shxparser-0.0.2-py2.py3-none-any.whl
  • Upload date:
  • Size: 11.3 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.8.10

File hashes

Hashes for shxparser-0.0.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 ccd37c9d63440f8c961189bf58d4a90db23ec7b31e4c12175267f0f780db7a6c
MD5 4ff78bac48eda6922930c8761cd0b6e2
BLAKE2b-256 57fb98c8204a5348566f24ee23127a680a9b5ddd3614ecc5a00a4efe4d5f53e4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page