Subversion Repositories Kolibri OS

Rev

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

  1. #ifndef INCLUDE_FONT_H
  2. #define INCLUDE_FONT_H
  3.  
  4. #ifndef INCLUDE_MATH_H
  5. #include "../lib/math.h"
  6. #endif
  7.  
  8. #ifndef INCLUDE_IO_H
  9. #include "../lib/io.h"
  10. #endif
  11.  
  12. :struct __SIZE
  13. {
  14.         word width,height;
  15.         signed offset_x,offset_y;
  16.         byte text;
  17. };
  18. :struct FONT
  19. {
  20.         __SIZE size;
  21.         byte width,height,offsetLine,r,g,b,weight;
  22.         dword color;
  23.         dword file_size;
  24.         dword buffer;
  25.         dword buffer_size;
  26.         word block;
  27.         dword data;
  28.         dword begin;
  29.         dword size_file;
  30.         byte load(...);
  31.         byte symbol(word x;byte s;dword c);
  32.         byte symbol_size(byte s);
  33.         dword text(word x,y;dword text1,c);
  34.         dword getsize(dword text1);
  35.         dword textarea(word x,y;dword text,c);
  36.         byte changeSIZE();
  37.         void PixelRGB(word x,y);
  38.         dword tmp_y,tmp_height,tmp_x;
  39.         byte no_bg_copy;
  40.         dword bg_color;
  41. };
  42. FONT font = 0;
  43.  
  44. :void FONT::PixelRGB(dword x,y)
  45. {
  46.         dword tmp;
  47.         tmp = y*size.width*3;
  48.         tmp += x*3;
  49.         tmp += buffer;
  50.  
  51.         DSBYTE[tmp] = r;
  52.         tmp++;
  53.         DSBYTE[tmp] = g;
  54.         tmp++;
  55.         DSBYTE[tmp] = b;
  56. }
  57. :byte FONT::changeSIZE()
  58. {
  59.         dword TMP_DATA;
  60.         dword ofs;
  61.         byte s;
  62.         IF(size.text<9) size.text = 8;
  63.         IF(size.text>45)size.text = 45;
  64.                 s = size.text-8;
  65.                 data = begin;
  66.                 TMP_DATA = data;
  67.                 TMP_DATA +=s*4;
  68.                 ofs = DSDWORD[TMP_DATA];
  69.                 IF(ofs==-1)return false;
  70.                 data += ofs;
  71.                 data += 156;
  72.                 TMP_DATA = data;
  73.                 file_size = DSDWORD[TMP_DATA];
  74.                 TMP_DATA += file_size;
  75.                 TMP_DATA--;
  76.                 height = DSBYTE[TMP_DATA];
  77.                 TMP_DATA--;
  78.                 width =  DSBYTE[TMP_DATA];
  79.                 block = math.ceil(height*width/32);
  80.                 return true;
  81. }
  82. :proc_info Form_SELF_FONTS;
  83.  
  84. :dword FONT::getsize(dword text1)
  85. {
  86.         size.height = size.width = 0;
  87.         size.offset_x = size.offset_y = -1;
  88.         IF(size.text)IF(!changeSIZE())return 0;
  89.         WHILE(DSBYTE[text1])
  90.         {
  91.                 symbol_size(DSBYTE[text1]);
  92.                 text1++;
  93.         }
  94.         $neg size.offset_y
  95.         $neg size.offset_x
  96.         size.height++;
  97.         size.height += size.offset_y;
  98.         size.width += size.offset_x;
  99.         size.width++;
  100.         return size.width;
  101. }
  102. :byte FONT::symbol_size(byte s)
  103. {
  104.         dword xi,yi;
  105.         dword tmp,_;
  106.         dword iii;
  107.         byte rw=0;
  108.                 byte X;
  109.         IF(s==32)
  110.                 {
  111.                         size.width += width/4;
  112.                         IF(weight) size.width++;
  113.                         return;
  114.                 }
  115.                 IF(s==9)
  116.                 {
  117.                         size.width += width;
  118.                         IF(weight) size.width++;
  119.                         return;
  120.                 }
  121.         yi = 0;
  122.         iii = 0;
  123.         tmp = 4*block*s;
  124.         tmp +=data;
  125.         while(yi<height)
  126.         {
  127.                 xi = 0;
  128.                 WHILE(xi<width)
  129.                 {
  130.                         IF(iii%32) _ >>= 1;
  131.                                                 ELSE
  132.                                                 {
  133.                                 tmp += 4;
  134.                                 _ = DSDWORD[tmp];
  135.                         }
  136.                         IF(_&1)
  137.                                                 {
  138.                                                         IF(xi>rw)rw=xi;
  139.                                                         IF(size.height<yi)size.height = yi;
  140.                                                         IF(size.offset_y<0)size.offset_y = yi;
  141.                                                         ELSE IF(yi<size.offset_y)size.offset_y = yi;
  142.                                                         IF(!X) X = xi;
  143.                                                         ELSE IF(X>xi)X = xi;
  144.                                                 }
  145.                         xi++;
  146.                         iii++;
  147.                 }
  148.                 yi++;
  149.         }
  150.                 size.width += rw;
  151.                 IF(weight) size.width++;
  152.                 IF(s=='_') size.width--;
  153.                 IF(size.offset_x<0)size.offset_x = X;
  154. }
  155. :dword FONT::text(word x,y;dword text1)
  156. {
  157.         signed len=0;
  158.         dword c;
  159.         word _tmp_h;
  160.         c = color;
  161.         IF(size.text)IF(!changeSIZE())return 0;
  162.         GetProcessInfo(#Form_SELF_FONTS, SelfInfo);
  163.         IF(y>Form_SELF_FONTS.cheight) return 0;
  164.         IF(x>Form_SELF_FONTS.cwidth) return 0;
  165.         tmp_y = y;
  166.         AX = c;
  167.         r = AL;
  168.         g = AH;
  169.         c>>=16;
  170.         AX = c;
  171.         b = AL;
  172.         getsize(text1);
  173.         IF(!buffer_size)
  174.         {
  175.                 buffer_size = size.width*size.height*3;
  176.                 buffer = malloc(buffer_size);
  177.         }
  178.         ELSE IF(buffer_size<size.width*size.height*3)
  179.         {
  180.                 buffer_size = size.width*size.height*3;
  181.                 buffer = realloc(buffer,buffer_size);
  182.         }
  183.         IF (no_bg_copy)
  184.         {
  185.                 EBX = bg_color;
  186.                 EAX = buffer_size+buffer;
  187.                 EDI = buffer;
  188.                 WHILE (EDI<EAX)
  189.                 {
  190.                         ESDWORD[EDI] = EBX;
  191.                         $add edi,3
  192.                 }
  193.         }
  194.         ELSE CopyScreen(buffer,x+Form_SELF_FONTS.left+5,y+Form_SELF_FONTS.top+GetSkinHeight(),size.width,size.height);
  195.  
  196.         WHILE(DSBYTE[text1])
  197.         {
  198.                 IF(DSBYTE[text1]=='_') len--;
  199.                 len+=symbol(len,DSBYTE[text1],c);
  200.                 IF(weight)len++;
  201.                 text1++;
  202.         }
  203.         _PutImage(x,y-size.offset_y,size.width,size.height,buffer);
  204.         return len;
  205. }
  206. :dword FONT::textarea(word x,y;dword text1,c;byte size)
  207. {
  208.        
  209. }
  210.  
  211. :byte FONT::symbol(signed x;byte s;dword c)
  212. {
  213.         dword xi,yi;
  214.         dword tmp,_;
  215.         dword iii;
  216.                 dword ___x;
  217.         byte rw=0;
  218.                 x += size.offset_x;
  219.         IF(s==32)return width/4;
  220.                 IF(s==9)return width;
  221.         yi = 0;
  222.         iii = 0;
  223.         tmp = 4*block*s;
  224.         tmp +=data;
  225.         while(yi<height)
  226.         {
  227.                 xi = 0;
  228.                 while(xi<width)
  229.                 {
  230.                         IF(iii%32) _ >>= 1;
  231.                                                 ELSE
  232.                                                 {
  233.                                 tmp += 4;
  234.                                 _ = DSDWORD[tmp];
  235.                         }
  236.                         IF(_&1)
  237.                         {
  238.                                 IF(xi>rw)rw=xi;
  239.                                                                 ___x = x+xi;
  240.                                                                 IF(___x<Form_SELF_FONTS.cwidth)&&(tmp_y+yi<Form_SELF_FONTS.cheight)
  241.                                                                 {
  242.                                                                         PixelRGB(___x,size.offset_y+yi);
  243.                                                                         IF(weight) PixelRGB(___x+1,size.offset_y+yi);
  244.                                                                 }
  245.                         }
  246.                         xi++;
  247.                         iii++;
  248.                 }
  249.                 yi++;
  250.         }
  251.         return rw;
  252. }
  253. :byte FONT::load(dword path)
  254. {
  255.         dword tmp;
  256.         buffer_size = 0;
  257.         IF(data)free(data);
  258.         if (!io.readKPACK(path))
  259.         {
  260.                 debug("Error while loading font: ");
  261.                 debugln(path);
  262.                 return 0;
  263.         }
  264.         tmp = io.buffer_data;
  265.         data = tmp;
  266.         begin = data;
  267.         size_file = io.FILES_SIZE;
  268.         tmp +=size_file;
  269.         tmp--;
  270.         height = DSBYTE[tmp];
  271.         tmp--;
  272.         width = DSBYTE[tmp];
  273.         block = math.ceil(height*width/32);
  274. }
  275.  
  276. #endif