Subversion Repositories Kolibri OS

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
5548 leency 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
 
5626 leency 41
	load_dll(libtruetype, #truetype, 1);
42
	load_dll(Proc_lib, #OpenDialog_init,0);
5548 leency 43
	OpenDialog_init stdcall (#o_dialog);
44
 
45
	if (param[0]) OpenFont(#param);
46
 
47
	loop()
48
   {
49
      switch(WaitEvent())
50
      {
51
         case evButton:
52
            id=GetButtonID();
53
            if (id==1) ExitProcess();
54
            if (id==10)
55
            {
56
            	OpenDialog_start stdcall (#o_dialog);
57
				OpenFont(#openfile_path);
58
            }
59
			break;
60
 
61
        case evKey:
62
			key = GetKey();
63
			break;
64
 
65
         case evReDraw:
66
			draw_window();
67
      }
68
   }
69
}
70
 
71
 
72
void draw_window()
73
{
74
	sc.get();
75
	DefineAndDrawWindow(30, 100, 800, 250+GetSkinHeight(), 0x34, 0xFFFfff, #win_title);
76
	GetProcessInfo(#Form, SelfInfo);
77
	DrawFonts();
78
}
79
 
80
 
81
word DrawFonts()
82
{
83
	if (!font_data)
84
	{
85
		WriteTextCenter(0,85,Form.cwidth,0x555555, T_INTRO);
86
		DrawCaptButton(Form.cwidth - 140 / 2, Form.cheight - 30 / 2, 140, 30, 10, sc.work_button, sc.work_button_text, T_INTRO_BUTTON_TEXT);
87
		return;
88
	}
89
	text_out stdcall (#test_text, #font_info, 10, 0x000000, 0xFFFfff, 3, 4);
90
	text_out stdcall (#test_text, #font_info, 12, 0x000000, 0xFFFfff, 3, 18);
91
	text_out stdcall (#test_text, #font_info, 24, 0x000000, 0xFFFfff, 3, 35);
92
	text_out stdcall (#test_text, #font_info, 36, 0x000000, 0xFFFfff, 3, 60);
93
	text_out stdcall (#test_text, #font_info, 48, 0x000000, 0xFFFfff, 3, 110);
94
	text_out stdcall (#test_text, #font_info, 58, 0x000000, 0xFFFfff, 3, 170);
95
}
96
 
97
 
98
void OpenFont(dword font_path)
99
{
100
	BDVK FontFile_atr;
101
	GetFileInfo(font_path, #FontFile_atr);
102
	font_data = malloc(FontFile_atr.sizelo);
103
	ReadFile(0, FontFile_atr.sizelo, #font_data, font_path);
104
	init_font stdcall (#font_info, #font_data);
105
	if (EAX==0)
106
	{
107
		font_data = 0;
108
		notify("'Can\096t open font: init_font failed' - E");
109
	}
110
	strcpy(#win_title + 18, font_path);
111
	draw_window();
112
}
113
 
114
stop: