Subversion Repositories Kolibri OS

Rev

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

  1. #ifndef AUTOBUILD
  2. #include "lang.h--"
  3. #endif
  4.  
  5. #define MEMSIZE 397113
  6. #include "..\lib\strings.h"
  7. #include "..\lib\mem.h"
  8. #include "..\lib\file_system.h"
  9. #include "..\lib\gui.h"
  10. #include "..\lib\obj\truetype.h"
  11. #include "..\lib\obj\proc_lib.h"
  12. #include "..\lib\patterns\simple_open_dialog.h"
  13.  
  14. char default_dir[] = "/rd/1";
  15. od_filter filter2 = {"TTF",0};
  16.  
  17. dword font_data;
  18. stbtt_fontinfo font_info;
  19. dword font_mem;
  20.  
  21. proc_info Form;
  22. char test_text[] = "The quick brown fox jumps over the lazy dog";
  23. char win_title[4096] = "TTF Viewer v0.1 - ";
  24.  
  25. #ifdef LANG_RUS
  26.         ?define T_INTRO "â® ¯à®áâ ï ¯à®£à ¬¬  ¤«ï ¯à®á¬®âà  èà¨ä⮢ ä®à¬ â  TTF"
  27.         ?define T_INTRO_BUTTON_TEXT "Žâªàëâì èà¨äâ"
  28. #else
  29.         ?define T_INTRO "This is simple program to view TTF fonts."
  30.         ?define T_INTRO_BUTTON_TEXT "Open font"
  31. #endif
  32.  
  33.  
  34. void main()
  35. {
  36.         int id, key;
  37.  
  38.         load_dll(libtruetype, #truetype, 1);
  39.         load_dll(Proc_lib, #OpenDialog_init,0);
  40.         OpenDialog_init stdcall (#o_dialog);
  41.  
  42.         if (param[0]) OpenFont(#param);
  43.  
  44.         loop()
  45.    {
  46.       switch(WaitEvent())
  47.       {
  48.          case evButton:
  49.             id=GetButtonID();              
  50.             if (id==1) ExitProcess();
  51.                         if (id==10)
  52.                         {
  53.                         OpenDialog_start stdcall (#o_dialog);
  54.                         OpenFont(#openfile_path);
  55.                         }
  56.                         break;
  57.      
  58.         case evKey:
  59.                         key = GetKey();
  60.                         break;
  61.          
  62.          case evReDraw:
  63.                         draw_window();
  64.       }
  65.    }
  66. }
  67.  
  68.  
  69. void draw_window()
  70. {
  71.         system.color.get();
  72.         DefineAndDrawWindow(30, 100, 800, 250+GetSkinHeight(), 0x34, 0xFFFfff, #win_title);
  73.         GetProcessInfo(#Form, SelfInfo);
  74.         DrawFonts();   
  75. }
  76.  
  77.  
  78. word DrawFonts()
  79. {
  80.         if (!font_data)
  81.         {
  82.                 WriteTextCenter(0,85,Form.cwidth,0x555555, T_INTRO);
  83.                 DrawCaptButton(Form.cwidth - 140 / 2, Form.cheight - 30 / 2, 140, 30, 10, system.color.work_button, system.color.work_button_text, T_INTRO_BUTTON_TEXT);
  84.                 return;
  85.         }
  86.         text_out stdcall (#test_text, #font_info, 10, 0x000000, 0xFFFfff, 3, 4);
  87.         text_out stdcall (#test_text, #font_info, 12, 0x000000, 0xFFFfff, 3, 18);
  88.         text_out stdcall (#test_text, #font_info, 24, 0x000000, 0xFFFfff, 3, 35);
  89.         text_out stdcall (#test_text, #font_info, 36, 0x000000, 0xFFFfff, 3, 60);
  90.         text_out stdcall (#test_text, #font_info, 48, 0x000000, 0xFFFfff, 3, 110);
  91.         text_out stdcall (#test_text, #font_info, 58, 0x000000, 0xFFFfff, 3, 170);
  92. }
  93.  
  94.  
  95. void OpenFont(dword font_path)
  96. {
  97.         BDVK FontFile_atr;
  98.         GetFileInfo(font_path, #FontFile_atr);
  99.         font_data = malloc(FontFile_atr.sizelo);
  100.         ReadFile(0, FontFile_atr.sizelo, #font_data, font_path);
  101.         init_font stdcall (#font_info, #font_data);
  102.         if (EAX==0)
  103.         {
  104.                 font_data = 0;
  105.                 notify("'Can\096t open font: init_font failed' - E");
  106.         }
  107.         strcpy(#win_title + 18, font_path);
  108.         draw_window();
  109. }
  110.  
  111. stop:
  112.