Subversion Repositories Kolibri OS

Rev

Rev 5674 | Go to most recent revision | Details | Compare with Previous | 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\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"
5778 leency 12
#include "..\lib\patterns\simple_open_dialog.h"
5548 leency 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
 
5626 leency 38
	load_dll(libtruetype, #truetype, 1);
39
	load_dll(Proc_lib, #OpenDialog_init,0);
5548 leency 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();
5778 leency 51
			if (id==10)
52
			{
53
			OpenDialog_start stdcall (#o_dialog);
54
			OpenFont(#openfile_path);
55
			}
5548 leency 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
{
5674 pavelyakov 71
	system.color.get();
5548 leency 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);
5674 pavelyakov 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);
5548 leency 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: