Subversion Repositories Kolibri OS

Rev

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