Thread: Fonts

  1. #1
    Registered User
    Join Date
    Nov 2007
    Posts
    9

    Fonts

    I am using a DOS based C complier (MS Quick C) to program a simple baseball game. It will mirror the old handheld games (mattel / entex) I have the game function completed and am working on the graphic interface.

    My question - Does anyone know how fonts are written for DOS programs? Are there Libraries for it out there, or do I need to write my own. Do I use a pixel command and just draw my own, or incooperate some sort of bit map storing function.

    Yes I have heard the common thoughts on DOS. Yes it's behind the times and arcaic. (sp?) but I am trying to get used to programming again so I took off from where I am most familiar.

    Thanks in advance.
    Ace

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    There was another similar question not so long ago. I think the answer was "no there's no known font editing programs available". Of course, I'm pretty sure that the Borland fonts are just bit-map-data in some defined format with some small header, so it shouldn't be impossible to create an application that does the same thing.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    It's heavily dependent on how many features your graphics library has.

    I have an old paint program that I wrote for DOS a long time ago. Its interface sucks and there's no help, but you can save in several formats (most [all?] of which I made up), including C source code.

    I also have some code to write text, pixel-by-pixel, on a screen approximately 320x200. (Any larger, and the text looks like an ant wrote it.) I could send it to you if you wanted.

    Both of these compile and run under DJGPP, but I'm sure you could modify them for your needs.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  4. #4
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    Font are a relatively simple thing to do if you are not super picky.

    First you would create your glyphs and place them in an image file.
    Next you need a string representing their order in the image file.

    To render you get the index of the currently needed glyph in the string.
    That index can then be converted to a row and column.

    Row = GlyphIndex / NumGlyphsPerRow;
    Column = GlyphIndex % NumGlyphsPerRow;

    ImageLocationX = Row * GlyphCellSize;
    ImageLocationY = Column * GlyphCellSize;

    Blit the image in this rectangle to the screen and you have a rudimentary font machine.

    RECT blitRect;
    blitRect.left = ImageLocationX;
    blitRect.top = ImageLocationY;
    blitRect.right = ImageLocationX + GlyphCellSize;
    blitRect.bottom = ImageLocationY + GlyphCellSize;

    Granted this is a monospace font but you could add functionality to the algo to support variable width fonts.

  5. #5
    Registered User
    Join Date
    Nov 2007
    Posts
    9

    Thanks

    Hey guys,

    Thanks for the information DWK I'll take the source code if you have it. Thanks alot.

    Ace

  6. #6
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Okay, I've uploaded a few things.
    • alpha.c: my (uppercase-only) DOS 5x3 font
    • paint2.txt (really .tar.gz): my paint program with the incomprehensible interface
    • dsfont.txt (really .tar.gz): newer SDL code to demonstrate simple block fonts
    • denora-font.txt (really .tar.gz): some GNU GPL fonts

    Just so you know: none of this is very well written. It's really old code. I recommend that you don't use it, but you can look at it to see how it works. (Good luck with my paint program ....)

    My dsfont "library" (dwk's simple font...) includes two fonts. I copied them from the standard Windows 98 DOS command prompt, so I have no idea of the copyright issues behind this. No doubt they're substantial. I recommend you create your own font if you're going to do something like this.

    You can see dsfont in action in Sail the Seas. http://dwks.theprogrammingsite.com/myprogs/sailseas.htm

    Also consider looking at the SDL library sfont. I've heard it's pretty good. They have some nice fonts, at least.

    denora-fonts contains some fonts I generated with the GIMP from GNU GPL fonts. You can probably use these if you like. I'm not sure about their copyright -- I've heard there are issues with fonts -- but I can't see this copyright restricting your use of it. Modifications, maybe.

    paint2 is completely keyboard-driven. The commands that I remember go something like this:
    • ESC: quit
    • m: switch between mouse and keyboard mode
    • arrow keys [in keyboard mode]: move cursor
    • mouse [in mouse mode]: move cursor
    • l: toggle line drawing
    • ;: actually save a line
    • c: clear screen

    It has saving and opening and circles and boxes etc, but you'll have to examine the source for the keys you press to get them.

    One thing: the DOS source code I have here is very, very old. I opened alpha.c out of curiosity and saw this:
    Code:
    for(i = 0; i < strlen(s); i ++) {
    *shudders*

    I'd forgotten that the font only supports uppercase, but there you have it. Lowercase looks really weird in a 5x3 font.

    These days I use truetype fonts with the SDL (SDL_ttf). I highly recommend the SDL, you should try it. It's a bit disconcerting for a DOS programmer at first, but you get used to it. And it's a lot better once you do.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  7. #7
    Registered User
    Join Date
    Nov 2007
    Posts
    9

    Thanks Again

    DWKS Thanks. I've gotten the files and am going to the Sail Seas web page. I really appreciate this. I'll let you know how it goes.

    Thanks again
    Ace

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Using fonts in C++
    By maxorator in forum Windows Programming
    Replies: 3
    Last Post: 09-25-2005, 02:16 PM
  2. Windows 'Hardwired Fonts'?
    By Davros in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 09-02-2004, 09:38 AM
  3. Scrolling text with variable pitch fonts
    By Raison in forum Windows Programming
    Replies: 0
    Last Post: 06-02-2004, 08:20 AM
  4. GNOME fonts
    By bludstayne in forum Tech Board
    Replies: 3
    Last Post: 01-20-2004, 09:49 PM
  5. DJGPP Allegro, using grabber and fonts
    By doubleanti in forum C++ Programming
    Replies: 0
    Last Post: 08-29-2001, 01:02 PM