Click here to Skip to main content
Licence 
First Posted 28 Mar 2000
Views 69,016
Bookmarked 26 times

Hershey Font wrapper class

By | 28 Mar 2000 | Article
Using Hershey vector fonts for faster rendering
  • 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



    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. (secure sign-in)
     
    Search this forum  
     FAQ
        Noise  Layout  Per page   
      Refresh
    QuestionHow faster ? PinmemberAlexandre GRANVAUD20:19 8 Sep '09  
    GeneralProblem editing new symbol Pinmemberandywolpert10:50 19 Sep '05  
    GeneralPermission to use the class Pinmemberallanwright13:01 1 Mar '03  
    GeneralWow! PinmemberSwinefeaster0:06 12 Aug '02  
    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! Pinmemberrakkar13:23 13 Nov '02  
    GeneralRe: Wow! PinmemberChris Richardson14:04 17 Dec '02  
    GeneralRe: Wow! Pinmemberplanetfall20:03 6 Jun '04  
    GeneralRe: Wow! PinmemberPaul Selormey23:10 17 Jun '04  

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

    Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

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