Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. ; $$$$$$$$$$$$$$$$$$$ ABAKIS $$$$$$$$$$$$$$$$$$$$$
  2. ; *************** STAR^2 SOFTWARE ****************
  3. ; ?????????????????? FONT.INC ????????????????????
  4.  
  5. ; 100% portable font
  6.  
  7. ;;;;;;;;;;;;;;;;;;;; SYMBOLS ;;;;;;;;;;;;;;;;;;;;;
  8.  
  9. ; my default character arrangement: 95 symbols.
  10. ; includes all standard visible characters
  11.  
  12. ; 0 1 2 3 4 5 6 7 8 9 A B C D E F G H I
  13. ; J K L M N O P Q R S T U V W X Y Z a b
  14. ; c d e f g h i j k l m n o p q r s t u
  15. ; v w x y z _   . ? ; : ' " , ~ ! @ # $
  16. ; % ^ & * ( ) [ ] { } = + - < > / \ | `
  17.  
  18. ; symbol lookup table to convert 7BIT ASCII
  19. ; character to index. 63=ignore (spaces, etc)
  20.  
  21. align 4
  22.  
  23. FONT.SYMBOLS: db \
  24. 63,63,63,63,63,63,63,63, 63,63,63,63,63,63,63,63,\
  25. 63,63,63,63,63,63,63,63, 63,63,63,63,63,63,63,63,\
  26. 63,72,69,74,75,76,78,68, 80,81,79,87,70,88,64,91,\
  27. 00,01,02,03,04,05,06,07, 08,09,67,66,89,86,90,65,\
  28. 73,10,11,12,13,14,15,16, 17,18,19,20,21,22,23,24,\
  29. 25,26,27,28,29,30,31,32, 33,34,35,82,92,83,77,62,\
  30. 94,36,37,38,39,40,41,42, 43,44,45,46,47,48,49,50,\
  31. 51,52,53,54,55,56,57,58, 59,60,61,84,93,85,71,63
  32. NO.C=63
  33.  
  34. macro FONT [p] { common IMAGE p }
  35.  
  36. align
  37.  
  38. void font.image.p
  39. integer font.image.w, font.w, font.h
  40. integer font.color=WHITE
  41.  
  42. macro set.font i {
  43.   . font.image.p=i#.p, r0=i#.w
  44.   . font.image.w=r0, r1=95, r0/r1
  45.   . font.w=r0, font.h=i#.h
  46. }
  47.  
  48. ;;;;;;;;;;;;;;;;; DRAW CHARACTER ;;;;;;;;;;;;;;;;;
  49.  
  50. function draw.c, c, x, y
  51.   locals i, p, iw
  52.   try visible x, y, font.w, font.h
  53.   . r0=FONT.SYMBOLS, r0+c, r0=*r0
  54.   if r0=NO.C, return, end
  55.   . r0*font.w, r0*4, r0+font.image.p
  56.   . p=r0, iw=font.image.w, iw*4, i=font.h
  57.   loop i, r0=i
  58.     if r0>=font.h, break, end
  59.     draw.scanline p, x, y, font.w
  60.     . r1=iw, p+r1, y++
  61.   endl
  62. endf
  63.  
  64. ;;;;;;;;;;;;;;;;;;; DRAW TEXT ;;;;;;;;;;;;;;;;;;;;
  65.  
  66. align
  67. integer clip.tx=-1, clip.ty=-1
  68.  
  69. function draw.text, t, x, y
  70.   locals i, n, p
  71.   . r0=t, p=r0, i=0
  72.   while true              ; draw all characters
  73.     . r1=i, r1*font.w     ; x=i*font.w+x
  74.     . r1+x, r0=p, r0=*r0  ; get c
  75.     if r0=0Dh             ; return?
  76.       . i=0, r1=font.h    ; reset x
  77.       . y+r1, p++         ; y+font.h
  78.       go .next
  79.     end
  80.     . r2=y, r2-font.h     ; clipping
  81.     if r2>screen.h
  82.       return
  83.     end
  84.     . r2=clip.tx
  85.     if r2<>-1, r2-font.w
  86.       if r1>=r2, return, end
  87.     end
  88.     . r2=clip.ty
  89.     if r2<>-1, r2-font.h
  90.       if r1>=r2, return, end
  91.     end
  92.     draw.c r0, r1, y      ; draw
  93.     . i++
  94.     .next:
  95.     . p++, r0=p, r0=*r0
  96.   endw
  97. endf
  98.  
  99. ; get width of text=a1 with insets
  100.  
  101. function get.text.w, t
  102.   text.n t
  103.   . r1=r0, r1+2, r0=font.w, r0*r1
  104. endf