uMain.pas 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462
  1. unit uMain;
  2. // RU: обратите внимание!!!
  3. // Проекты LCL имеют свои конфигурационные файлы "zgl_config.cfg". Лучше всего для каждого вашего проекта иметь свой
  4. // конфигурационный файл, это может решить многие проблемы, если вдруг вы будете вносить изменения в конфигурацию проекта
  5. // и, это отобразится на других ваших проектах использующих тот же конфигурационный файл.
  6. // EN: note!!!
  7. // LCL projects have their own configuration files "zgl_config.cfg". It's best to have a separate config file for each of
  8. // your projects, this can solve many problems if you suddenly make changes to the project config and it will show up on
  9. // your other projects using the same config file.
  10. interface
  11. uses
  12. Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
  13. ExtCtrls, ComCtrls, Spin,
  14. {$IFDEF LINUX}
  15. {$IFDEF LCLGTK}
  16. GLib, GTK, GDK,
  17. {$ENDIF}
  18. {$IFDEF LCLGTK2}
  19. GLib2, GTK2, GDK2, GDK2x,
  20. {$ENDIF}
  21. {$ENDIF}
  22. zgl_screen,
  23. zgl_window,
  24. zgl_utils,
  25. zgl_primitives_2d,
  26. zgl_sprite_2d,
  27. zgl_application,
  28. zgl_font,
  29. zgl_text,
  30. zgl_file,
  31. zgl_types,
  32. gegl_color,
  33. zgl_font_gen;
  34. type
  35. { TForm1 }
  36. TForm1 = class(TForm)
  37. ButtonRebuildFont: TButton;
  38. ButtonImportSymbols: TButton;
  39. ButtonDefaultSymbols: TButton;
  40. ButtonExit: TButton;
  41. ButtonSaveFont: TButton;
  42. ButtonChooseFont: TButton;
  43. CheckBoxAntialiasing: TCheckBox;
  44. CheckBoxPack: TCheckBox;
  45. ComboBoxPageSize: TComboBox;
  46. EditChars: TEdit;
  47. EditTest: TEdit;
  48. FontDialog: TFontDialog;
  49. GroupBox1: TGroupBox;
  50. GroupBox2: TGroupBox;
  51. GroupBox3: TGroupBox;
  52. GroupBox4: TGroupBox;
  53. Label1: TLabel;
  54. Label2: TLabel;
  55. Label3: TLabel;
  56. Label4: TLabel;
  57. LabelPageSize: TLabel;
  58. LabelCurrentPage: TLabel;
  59. OpenDialog: TOpenDialog;
  60. Panel1: TPanel;
  61. SaveFontDialog: TSaveDialog;
  62. SpinCurrentPage: TSpinEdit;
  63. SpinTop: TSpinEdit;
  64. SpinLeft: TSpinEdit;
  65. SpinRight: TSpinEdit;
  66. SpinBottom: TSpinEdit;
  67. Timer1: TTimer;
  68. procedure ButtonChooseFontClick(Sender: TObject);
  69. procedure ButtonDefaultSymbolsClick(Sender: TObject);
  70. procedure ButtonExitClick(Sender: TObject);
  71. procedure ButtonImportSymbolsClick(Sender: TObject);
  72. procedure ButtonRebuildFontClick(Sender: TObject);
  73. procedure ButtonSaveFontClick(Sender: TObject);
  74. procedure CheckBoxAntialiasingChange(Sender: TObject);
  75. procedure CheckBoxPackChange(Sender: TObject);
  76. procedure ComboBoxPageSizeChange(Sender: TObject);
  77. procedure FormActivate(Sender: TObject);
  78. procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
  79. procedure FormResize(Sender: TObject);
  80. procedure Panel1MouseDown(Sender: TObject; Button: TMouseButton;
  81. Shift: TShiftState; X, Y: Integer);
  82. procedure Panel1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer
  83. );
  84. procedure Panel1MouseUp(Sender: TObject; Button: TMouseButton;
  85. Shift: TShiftState; X, Y: Integer);
  86. procedure SpinCurrentPageChange(Sender: TObject);
  87. procedure SpinLeftChange(Sender: TObject);
  88. procedure SpinTopChange(Sender: TObject);
  89. procedure SpinBottomChange(Sender: TObject);
  90. procedure SpinRightChange(Sender: TObject);
  91. procedure Timer1Timer(Sender: TObject);
  92. private
  93. { private declarations }
  94. public
  95. { public declarations }
  96. procedure SetDefaultSymbolList;
  97. procedure UpdateSymbolList;
  98. procedure UpdateFont;
  99. end;
  100. var
  101. Form1 : TForm1;
  102. zgl_Inited : Boolean = False;
  103. fontMoving : Boolean;
  104. fontX, fontY : Integer;
  105. lastX, lastY : Integer;
  106. utf8chars : array[ 0..65535, 0..5 ] of AnsiChar;
  107. newColor : LongWord;
  108. implementation
  109. {$R *.lfm}
  110. procedure Init;
  111. begin
  112. wnd_SetSize( Form1.Panel1.ClientWidth, Form1.Panel1.ClientHeight );
  113. scrVSync := True;
  114. fontgen_Init();
  115. fg_Font := font_Add();
  116. Form1.SetDefaultSymbolList();
  117. Form1.UpdateFont();
  118. fontX := ( Form1.Panel1.Width - fg_PageSize ) div 2;
  119. fontY := ( Form1.Panel1.Height - fg_PageSize ) div 2;
  120. newColor := Color_FindOrAdd($505050FF);
  121. setTextColor(Get_Color(cl_Yellow));
  122. end;
  123. procedure Draw;
  124. var
  125. r: zglTRect2D;
  126. begin
  127. pr2d_Rect( 0, 0, Form1.Panel1.Width, Form1.Panel1.Height, newColor, PR2D_FILL );
  128. pr2d_Rect( fontX, fontY, fg_PageSize, fg_PageSize, cl_Black, PR2D_FILL );
  129. if ( fg_Font <> 0) and Assigned(managerFont.Font[fg_Font].Pages) Then
  130. begin
  131. ssprite2d_Draw( managerFont.Font[fg_Font].Pages[ Form1.SpinCurrentPage.Value - 1 ], fontX, fontY, fg_PageSize, fg_PageSize, 0 );
  132. r.W := text_GetWidth( fg_Font, Form1.EditTest.Text );
  133. r.X := ( Form1.Panel1.Width - r.W ) / 2;
  134. r.Y := Form1.Panel1.Height - managerFont.Font[fg_Font].MaxShiftY - managerFont.Font[fg_Font].MaxHeight;
  135. r.H := managerFont.Font[fg_Font].MaxShiftY + managerFont.Font[fg_Font].MaxHeight;
  136. pr2d_Rect( r.X, r.Y, r.W, r.H, cl_Black, PR2D_FILL );
  137. text_Draw( fg_Font, Form1.Panel1.Width div 2, Form1.Panel1.Height - managerFont.Font[fg_Font].MaxHeight, Form1.EditTest.Text, TEXT_HALIGN_CENTER );
  138. end;
  139. Application.ProcessMessages();
  140. u_Sleep( 10 );
  141. end;
  142. { TForm1 }
  143. procedure TForm1.SetDefaultSymbolList;
  144. begin
  145. EditChars.Text := ' !"#$%&''()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}' +
  146. '~¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ' +
  147. 'ЁЄІЇАБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯабвгдежзийклмнопрстуфхцчшщъыьэюяёєіїҐґ' + '№';
  148. end;
  149. procedure TForm1.UpdateSymbolList;
  150. var
  151. i, j, len : Integer;
  152. c : Word;
  153. begin
  154. len := length(EditChars.Text);
  155. Panel1.Canvas.Clear();
  156. Application.ProcessMessages();
  157. i := 1;
  158. FillChar(fg_CharsUse, 65536, 0);
  159. managerFont.Font[fg_Font].Count.Chars := 0;
  160. while i <= len do
  161. begin
  162. c := utf8_GetID(EditChars.Text, i, @j);
  163. if not fg_CharsUse[c] Then
  164. begin
  165. fg_CharsUse[c] := TRUE;
  166. FillChar(utf8chars[ c, 0], 6, 0);
  167. Move(EditChars.Text[i], utf8chars[c, 0], j - i);
  168. inc(managerFont.Font[fg_Font].Count.Chars);
  169. end;
  170. i := j;
  171. end;
  172. EditChars.Text := '';
  173. for i := 0 to 65535 do
  174. if fg_CharsUse[ i ] Then
  175. EditChars.Text := EditChars.Text + utf8chars[ i ];
  176. Application.ProcessMessages();
  177. end;
  178. procedure TForm1.UpdateFont;
  179. begin
  180. UpdateSymbolList();
  181. fontgen_BuildFont( fg_Font, FontDialog.Font.Name );
  182. SpinCurrentPage.MaxValue := managerFont.Font[fg_Font].Count.Pages;
  183. if (managerFont.Font[fg_Font].Count.Pages = 0) or (managerFont.Font[fg_Font].Count.Pages = 1) then
  184. begin
  185. SpinCurrentPage.Enabled := False;
  186. SpinCurrentPage.Value := managerFont.Font[fg_Font].Count.Pages;
  187. Exit;
  188. end
  189. else
  190. SpinCurrentPage.Enabled := True;
  191. if SpinCurrentPage.Value > SpinCurrentPage.MaxValue Then
  192. SpinCurrentPage.Value := SpinCurrentPage.MaxValue;
  193. end;
  194. procedure TForm1.ButtonChooseFontClick(Sender: TObject);
  195. begin
  196. Timer1.Enabled := False;
  197. if FontDialog.Execute() Then
  198. begin
  199. fg_FontSize := FontDialog.Font.Size;
  200. fg_FontBold := fsBold in FontDialog.Font.Style;
  201. fg_FontItalic := fsItalic in FontDialog.Font.Style;
  202. UpdateFont();
  203. end;
  204. Timer1.Enabled := true;
  205. end;
  206. procedure TForm1.ButtonDefaultSymbolsClick(Sender: TObject);
  207. begin
  208. Timer1.Enabled := False;
  209. SetDefaultSymbolList();
  210. UpdateFont();
  211. Timer1.Enabled := true;
  212. end;
  213. procedure TForm1.ButtonExitClick(Sender: TObject);
  214. begin
  215. form1.Close;
  216. end;
  217. procedure TForm1.ButtonImportSymbolsClick(Sender: TObject);
  218. var
  219. i : Integer;
  220. s : TStrings;
  221. begin
  222. Timer1.Enabled := False;
  223. s := TStringList.Create;
  224. if OpenDialog.Execute() Then
  225. begin
  226. s.LoadFromFile( OpenDialog.FileName );
  227. for i := 0 to s.Count - 1 do
  228. EditChars.Text := EditChars.Text + s.Strings[ i ];
  229. UpdateFont();
  230. end;
  231. Timer1.Enabled := true;
  232. end;
  233. procedure TForm1.ButtonRebuildFontClick(Sender: TObject);
  234. begin
  235. Timer1.Enabled := False;
  236. UpdateFont();
  237. Timer1.Enabled := True;
  238. end;
  239. procedure TForm1.FormClose(Sender: TObject; var CloseAction: TCloseAction);
  240. begin
  241. Timer1.Enabled := false;
  242. winOn := FALSE;
  243. zgl_Destroy;
  244. Application.Terminate;
  245. end;
  246. procedure TForm1.FormResize(Sender: TObject);
  247. begin
  248. wnd_SetSize( Panel1.ClientWidth, Panel1.ClientHeight );
  249. end;
  250. procedure TForm1.Panel1MouseDown(Sender: TObject; Button: TMouseButton;
  251. Shift: TShiftState; X, Y: Integer);
  252. begin
  253. if not fontMoving Then
  254. begin
  255. fontMoving := TRUE;
  256. lastX := X;
  257. lastY := Y;
  258. end;
  259. end;
  260. procedure TForm1.Panel1MouseMove(Sender: TObject; Shift: TShiftState; X,
  261. Y: Integer);
  262. begin
  263. if fontMoving Then
  264. begin
  265. fontX := fontX + ( X - lastX );
  266. fontY := fontY + ( Y - lastY );
  267. lastX := X;
  268. lastY := Y;
  269. end;
  270. end;
  271. procedure TForm1.Panel1MouseUp(Sender: TObject; Button: TMouseButton;
  272. Shift: TShiftState; X, Y: Integer);
  273. begin
  274. fontMoving := FALSE;
  275. end;
  276. procedure TForm1.SpinCurrentPageChange(Sender: TObject);
  277. begin
  278. if SpinCurrentPage.Value < 1 then
  279. SpinCurrentPage.Value := 1;
  280. end;
  281. procedure TForm1.SpinLeftChange(Sender: TObject);
  282. begin
  283. Timer1.Enabled := False;
  284. if fg_FontPadding[ 0 ] <> SpinLeft.Value Then
  285. begin
  286. fg_FontPadding[ 0 ] := SpinLeft.Value;
  287. UpdateFont();
  288. end;
  289. Timer1.Enabled := true;
  290. end;
  291. procedure TForm1.SpinTopChange(Sender: TObject);
  292. begin
  293. Timer1.Enabled := False;
  294. if fg_FontPadding[ 1 ] <> SpinTop.Value Then
  295. begin
  296. fg_FontPadding[ 1 ] := SpinTop.Value;
  297. UpdateFont();
  298. end;
  299. Timer1.Enabled := true;
  300. end;
  301. procedure TForm1.SpinRightChange(Sender: TObject);
  302. begin
  303. Timer1.Enabled := False;
  304. if fg_FontPadding[ 2 ] <> SpinRight.Value Then
  305. begin
  306. fg_FontPadding[ 2 ] := SpinRight.Value;
  307. UpdateFont();
  308. end;
  309. Timer1.Enabled := True;
  310. end;
  311. procedure TForm1.Timer1Timer(Sender: TObject);
  312. begin
  313. app_PLoop;
  314. end;
  315. procedure TForm1.SpinBottomChange(Sender: TObject);
  316. begin
  317. Timer1.Enabled := False;
  318. if fg_FontPadding[ 3 ] <> SpinBottom.Value Then
  319. begin
  320. fg_FontPadding[ 3 ] := SpinBottom.Value;
  321. UpdateFont();
  322. end;
  323. Timer1.Enabled := true;
  324. end;
  325. procedure TForm1.ButtonSaveFontClick(Sender: TObject);
  326. var
  327. style : String;
  328. _name : String;
  329. dir : String;
  330. begin
  331. if fg_FontBold and fg_FontItalic Then
  332. style := 'BoldItalic'
  333. else
  334. if fg_FontBold Then
  335. style := 'Bold'
  336. else
  337. if fg_FontItalic Then
  338. style := 'Italic'
  339. else
  340. style := 'Regular';
  341. Timer1.Enabled := False;
  342. SaveFontDialog.FileName := FontDialog.Font.Name + '-' + style + '-' + IntToStr( fg_FontSize ) + 'pt';
  343. _name := file_GetName( SaveFontDialog.FileName );
  344. dir := file_GetDirectory( SaveFontDialog.FileName );
  345. fontgen_SaveFont( fg_Font, _name );
  346. ShowMessage(_name + ' save');
  347. Timer1.Enabled := True;
  348. end;
  349. procedure TForm1.CheckBoxAntialiasingChange(Sender: TObject);
  350. begin
  351. Timer1.Enabled := False;
  352. fg_FontAA := CheckBoxAntialiasing.Checked;
  353. UpdateFont();
  354. Timer1.Enabled := true;
  355. end;
  356. procedure TForm1.CheckBoxPackChange(Sender: TObject);
  357. begin
  358. Timer1.Enabled := False;
  359. fg_FontPack := CheckBoxPack.Checked;
  360. UpdateFont();
  361. Timer1.Enabled := true;
  362. end;
  363. procedure TForm1.ComboBoxPageSizeChange(Sender: TObject);
  364. begin
  365. Timer1.Enabled := False;
  366. fg_PageSize := StrToInt( ComboBoxPageSize.Items[ ComboBoxPageSize.ItemIndex ] );
  367. UpdateFont();
  368. Timer1.Enabled := true;
  369. end;
  370. procedure TForm1.FormActivate(Sender: TObject);
  371. {$IFDEF LINUX}
  372. var
  373. widget : PGtkWidget;
  374. socket : PGtkWidget;
  375. glist : PGlist;
  376. {$ENDIF}
  377. begin
  378. if not zgl_Inited then
  379. begin
  380. zgl_Inited := True;
  381. // zgl_Disable( APP_USE_LOG );
  382. zgl_Reg( SYS_LOAD, @Init );
  383. zgl_Reg( SYS_DRAW, @Draw );
  384. {$IFDEF LINUX}
  385. glist := gtk_container_children( GTK_CONTAINER( PGtkWidget( Panel1.Handle ) ) );
  386. widget := PGtkWidget( glist^.data );
  387. socket := gtk_socket_new();
  388. gtk_container_add( GTK_CONTAINER( widget ), socket );
  389. gtk_widget_show( socket );
  390. gtk_widget_show( widget );
  391. gtk_widget_realize( socket );
  392. {$IFDEF LCLGTK}
  393. zgl_InitToHandle( ( PGdkWindowPrivate( widget.window ) ).xwindow );
  394. {$ENDIF}
  395. {$IFDEF LCLGTK2}
  396. zgl_InitToHandle( GDK_WINDOW_XID( widget^.window ) );
  397. {$ENDIF}
  398. {$ENDIF}
  399. {$IFDEF WINDOWS}
  400. zgl_InitToHandle( Panel1.Handle );
  401. {$ENDIF}
  402. timer1.Enabled := true;
  403. end;
  404. end;
  405. end.