Click here to Skip to main content
Click here to Skip to main content

Hershey Font wrapper class

By , 28 Mar 2000
 
  • Download demo project - 51 Kb
  • Sample Image - HersheyFont.gif

  • Download FontEdit sample program - 68 Kb
  • Download Font data files - 156 Kb
  • Recently when building a GIS display system I ran into the problem of displaying characters at many different sizes, rotations (escapments), and in several typefaces all in the same view. Unfortunately the redraw performance I was able to obtain using Windows' font routines was not very good. Reaching back to my past (and definitely showing my age) I decided to use the venerable "Hershey" vector fonts.

    All of the font management and display is wrapped up the class SMFontUtil the use of which it illustrated in the FontDemo program included. The only method of any real consequence is:

    void SMFontUtil::DrawString(
    	CDC * pDC,            //device context to draw to
    	CPoint pStart,        //starting point
    	double pRotation,     //rotation angle clockwise in radians (0 = 12:00)
    	double pCharWidth,    //width of each character
    	double pCharHeight,   //height of each character
    	FONT_TYPE pFontType,  //the font to use
    	CString pString)      //the string
    

    NOTE: For this article I hard-coded the path so that the font definition data (found in FontData.zip) must reside in C:\HersheyFonts. In the real system this is stored on a server with the GIS data.

    The original Hershey font character codes do not match well ASCII. I have built a translation table that maps ASCII character and font to a Hershey character. The included fonts are:

    • SMALL_SIMPLEX
    • SMALL_DUPLEX
    • SIMPLEX
    • DUPLEX
    • TRIPLEX
    • MODERN
    • SCRIPT_SIMPLEX
    • SCRIPT_DUPLEX
    • ITALLIC_DUPLEX
    • ITALLIC_TRIPLEX
    • FANCY
    • GOTHIC

    I have also included a crude font editor that lets you edit the vertices and the translation table. To edit a character right click on it in any view. To assign a hershey font to a ASCII font family pairing select the character in the numeric view and select "index save" from the menu. Switch to Xlated view and select the target cell, then select "Assign Index".

    The font data resides in two files. The vector data, and the translation table I have supplied both the runtime version, and a human readable version in CSV format for those who wish to use them. The SMFontUtils class provides a method to convert from the CSV to the runtime. Again, please note that for the purposes of this article the font definition data (FontData.zip) must be extracted into C:\HersheyFonts.

    License

    This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

    A list of licenses authors might use can be found here

    About the Author

    Randy More
    United States United States
    Member
    No Biography provided

    Sign Up to vote   Poor Excellent
    Add a reason or comment to your vote: x
    Votes of 3 or less require a comment

    Comments and Discussions

     
    You must Sign In to use this message board.
    Search this forum  
        Spacing  Noise  Layout  Per page   
    QuestionHow faster ?memberAlexandre GRANVAUD8 Sep '09 - 20:19 
    Could you say how faster it is ?
    Thanks
    GeneralProblem editing new symbolmemberandywolpert19 Sep '05 - 10:50 
    First off this is a great program! I am learning alot about graphics and fonts from experimenting with it.
     
    I want to define some symbols of my own within the number space of the Hershey Fonts.
     
    When I use the FontManager program I get an extra line in each character that goes to a point I never defined, I think it is (-512, 0)
     
    For example I edit an exisitng character, delete all of its lines, then I:
    1. left click somewhere
    2. move the mouse
    3. right click
     
    I get two lines insteadof one!
     
    Any suggestions about how to use fontmanager to create new symbols?
    I am hoping it is something as simple as the correct mouse operations.
     
    Tnanks,
     
    Andy

    GeneralPermission to use the classmemberallanwright1 Mar '03 - 13:01 
    Randy,
     
    I am writing a printed-circuit board layout program which I intend to post on the Internet as an Open Source project, probably under the GPL or something similar. It is called FreePCB, and I have registerd FreePCB.com for the website.
     
    I downloaded your code, and I would like to use your Hershey Font class in my program. I will give you credit on the website and in the code. If this is OK, please send me an email giving me permission to use your code.
     
    Thanks,
     
    Allan Wright
    allanwright@attbi.com
    GeneralWow!memberSwinefeaster12 Aug '02 - 0:06 
    This is pretty cool Wink | ;) . Very tiny DrawString() funtion too!
     
    Any ideas on how to convert a system true type font to a hershey font? I'm trying to store fonts within a binary file so they can be used on machines which do not necessarily have those fonts installed. Any ideas on how I can do this?
     
    Thanx!
     
    Swine
     
    Check out Aephid Photokeeper, the powerful digital
    photo album solution at www.aephid.com.

    GeneralRe: Wow!memberrakkar13 Nov '02 - 13:23 
    Sux, the zip file for the source code doesn't contain smfontutil.cpp, which contains the class. Why would we want the code if we can't compile it and don't get the class?Mad | :mad:
    GeneralRe: Wow!memberChris Richardson17 Dec '02 - 14:04 
    I found smfontutil.cpp located in the zip file I downloaded. Here's a link to the zip file:
     
    http://www.codeproject.com/gdi/HersheyFont/FontEdit.zip[^]
     
    Chris Richardson
     
    Programmers find all sorts of ingenious ways to screw ourselves over. - Tim Smith
    GeneralRe: Wow!memberplanetfall6 Jun '04 - 20:03 
    Everything works great for me. Its quickly becomes obvious that you need to unzip
    FontData.zip to 'c:\HersheyFonts' folder,
    FontEdit.zip to 'c:\FontManager' Folder, and
    HersheyFont.zip to 'c:\HersheyFont' folder
     
    after that lock and load! This is very cool stuff.
     
    Is the Hershey Font data free? Would it be legal to use the Font data in a commercial product?

    GeneralRe: Wow!memberPaul Selormey17 Jun '04 - 23:10 
    planetfall wrote:
    Is the Hershey Font data free? Would it be legal to use the Font data in a commercial product?
     
    Yes, public domain - see here.
     
    Best regards,
    Paul.

     
    Jesus Christ is LOVE! Please tell somebody.

    General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

    Permalink | Advertise | Privacy | Mobile
    Web04 | 2.6.130523.1 | Last Updated 29 Mar 2000
    Article Copyright 2000 by Randy More
    Everything else Copyright © CodeProject, 1999-2013
    Terms of Use
    Layout: fixed | fluid