unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, Forms, Graphics, StdCtrls, Types;
type
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
fTextPosX: Integer;
fTextPosY: Integer;
fFontSize: Integer;
fFontColor: TColor;
public
procedure TextInit(X, Y, S: Integer; C: TColor);
procedure TextColor(C: TColor);
procedure TextNormal(const S: string);
procedure TextSuperscript(const S: string);
procedure TextSubscript(const S: string);
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.Button1Click(Sender: TObject);
begin
TextInit(30, 20, 18, clBlack);
TextNormal('E := MC');
TextSuperscript('2');
TextInit(30, 60, 18, clBlack);
TextNormal('H');
TextSubscript('3');
TextNormal('O');
TextSuperscript('+');
TextInit(30, 100, 18, clBlack);
TextNormal('Lazarus is ');
TextColor(clRed); TextNormal('a');
TextColor(clPurple); TextNormal('w');
TextColor(clGreen); TextNormal('e');
TextColor(clBlue); TextNormal('s');
TextColor(clWhite); TextNormal('o');
TextColor(clMaroon); TextNormal('m');
TextColor(clYellow); TextNormal('e');
end;
procedure TForm1.TextInit(X, Y, S: Integer; C: TColor);
begin
fTextPosX := X;
fTextPosY := Y;
fFontSize := S;
fFontColor := C;
end;
procedure TForm1.TextColor(C: TColor);
begin
fFontColor := C;
end;
procedure TForm1.TextNormal(const S: string);
var
TextSize: TSize;
begin
with Canvas do
begin
Brush.Style := bsClear;
Font.Color := fFontColor;
Font.Size := fFontSize;
TextSize := TextExtent(S);
TextOut(fTextPosX, fTextPosY, S);
end;
Inc(fTextPosX, TextSize.cx);
end;
procedure TForm1.TextSuperscript(const S: string);
var
NewSize : Integer;
TextSize : TSize;
begin
NewSize := (fFontSize*2) div 3;
with Canvas do
begin
Brush.Style := bsClear;
Font.Color := fFontColor;
Font.Size := NewSize;
TextSize := TextExtent(S);
TextOut(fTextPosX, fTextPosY, S);
end;
Inc(fTextPosX, TextSize.cx);
end;
procedure TForm1.TextSubscript(const S: string);
var
NewSize : Integer;
TextSize : TSize;
begin
NewSize := (fFontSize*2) div 3;
with Canvas do
begin
Brush.Style := bsClear;
Font.Color := fFontColor;
Font.Size := NewSize;
TextSize := TextExtent(S);
TextOut(fTextPosX, fTextPosY+NewSize, S);
end;
Inc(fTextPosX, TextSize.cx);
end;
end.