unit jpxheader;

interface

uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, Buttons, ExtCtrls, ComCtrls,TextImages,iniFiles,adTextImages;

type


  TJPXFrame = class(TFrame)
    ColorDialog1: TColorDialog;
    HeightEdit: TEdit;
    heightUpDown: TUpDown;
    Label1: TLabel;
    Label2: TLabel;
    WidthEdit: TEdit;
    widthUpDown: TUpDown;
    Memo1: TMemo;
    BitBtn3: TBitBtn;
    smoothCB: TCheckBox;
    LineEdit: TEdit;
    lineUpDown: TUpDown;
    Label3: TLabel;
    FontComboBox: TComboBox;
    Label4: TLabel;
    Label5: TLabel;
    FontPanel: TPanel;
    FontSizeEdit: TEdit;
    FontSizeUpDown: TUpDown;
    Button1: TButton;
    ScreenPanel: TPanel;
    transCB: TCheckBox;
    autoLineCB: TCheckBox;
    procedure BitBtn3Click(Sender: TObject);
    procedure FontComboBoxChange(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure FontSizeEditChange(Sender: TObject);
  private
    { Private 宣言 }
    eventLock:boolean;
  public
    { Public 宣言 }
    tagLines:TStrings;
    viewBitmap:TBitmap;
    nowFileName:string;
    constructor create(Owner:TComponent);override;
    destructor destroy();override;
    function getJInf():TJPXInf;
    procedure loadJPX(fileName:string);
    procedure saveJPX(fileName:string);
   // procedure drawBack();
    procedure makeJPX(sList:TStrings;inf:TJPXInf);
  end;

implementation

{$R *.dfm}

(*フレーム*)
constructor TJPXFrame.create(Owner:TComponent);
var
 i,index:Integer;
begin
 inherited;
 eventLock:=false;
 FontComboBox.Clear();
 Memo1.Font.Charset:=DEFAULT_CHARSET;
 tagLines:=TStringList.Create();
 viewBitmap:=TBitmap.Create();

 for i:=0 to Screen.Fonts.Count -1 do
 begin
  FontComboBox.Items.Add(Screen.Fonts[i]);
 end;

 eventLock:=true;
 index:=FontComboBox.Items.IndexOf(Memo1.Font.Name);
 self.FontSizeUpDown.Position:=-memo1.Font.Height;

 if(index>-1)then
 begin
  FontComboBox.ItemIndex:=index;
 end;

  eventLock:=false;

end;

destructor TJPXFrame.destroy();
begin
 self.tagLines.Free();
 viewBitmap.Create();
 inherited;
end;

procedure TJPXFrame.BitBtn3Click(Sender: TObject);
begin
 ColorDialog1.Color:=Memo1.Color;
if(ColorDialog1.Execute)then
 Memo1.Color:=ColorDialog1.Color;
end;

procedure TJPXFrame.FontComboBoxChange(Sender: TObject);
begin
 if not(eventLock)then
  Memo1.Font.Name:=FontComboBox.Items.Strings[FontComboBox.ItemIndex];
end;

procedure TJPXFrame.Button1Click(Sender: TObject);
begin
 if not(eventLock)then
 begin
  ColorDialog1.Color:=Memo1.Font.Color;
  if(ColorDialog1.Execute)then
   Memo1.Font.Color:=ColorDialog1.Color;
 end;
end;

procedure TJPXFrame.FontSizeEditChange(Sender: TObject);
begin
 if not(eventLock)then
 begin
  Memo1.Lines.BeginUpdate;
  Memo1.Font.Height:=self.FontSizeUpDown.Position;
  Memo1.Lines.Strings[0]:=IntToStr(-Memo1.Font.Size)+'point';
  Memo1.Lines.EndUpdate;
 end;
end;

procedure TJPXFrame.loadJPX(fileName:string);
var
 loader:TADTextImage;
 inf:TJPXINF;
begin
 loader:=TADTextImage.Create();
 loader.setJPX(fileName);
 inf:=loader.jInf;

 self.FontSizeUpDown.Position:=inf.fontPixels;
 self.smoothCB.Checked:=inf.smooth;
 self.lineUpDown.Position:=inf.lineHeight;
 self.transCB.Checked:=inf.fontTrans;

 self.widthUpDown.Position:=inf.width;
 self.heightUpDown.Position:=inf.height;
 Memo1.Lines.BeginUpdate;
 Memo1.Color:=inf.backColor;
 Memo1.Font.Color:=inf.fontColor;
 Memo1.Font.Height:=inf.fontPixels;
 Memo1.Font.Name:='ＭＳ Ｐゴシック';
 Memo1.Font.Name:=inf.fontName;
 Memo1.Lines.EndUpdate;
 self.autoLineCB.Checked:=inf.autoLine;

 tagLines.Clear();
 tagLines.AddStrings(loader.strings);
 viewBitmap.Assign(loader.bitmap);
 viewBitmap.Canvas.Brush.Color:=Memo1.Color;
 self.nowFileName:=fileName;

 loader.Free();

end;

procedure TJPXFrame.makeJPX(sList:TStrings;inf:TJPXInf);
var
 loader:TADTextImage;
begin
 tagLines.Assign(sList);
 loader:=TADTextImage.Create();
 loader.setJPX(sList,inf);
 viewBitmap.Assign(loader.bitmap);
 viewBitmap.Canvas.Brush.Color:=inf.backColor;
 loader.Free();
end;

procedure TJPXFrame.saveJPX(fileName:string);
var
 loader:TADTextImage;
begin
 loader:=TADTextImage.Create();
 loader.nowFileName:=nowFileName;
 loader.setJPX(tagLines,getJInf());
 loader.saveToFile(fileName);
 loader.nowFileName:=fileName;
 loader.Free();
end;

function TJPXFrame.getJInf():TJPXInf;
begin
 result.width:=self.widthUpDown.Position;
 result.height:=self.heightUpDown.Position;
 result.lineHeight:=self.lineUpDown.Position;
 result.fontPixels:=self.Memo1.Font.Height;
 result.fontName:=self.Memo1.Font.Name;
 result.backColor:=self.Memo1.Color;
 result.fontColor:=self.Memo1.Font.Color;
 result.smooth:=self.smoothCB.Checked;
 result.autoLine:=self.autoLineCB.Checked;
 result.fontTrans:=self.transCB.Checked;
end;

end.
