Results 1 to 3 of 3

Thread: Hershey Fonts

  1. #1
    Join Date
    Jul 2020
    Posts
    2

    Post Hershey Fonts

    Please, would anyone have a tutorial on how to write code to interpret Hershey fonts? I need to create G-code from text fonts. Can someone help me?
    Thank you

  2. #2
    Join Date
    Sep 2006
    Location
    Garland Tx
    Posts
    2,277

    Default

    Not exactly sure what you need...
    Does this help?

    http://paulbourke.net/dataformats/hershey/

  3. #3
    Join Date
    Mar 2008
    Location
    Tulsa Oklahoma
    Posts
    1,238

    Default

    Hello- Im quite happy to share my code on this subject, but note that its "object-oriented" c#, so its not a trivial subject to explain.

    Dr Hershey designed this font system to drive XY plotters, which make they very useful for things like ShopBots which also act like XY plotters. However converting hershey data to drive a shopbot or any specific device required me to write some code to make the process generic. The interface to a specific "plotter" is controlled by two call-back functions:
    public delegate void EngraverMoveCommand(double X, double Y, object Opaque);
    public delegate void EngraverPenDownCommand(bool PenDown, object Opaque);

    If how to use that is reasonably obvious- then keep reading.

    My C# hershey font interpreter defines a series of objects in 5 source files. None of them can control an engraver directly, it is up to the reader to supply the functions requested above. The opaque parameter is present to allow "extra data" required by a given engraver to be passed through the system.

    The general idea is that an engraved letter of the alphabet may be one or more engraving motions. Each motion is named a "scribble". Each letter to be engraved is a glyph which may have 0 or more component scribbles. Each hershey font (really a typeface) is a list of glyphs, often sharing glyphs between several hershey fonts. Charcters like period are not duplicated, there is one definition of the glyph for period and all the fonts call for that definition to be used when a period is needed. Many glyphs are shared, that is the purpose of the font tables, is to list the glyph numbers needed to engrave letters in that font.

    Scribbles handle things like the letter i. Which is actually two engravings to form one letter (glyph), so i has two scribbles. Letters like zero with a slash through it are also two scribbles, etc. My code handles the details, the two call-back functions drive the plotter.

    A HersheyFontFace is the definition of a typeface like "old english" within the hershey glyph defaintions. The hershey fonts define several type faces, and there have been additions by other people after Dr Hershey's original work.

    HersheyFontData is the file with the original Hershey scribble definitions, and the glyph/scribble associations to characters.

    HersheyFont is the class that pulls all this together, and provides the interface to engrave (or draw) something in vector form.

    Here is an example program of using all this:
    class Program
    {
    static void Main(string[] args)
    {
    HersheyFont Engraver = new HersheyFont();

    // start the engraver here
    // this function does the engraving.
    Engraver.EngraveString("Howdy", "Roman Simplex", 3.0, 2.0, 0.5, Move, PenControl, null);
    // stop the engraver here
    }

    public static void Move(double X, double Y, object Opaque)
    {
    // move the engraver to X, Y
    // wait for move complete if in direct control of the engraver
    }

    public static void PenControl(bool Down, object Opaque)
    {
    // raise or lower the engraver into the material. This will get called many times to lower the pen
    // to save time if it is alreay down or up, ignore the request.

    if(Down)
    {
    // lower the engraver into the material
    }
    else
    {
    // raise the engraver out of the material and clear of obstacles.
    }
    }
    }


    If anybody is seriously interested in pursuing this, I will zip the 5 files and post them.



    D
    "The best thing about building something new is either you succeed or learn something. Its a win-win situation."

    --Greg Westbrook

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •