Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1.  BGIFONT.INC v1.0 beta
  2.  
  3.  Written in pure assembler by Ivushkin Andrey aka Willow
  4.  
  5.   At present Menuet operation system has poor means to draw charaters. Its
  6. distro contains 2 raster fonts (CHAR.MT & CHAR2.MT files). The kernel supports
  7. them internally. That is Jarek Pelczar who makes certain efforts to develop
  8. scalable TTF-like fonts but huge Menuet C Library does not become widespread
  9. inside our assembly-written OS. Bulgarian MenuetOS team also tries to include
  10. third scalable font into the kernel, though, as far as I know, its characters
  11. are still under design and are incomplete. Therefore Bulgarian developing is
  12. not valuable for ordinary users. It is obvious that scalable fonts will help
  13. to develop such products as browsers and word processors where character
  14. formatting is of great importance.
  15.   Let me introduce for public domain an include file BGIFONT.INC to process
  16. vector fonts (*.CHR) worked out by famous Borland Corporation to use in Turbo
  17. Pascal, Turbo C and Borland C++ compilers under MS-DOS. Sorry, I still fail to
  18. add BGI font support into kernel - deeper knowledge on memory allocation and
  19. system calls needed. I hope that Menuet system programmers will be glad to help
  20. me. Module compiling within kernel is supposed using constant BGI_LEVEL equ
  21. KERNEL. By means of conditional compiling it will be possible to use the module
  22. at both kernel and application levels. Following is concerned using the include
  23. file while programming an application.
  24.  
  25.   BGI fonts may reside in any folder on HD or RD. They are searched using value
  26. of constant BGI_PATH. If constant BGI_WINDOW_CLIP is equal to 1, module routines
  27. perform window bounds check to avoid artifacts while drawing. Use this if you
  28. aren't sure that strings are fit in window. All BGIFONT.INC routines are
  29. declared as macros, that is they are used without "call". To load 11 fonts into
  30. application's memory a contiguous free space up to 120 kb is needed. When
  31. loading, font data relocation is performed to save memory. Let us see a chart:
  32.  
  33. |  Font   |  |  BGIrec  |  | Font |   |  BGIrec  |  | Font |  |  BGIrec  |
  34. | counter |  | structure|  | data |   | structure|  | data |  | structure|   ...
  35. | (1 byte)|          |                  |    |                  |    |
  36.      |               ------------->------    -------------->-----    ----------
  37.      - referenced by [BGIfont_Ptr]
  38.  
  39.   BGIrec structure fields have following meaning:
  40.  
  41.  +00 dword .FontName     font name (4 characters)
  42.  +04 byte  .CharsCount   amount of font characters
  43.  +05 byte  .FirstChar    code of the first character present
  44.  +06 byte  .UpperMargin  high bound of characters
  45.  +07 byte  .LowerMargin  low bound of characters
  46.  +08 dword .Widths       offset to width array
  47.  +12 dword .FirstData    offset to vector table
  48.  +16 dword .EOF          pointer to the following BGIrec
  49.  +20 dword .font_data    here font data begin
  50.  
  51.   Font loading and verification are carried out by BGIfont_Prepare procedure.
  52.  
  53.   BGIfont_Prepare
  54.      in:  EDX - font name (4 characters) to be loaded. It must to be the same as
  55.             the font filename (without extension)
  56.           EDI - address to where font have to be loaded. Used only for the
  57.             first time. Then you may find this value in [BGIfont_Ptr]
  58.      out: EAX=0, if an error occured, otherwise EAX is identifier (ID) of the
  59.             loaded font. Later it is possible to get font ID with BGIfont_GetID
  60.             function.
  61.  
  62.   For the simultaneous loading of few fonts you may use BGIfont_Init routine.
  63.  
  64.   BGIfont_Init
  65.      in:  ESI - pointer to array of font names (for example db 'TRIPSIMPEURO')
  66.           ECX is amount of fonts to load
  67.           EDI - see BGIfont_Prepare
  68.      out: nothing.
  69.  
  70.   To load 10 standard fonts the module defines an array BGIfont_names (see in
  71. BGITEST for usage demonstration).
  72.  
  73.   For compatibility and subsequent kernel introduction, the module offers 2
  74. routines for drawing vector characters. One of them uses registers (like sysfunc
  75. 4), another uses a structure.
  76.  
  77.   BGIfont_Outtext
  78.      in:  EAX - "pivot point" of a string [x] shl 16+[y]
  79.           ECX - text color and font size 0xXYRRGGBB,
  80.               where X - vector font ID(4..F),
  81.                     Y - size of caracters divided by 4, e.g. 0x1 - 1/4 of
  82.                       ordinary size, 0xC - triple size.
  83.             EDX - pointer to the string
  84.             ESI - string length + formatting flags (see below). BGI_ITALIC and
  85.               BGI_NODRAW flags are ignored.
  86.      out: EAX - coords at the end of the string drawn [x] shl 16+[y].
  87.  
  88.   As you can see, BGIfont_Outtext is similar to the 4th system function,
  89. but provides an extended management of drawing symbols.
  90.  
  91.   The most complete use of vector fonts is provided by BGIfont_Freetext routine.
  92. Parameters are passed in a BGIfree structure.
  93.  
  94.   BGIfree structure fields have following meaning:
  95.  
  96.  +00 dword   font name (4 characters)
  97.  +04 dword   "pivot point" of a string [x] shl 16+[y]
  98.  +08 dword   turn angle (clockwise, 0 is horizontal)
  99.  +12 dword   X scale (floating point value!)
  100.  +16 dword   Y scale (floating point value!)
  101.  +20 dword   pointer to the string
  102.  +24 dword   string length WITHOUT formatting flags
  103.  +28 dword   text color 0x00RRGGBB
  104.  +32 dword   formatting flags
  105.  
  106.   The module defines following formatting flags:
  107. BGI_NODRAW     - do not draw
  108. BGI_ITALIC     - italic
  109. BGI_BOLD       - bold
  110. BGI_HALEFT     - left alignment
  111. BGI_HARIGHT    - right alignment
  112. BGI_HACENTER   - center alignment
  113. BGI_VABOTTOM   - bottom alignment
  114. BGI_VATOP      - top alignment
  115. BGI_VACENTER   - middle vertical alignment
  116.  
  117.   Combination of flags can be performed by addition or the OR operation.
  118.  
  119.   BGIfont_Freetext
  120.      in:  EBX - pointer to BGIfree structure
  121.      out: EAX coords at the end of the string drawn [x] shl 16+[y].
  122.  
  123.   BGIfont_GetID routine returns font ID by its name.
  124.  
  125.   BGIfont_GetID
  126.      in:  EDX - font name (4 characters)
  127.      out: EAX - ID of the font
  128.           EDI - pointer on font's BGIrec structure.
  129.  
  130.   Using functions of BGIFONT.INC module is demonstrated by BGITEST app.
  131.  
  132.   Todo list:
  133. 1. An insidious bug sometimes shows up while loading multiple fonts (as in
  134.    BGITEST), that corrupts some characters. It disappears when font loading
  135.    order is changed... :-(
  136. 2. To correct a hardly reproduceable bug when moving along the font list.
  137. 3. To perfect drawing of bold fonts.
  138. 4. To add number drawing routines.
  139.  
  140.  
  141.