unit U_MakeMarkPage;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, RzButton, ExtCtrls, RzPanel, RzCmboBx, RzRadChk, Mask,
  RzEdit, RzSpnEdt, Buttons, RzLabel, RzCommon, ImgList, U_BaseCommon, U_BaseConstants,
  RzLine, Printers, Menus, XPMenu, siComp, siLngLnk;

type
  TF_MakeMarkPage = class(TForm)
    RzPanel1: TRzPanel;
    RzPanel2: TRzPanel;
    btOK: TRzBitBtn;
    btCancel: TRzBitBtn;
    RzGroupBox1: TRzGroupBox;
    Label1: TLabel;
    cbPageSize: TRzComboBox;
    RzGroupBox2: TRzGroupBox;
    rbPortrait: TRzRadioButton;
    rbLandscape: TRzRadioButton;
    RzGroupBox3: TRzGroupBox;
    RzGroupBox4: TRzGroupBox;
    Label4: TLabel;
    cbUnitOfMeasure: TRzComboBox;
    RzGroupBox5: TRzGroupBox;
    Label2: TLabel;
    Label3: TLabel;
    seCellWidth: TRzSpinEdit;
    seCellHeight: TRzSpinEdit;
    RzGroupBox6: TRzGroupBox;
    Label5: TLabel;
    cbFontName: TRzFontComboBox;
    Label6: TLabel;
    seFontSize: TRzSpinEdit;
    RzGroupBox7: TRzGroupBox;
    cbFontBold: TRzCheckBox;
    cbFontItalic: TRzCheckBox;
    cbFontUnderline: TRzCheckBox;
    cbCreateTitlePage: TRzCheckBox;
    cbShowPageNumber: TRzCheckBox;
    RzGroupBox8: TRzGroupBox;
    RzPanel3: TRzPanel;
    lbBorderTop: TRzLabel;
    lbBorderBottom: TRzLabel;
    lbBorderLeft: TRzLabel;
    lbBorderRight: TRzLabel;
    pnSample: TRzPanel;
    Label7: TLabel;
    cbLineStyle: TRzImageComboBox;
    ilLineStyles: TImageList;
    Label8: TLabel;
    ceLineColor: TRzColorEdit;
    Label9: TLabel;
    Label10: TLabel;
    cbLineWidth: TRzComboBox;
    RzGroupBox9: TRzGroupBox;
    Label11: TLabel;
    Label12: TLabel;
    Label13: TLabel;
    Label14: TLabel;
    seMarginLeft: TRzSpinEdit;
    seMarginRight: TRzSpinEdit;
    seMarginTop: TRzSpinEdit;
    seMarginBottom: TRzSpinEdit;
    RzPanel5: TRzPanel;
    cbOpenInDesigner: TRzCheckBox;
    Label15: TLabel;
    seCellGap: TRzSpinEdit;
    pmRecommCellSizes: TPopupMenu;
    XPMenu: TXPMenu;
    lbRecommCellSize: TRzLabel;
    lng_Forms: TsiLangLinked;
    procedure lbBorderClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure cbLineWidthKeyPress(Sender: TObject; var Key: Char);
    procedure cbUnitOfMeasureChange(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure btOKClick(Sender: TObject);
    procedure pnSamplePaint(Sender: TObject);
    procedure OnSampleFontChange(Sender: TObject);
    procedure OnSampleFrameChange(Sender: TObject);
    procedure lbRecommCellSizeClick(Sender: TObject);

  private
    GForm: TForm;
    FReportType: Integer;

    FBorderStyleUp: TFrameStyleEx;
    FBorderStyleDown: TFrameStyleEx;
    FFloatSpinEdits: TList;
    FCurrUnitOfMeassure: Integer;

    FRecommWidth: TStringList;
    FRecomHeight: TStringList;
    FRecomComment: TStringList;

    procedure DefineRecommendedCellSizes;
    procedure DefinePMRecommendedCellSizes;
    procedure OnMemuItemRecommClick(Sender: TObject);
    procedure PrepareSampleFont;
    procedure PrepareSampleFrame;
    procedure SetRecommendedCellSizes(AIndex: Integer);
  public
    FResPrinterOrientation: TPrinterOrientation;
    FResFont: TFont;
    FResFrameStyle: Integer;
    FResFrameTyp: Word;
    FResFrameWidth: Double;

    Constructor Create(AOwner: TComponent; AForm: TForm);
    Destructor Destroy; override;

    function Execute(AReportType: Integer): Boolean;
    function GetSpinEditValueMM(ASpinEdit: TRzSpinEdit): Double;
  end;

//var
//  Form1: TForm1;

implementation

Uses FR_Prntr;

{$R *.dfm}

constructor TF_MakeMarkPage.Create(AOwner: TComponent; AForm: TForm);
begin
  GForm := AForm;
  inherited Create(AOwner);
end;

destructor TF_MakeMarkPage.Destroy;
begin
  inherited;
end;

procedure TF_MakeMarkPage.DefineRecommendedCellSizes;
  procedure AddItemToRecomm(AWidth, AHeight: Double; AComment: String; ARotate: Boolean = false);
  begin
    if Not ARotate then
    begin
      FRecommWidth.Add(FloatToStr(AWidth));
      FRecomHeight.Add(FloatToStr(AHeight));
    end
    else
    begin
      FRecommWidth.Add(FloatToStr(AHeight));
      FRecomHeight.Add(FloatToStr(AWidth));
    end;
    FRecomComment.Add(AComment);
  end;
begin
  try
    FRecommWidth.Clear;
    FRecomHeight.Clear;
    FRecomComment.Clear;

    // Добавляем размеры в mm
    case FReportType of
      rtMarkRoomTS:
        begin
          //AddItemToRecomm(50.80, 25.40, '');
          //AddItemToRecomm(18.80, 25.40, '');
          //AddItemToRecomm(15.49, 25.40, '');

          AddItemToRecomm(15.49, 25.40, '');
          AddItemToRecomm(18.80, 25.40, '');
          AddItemToRecomm(50.80, 25.40, '');
        end;
      rtMarkPathPanel:
        begin
          //AddItemToRecomm(15.49, 7.62, '');
          //AddItemToRecomm(16.57, 7.62, '');
          //AddItemToRecomm(16.05, 7.62, '');
          //AddItemToRecomm(32.00, 7.62, '');
          //AddItemToRecomm(16.51, 7.62, '');

          AddItemToRecomm(15.49, 7.62, '');
          //AddItemToRecomm(16.05, 7.62, '');
          AddItemToRecomm(16.51, 7.62, '');
          //AddItemToRecomm(16.57, 7.62, '');
          AddItemToRecomm(32.00, 7.62, '');
        end;
      rtMarkPathPanelPorts:
        begin
          //AddItemToRecomm(15.49, 7.62, '');
          //AddItemToRecomm(16.57, 7.62, '');
          //AddItemToRecomm(16.05, 7.62, '');
          //AddItemToRecomm(16.51, 7.62, '');

          AddItemToRecomm(15.49, 7.62, '');
          //AddItemToRecomm(16.05, 7.62, '');
          AddItemToRecomm(16.51, 7.62, '');
          //AddItemToRecomm(16.57, 7.62, '');
        end;
      rtMarkSocket, rtMarkSocketPanel:
        begin
          //AddItemToRecomm(15.24, 5.08, '');
          //AddItemToRecomm(15.49, 7.62, '');
          //AddItemToRecomm(25.40, 6.35, '');
          //AddItemToRecomm(15.88, 7.62, '');
          //AddItemToRecomm(15.92, 7.62, '');
          //AddItemToRecomm(16.57, 7.62, '');
          //AddItemToRecomm(16.00, 7.62, '');

          //AddItemToRecomm(49.53, 10.16, '');
          //AddItemToRecomm(39.58, 10.16, '');

          AddItemToRecomm(15.24, 5.08, '');
          AddItemToRecomm(15.49, 7.62, '');
          AddItemToRecomm(25.40, 6.35, '');
          AddItemToRecomm(35.05, 4.83, '');
          AddItemToRecomm(39.58, 10.16, '');
          AddItemToRecomm(40.64, 5.08, '');
          AddItemToRecomm(49.53, 10.16, '');
        end;
      rtMarkCable:
        begin
          //AddItemToRecomm(12.70, 38.10, 'для кабеля кат. 5/5е/6', true);
          //AddItemToRecomm(25.40, 31.75, 'для кабеля 12-10 AWG', true);
          //AddItemToRecomm(25.40, 38.10, 'для кабеля кат. 5/5е/6', true);
          //AddItemToRecomm(50.80, 106.60, 'для кабеля 2-1 AWG', true);
          //AddItemToRecomm(12.70, 19.05, 'для кабеля 18-14 AWG', true);
          //AddItemToRecomm(12.70, 31.75, 'для кабеля 12-10 AWG', true);
          //AddItemToRecomm(12.70, 38.10, 'для кабеля кат. 5/5е/6', true);
          //AddItemToRecomm(25.40, 19.05, 'для кабеля 18-14 AWG', true);
          //AddItemToRecomm(25.40, 31.75, 'для кабеля 12-10 AWG', true);
          //AddItemToRecomm(25.40, 38.10, 'для кабеля кат. 5/5е/6', true);
          //AddItemToRecomm(25.40, 57.15, 'для кабеля 8-4 AWG', true);
          //AddItemToRecomm(25.40, 101.60, 'для кабеля 2-1 AWG', true);
          //AddItemToRecomm(25.40, 165.10, 'для кабеля 1/0-250 МСМ', true);


          AddItemToRecomm(12.70, 19.05, cMakeMarkPage_Msg3_1, true);
          AddItemToRecomm(25.40, 19.05, cMakeMarkPage_Msg3_1, true);
          AddItemToRecomm(12.70, 31.75, cMakeMarkPage_Msg3_2, true);
          AddItemToRecomm(25.40, 31.75, cMakeMarkPage_Msg3_2, true);
          AddItemToRecomm(12.70, 38.10, cMakeMarkPage_Msg3_3, true);
          AddItemToRecomm(25.40, 38.10, cMakeMarkPage_Msg3_3, true);
          AddItemToRecomm(25.40, 57.15, cMakeMarkPage_Msg3_4, true);
          AddItemToRecomm(25.40, 101.60, cMakeMarkPage_Msg3_5, true);
          AddItemToRecomm(50.80, 106.60, cMakeMarkPage_Msg3_5, true);
          AddItemToRecomm(25.40, 165.10, cMakeMarkPage_Msg3_6, true);
        end;
    end;
  except
    on E: Exception do AddExceptionToLogEx('TF_MakeMarkPage.DefineRecommendedCellSizes', E.Message);
  end;
end;

procedure TF_MakeMarkPage.DefinePMRecommendedCellSizes;
var
  i: integer;
  MenuItem: TMenuItem;
  MenuItemCaption: String;
  Uom: String;

  function GetMenuItemCaption(AIndex: Integer): String;
  begin
    Result := '';
    try
      //Result := FloatToStrFix(FloatInUOM(StrToFloat(FRecommWidth[AIndex]), umMillimetr, FCurrUnitOfMeassure), 2)+Uom +' x '+
      //          FloatToStrFix(FloatInUOM(StrToFloat(FRecomHeight[AIndex]), umMillimetr, FCurrUnitOfMeassure), 2)+Uom;
      Result := FormatFloat('0.00', FloatInUOM(StrToFloat(FRecommWidth[AIndex]), umMillimetr, FCurrUnitOfMeassure))+Uom +' x '+
                FormatFloat('0.00', FloatInUOM(StrToFloat(FRecomHeight[AIndex]), umMillimetr, FCurrUnitOfMeassure))+Uom;
      if FRecomComment[AIndex] <> '' then
        Result := Result + ' ('+FRecomComment[AIndex]+')';
    except
    end;
  end;

begin
  try
    Uom := '';
    case Integer(cbUnitOfMeasure.Items.Objects[cbUnitOfMeasure.ItemIndex]) of
      umMillimetr:
        Uom := 'mm';
      umSantimetr:
        Uom := 'sm';
      umInch:
        Uom := '"';
    end;

    pmRecommCellSizes.Items.Clear;
    for i := 0 to FRecommWidth.Count - 1 do
    begin
      MenuItemCaption := GetMenuItemCaption(i);
      if MenuItemCaption <> '' then
      begin
        MenuItem := TMenuItem.Create(pmRecommCellSizes);
        MenuItem.Caption := MenuItemCaption;
        MenuItem.Tag := i;
        MenuItem.OnClick := OnMemuItemRecommClick;
        pmRecommCellSizes.Items.Add(MenuItem);
      end;
    end;

    if pmRecommCellSizes.Items.Count > 0 then
    begin
      MenuItem := TMenuItem.Create(pmRecommCellSizes);
      MenuItem.Caption := '-';
      pmRecommCellSizes.Items.Add(MenuItem);

      MenuItem := TMenuItem.Create(pmRecommCellSizes);
      MenuItem.Caption := cMain_Msg91;
      pmRecommCellSizes.Items.Add(MenuItem);
    end;

    XPMenu.Active := false;
    XPMenu.Active := true;
  except
    on E: Exception do AddExceptionToLogEx('TF_MakeMarkPage.DefinePMRecommendedCellSizes', E.Message);
  end;
end;

procedure TF_MakeMarkPage.OnMemuItemRecommClick(Sender: TObject);
var
  MenuItem: TMenuItem;
begin
  try
    if Sender is TMenuItem then
    begin
      MenuItem := TMenuItem(Sender);
      if MenuItem.Tag <> -1 then
      begin
        SetRecommendedCellSizes(MenuItem.Tag);
      end;
    end;
  except
    on E: Exception do AddExceptionToLogEx('TF_MakeMarkPage.OnMemuItemRecommClick', E.Message);
  end;
end;


function TF_MakeMarkPage.Execute(AReportType: Integer): Boolean;
begin
  Result := false;
  try
    FReportType := AReportType;

    PrepareSampleFont;
    PrepareSampleFrame;

    DefineRecommendedCellSizes;
    SetRecommendedCellSizes(0);

    if ShowModal = mrOk then
    begin
      Result := true;

      //Ориентация бумаги
      if rbPortrait.Checked then
        FResPrinterOrientation := poPortrait
      else
      if rbLandscape.Checked then
        FResPrinterOrientation := poLandscape;

      // Шрифт
      FResFont.Name := cbFontName.FontName;
      FResFont.Size := Trunc(seFontSize.Value);
      if cbFontBold.Checked then
        FResFont.Style := FResFont.Style + [fsBold];
      if cbFontItalic.Checked then
        FResFont.Style := FResFont.Style + [fsItalic];
      if cbFontUnderline.Checked then
        FResFont.Style := FResFont.Style + [fsUnderline];

      // Стиль линии
      FResFrameStyle := cbLineStyle.ItemIndex;
      // Граници линии
      FResFrameTyp := 0;
      if lbBorderLeft.BorderOuter = FBorderStyleDown then
        FResFrameTyp := FResFrameTyp or $4;
      if lbBorderRight.BorderOuter = FBorderStyleDown then
        FResFrameTyp := FResFrameTyp or $1;
      if lbBorderTop.BorderOuter = FBorderStyleDown then
        FResFrameTyp := FResFrameTyp or $8;
      if lbBorderBottom.BorderOuter = FBorderStyleDown then
        FResFrameTyp := FResFrameTyp or $2;

      FResFrameWidth := 1;
      try
        FResFrameWidth := StrToFloat(cbLineWidth.Text);
      except
      end;
    end;
  except
    on E: Exception do AddExceptionToLogEx('TF_MakeMarkPage.Execute', E.Message);
  end;
end;

function TF_MakeMarkPage.GetSpinEditValueMM(ASpinEdit: TRzSpinEdit): Double;
begin
  Result := FloatInUOM(ASpinEdit.Value, FCurrUnitOfMeassure, umMillimetr);
end;

procedure TF_MakeMarkPage.lbBorderClick(Sender: TObject);
begin
  if Sender is TRZLabel then
  begin
    if TRZLabel(Sender).BorderOuter = FBorderStyleUp then
      TRZLabel(Sender).BorderOuter := FBorderStyleDown
    else
    if TRZLabel(Sender).BorderOuter = FBorderStyleDown then
      TRZLabel(Sender).BorderOuter := FBorderStyleUp;

    PrepareSampleFrame;
  end;
end;

procedure TF_MakeMarkPage.FormCreate(Sender: TObject);
var
  i: Integer;
  RzSpinEdit: TRzSpinEdit;
begin
  FBorderStyleUp := fsPopup;
  FBorderStyleDown := fsLowered;

  FResFont := TFont.Create;

  //cbLineColor.ColorNames
  FCurrUnitOfMeassure := -1;
  cbUnitOfMeasure.Items.AddObject(cMakeMarkPage_Msg1_1, TObject(umMillimetr));
  cbUnitOfMeasure.Items.AddObject(cMakeMarkPage_Msg1_2, TObject(umSantimetr));
  cbUnitOfMeasure.Items.AddObject(cMakeMarkPage_Msg1_3, TObject(umInch));

  //cbLineStyle.AddItem('Сплошная', 0, 0);
  //cbLineStyle.AddItem('Тире', 1, 0);
  //cbLineStyle.AddItem('Точка', 2, 0);
  //cbLineStyle.AddItem('Точка тире', 3, 0);
  //cbLineStyle.AddItem('Тире точка точка', 4, 0);
  //cbLineStyle.AddItem('Двойная', 5, 0);
  cbLineStyle.AddItem('', 0, 0);
  cbLineStyle.AddItem('', 1, 0);
  cbLineStyle.AddItem('', 2, 0);
  cbLineStyle.AddItem('', 3, 0);
  cbLineStyle.AddItem('', 4, 0);
  cbLineStyle.AddItem('', 5, 0);

  ceLineColor.DefaultColorCaption := cColorEdit_DefaultColorCaption;
  ceLineColor.CustomColorCaption := cColorEdit_CustomColorCaption;

  cbLineWidth.Items.Add(FloatToStr(0.1));
  cbLineWidth.Items.Add(FloatToStr(0.5));
  cbLineWidth.Items.Add(FloatToStr(1));
  cbLineWidth.Items.Add(FloatToStr(1.5));
  for i := 2 to 10 do
    cbLineWidth.Items.Add(FloatToStr(i));

  // Float SpinEdits
  FFloatSpinEdits := TList.Create;
  FFloatSpinEdits.Add(seMarginLeft);
  FFloatSpinEdits.Add(seMarginRight);
  FFloatSpinEdits.Add(seMarginTop);
  FFloatSpinEdits.Add(seMarginBottom);
  FFloatSpinEdits.Add(seCellWidth);
  FFloatSpinEdits.Add(seCellHeight);
  FFloatSpinEdits.Add(seCellGap);
  for i := 0 to FFloatSpinEdits.Count - 1 do
  begin
    RzSpinEdit := TRzSpinEdit(FFloatSpinEdits[i]);
    RzSpinEdit.AllowKeyEdit := true;
    RzSpinEdit.Decimals := 2;
    RzSpinEdit.IntegersOnly := false;
    RzSpinEdit.Update;
  end;

  FRecommWidth := TStringList.Create;
  FRecomHeight := TStringList.Create;
  FRecomComment := TStringList.Create;


  // Единици измерения - миллиметры
  cbUnitOfMeasure.ItemIndex := cbUnitOfMeasure.Items.IndexOfObject(TObject(umMillimetr));
  FCurrUnitOfMeassure := umMillimetr;

  // Формат листа - A4
  cbPageSize.Items.Clear;
  cbPageSize.Items.AddStrings(Prn.PaperNames);
  cbPageSize.ItemIndex := cbPageSize.Items.IndexOf('A4');
  // Ориентация
  rbPortrait.Checked := true;
  //Границы
  seMarginLeft.Value := 20;
  seMarginRight.Value := 5;
  seMarginTop.Value := 5;
  seMarginBottom.Value := 5;

  // Размеры наклейки
  seCellHeight.Value := 14;
  seCellWidth.Value := 40;

  // Наименование шрифта
  cbFontName.ItemIndex := cbFontName.Items.IndexOf('Arial');
  // Размер шрифта
  seFontSize.Value := 12;
  // Стиль шрифта
  cbFontBold.Checked := false;
  cbFontItalic.Checked := false;
  cbFontUnderline.Checked := false;

  // Граници наклейки
  lbBorderTop.BorderOuter := FBorderStyleDown;
  lbBorderBottom.BorderOuter := FBorderStyleDown;
  lbBorderLeft.BorderOuter := FBorderStyleUp;
  lbBorderRight.BorderOuter := FBorderStyleUp;
  // Стиль линии
  if cbLineStyle.Items.Count > 0 then
    cbLineStyle.ItemIndex := 0;
  // Цвет линии - черный
  ceLineColor.SelectedColor := clBlack;
  // Толщина линии
  cbLineWidth.ItemIndex := cbLineWidth.IndexOf(FloatToStr(1));
end;

procedure TF_MakeMarkPage.FormDestroy(Sender: TObject);
begin
  FreeAndNil(FFloatSpinEdits);
  FreeAndNil(FResFont);
end;


procedure TF_MakeMarkPage.cbLineWidthKeyPress(Sender: TObject;
  var Key: Char);
var
  NewText: String;
  RzSpinEdit: TRzSpinEdit;
begin
  NewText := cbLineWidth.Text + Key;
  try
    if NewText <> '' then
      StrToFloat(NewText);
  except
    Key := #0;
  end;
end;

procedure TF_MakeMarkPage.cbUnitOfMeasureChange(Sender: TObject);
var
  NewUnitOfMeassure: Integer;
  i: integer;
  RzSpinEdit: TRzSpinEdit;
begin
  try
    if FCurrUnitOfMeassure <> -1 then
    begin
      NewUnitOfMeassure := Integer(cbUnitOfMeasure.Items.Objects[cbUnitOfMeasure.ItemIndex]);
      for i := 0 to FFloatSpinEdits.Count - 1 do
      begin
        RzSpinEdit := TRzSpinEdit(FFloatSpinEdits[i]); 
        RzSpinEdit.Value := FloatInUOM(RzSpinEdit.Value, FCurrUnitOfMeassure, NewUnitOfMeassure);
      end;
      FCurrUnitOfMeassure := NewUnitOfMeassure;
    end;
  except
    on E: Exception do AddExceptionToLogEx('TF_MakeMarkPage.cbUnitOfMeasureChange', E.Message);
  end;
end;


procedure TF_MakeMarkPage.btOKClick(Sender: TObject);
var
  ControlToFocus: TWinControl;
begin
  ControlToFocus := nil;
  if cbPageSize.Text = '' then
  begin
    MessageModal(cMakeMarkPage_Msg2, ApplicationName, MB_ICONINFORMATION or MB_OK);
    ControlToFocus := cbPageSize;
  end;

  if ControlToFocus <> nil then
  begin
    ModalResult := mrNone;
    ControlToFocus.SetFocus;
  end;
end;

procedure TF_MakeMarkPage.pnSamplePaint(Sender: TObject);
var
  Margin: Integer;
  FrameColor: Integer;
  FrameWidth: Integer;
  FrameStyle: integer;
  FillColor: Integer;

  procedure ShowLine(x, y, x1, y1: Integer);
  var
    i, w: Integer;
  begin
    if pnSample.Canvas.Pen.Style = psSolid then
    begin
      if FrameStyle <> 5 then
      begin
        pnSample.Canvas.MoveTo(x, y);
        pnSample.Canvas.LineTo(x1, y1);
      end
      else
      begin
        if x = x1 then
        begin
          pnSample.Canvas.MoveTo(x - Round(FrameWidth), y);
          pnSample.Canvas.LineTo(x1 - Round(FrameWidth), y1);
          pnSample.Canvas.Pen.Color := FillColor;
          pnSample.Canvas.MoveTo(x, y);
          pnSample.Canvas.LineTo(x1, y1);
          pnSample.Canvas.Pen.Color := FrameColor;
          pnSample.Canvas.MoveTo(x + Round(FrameWidth), y);
          pnSample.Canvas.LineTo(x1 + Round(FrameWidth), y1);
        end
        else
        begin
          pnSample.Canvas.MoveTo(x, y - Round(FrameWidth));
          pnSample.Canvas.LineTo(x1, y1 - Round(FrameWidth));
          pnSample.Canvas.Pen.Color := FillColor;
          pnSample.Canvas.MoveTo(x, y);
          pnSample.Canvas.LineTo(x1, y1);
          pnSample.Canvas.Pen.Color := FrameColor;
          pnSample.Canvas.MoveTo(x, y + Round(FrameWidth));
          pnSample.Canvas.LineTo(x1, y1 + Round(FrameWidth));
        end;
      end;
    end
    else
    begin
      pnSample.Canvas.Brush.Color := FillColor;
      w := pnSample.Canvas.Pen.Width;
      pnSample.Canvas.Pen.Width := 1;
      if x = x1 then
        for i := 0 to w - 1 do
        begin
          pnSample.Canvas.MoveTo(x - w div 2 + i, y);
          pnSample.Canvas.LineTo(x - w div 2 + i, y1);
        end
      else
        for i := 0 to w - 1 do
        begin
          pnSample.Canvas.MoveTo(x, y - w div 2 + i);
          pnSample.Canvas.LineTo(x1, y - w div 2 + i);
        end;
      pnSample.Canvas.Pen.Width := w;
    end;
  end;

begin
  FrameWidth := 1;
  try
    FrameWidth := Round(StrToFloat(cbLineWidth.Text));
  except
  end;

  FillColor := clWhite;
  FrameColor := ceLineColor.SelectedColor;
  pnSample.Canvas.Pen.Color := FrameColor;
  pnSample.Canvas.Pen.Width := Round(FrameWidth);
  FrameStyle := cbLineStyle.ItemIndex;
  if FrameStyle <> 5 then
    pnSample.Canvas.Pen.Style := TPenStyle(FrameStyle);

  Margin := 1;
  if lbBorderLeft.BorderOuter = FBorderStyleDown then
    ShowLine(Margin, Margin, Margin, pnSample.Height - Margin);
  if lbBorderRight.BorderOuter = FBorderStyleDown then
    ShowLine(pnSample.Width - Margin, Margin, pnSample.Width - Margin, pnSample.Height - Margin);
  if lbBorderTop.BorderOuter = FBorderStyleDown then
    ShowLine(Margin, Margin, pnSample.Width - Margin, Margin);
  if lbBorderBottom.BorderOuter = FBorderStyleDown then
    ShowLine(Margin, pnSample.Height - Margin, pnSample.Width - Margin, pnSample.Height - Margin);
end;

procedure TF_MakeMarkPage.PrepareSampleFont;
begin
  pnSample.Font.Name := cbFontName.SelectedFont.Name;
  pnSample.Font.Size := Trunc(seFontSize.Value);
  pnSample.Font.Style := [];
  if cbFontBold.Checked then
    pnSample.Font.Style := pnSample.Font.Style + [fsBold];
  if cbFontItalic.Checked then
    pnSample.Font.Style := pnSample.Font.Style + [fsItalic];
  if cbFontUnderline.Checked then
    pnSample.Font.Style := pnSample.Font.Style + [fsUnderline];
end;

procedure TF_MakeMarkPage.PrepareSampleFrame;
begin
  pnSample.Repaint;
end;

procedure TF_MakeMarkPage.SetRecommendedCellSizes(AIndex: Integer);
var
  CellWidth: Double;
  CellHeight: Double;
begin
  try
    if (AIndex >= 0) and (AIndex <= (FRecommWidth.Count-1)) then
    begin
      CellWidth := seCellWidth.Value;
      CellHeight := seCellHeight.Value;
      try
        CellWidth := FloatInUOM(StrToFloat(FRecommWidth[AIndex]), umMillimetr, FCurrUnitOfMeassure);
      except
      end;
      try
        CellHeight := FloatInUOM(StrToFloat(FRecomHeight[AIndex]), umMillimetr, FCurrUnitOfMeassure);
      except
      end;
      seCellWidth.Value := CellWidth;
      seCellHeight.Value := CellHeight;
    end;
  except
    on E: Exception do AddExceptionToLogEx('TF_MakeMarkPage.SetRecommendedCellSizes', E.Message);
  end;
end;


procedure TF_MakeMarkPage.OnSampleFontChange(Sender: TObject);
begin
  PrepareSampleFont;
end;

procedure TF_MakeMarkPage.OnSampleFrameChange(Sender: TObject);
begin
  PrepareSampleFrame;
end;

procedure TF_MakeMarkPage.lbRecommCellSizeClick(Sender: TObject);
begin
  if Sender is TControl then
  begin
    DefinePMRecommendedCellSizes;
    ShowPopupMenuForControl(TControl(Sender), pmRecommCellSizes);
  end;
end;

end.
