📄 remain.pas
字号:
if BoldButton.Down then
CurrText.Style := CurrText.Style + [fsBold]
else
CurrText.Style := CurrText.Style - [fsBold];
end;
procedure TMainForm.ItalicButtonClick(Sender: TObject);
begin
if FUpdating then Exit;
if ItalicButton.Down then
CurrText.Style := CurrText.Style + [fsItalic]
else
CurrText.Style := CurrText.Style - [fsItalic];
end;
procedure TMainForm.FontSizeChange(Sender: TObject);
begin
if FUpdating then Exit;
CurrText.Size := StrToInt(FontSize.Text);
end;
procedure TMainForm.AlignButtonClick(Sender: TObject);
begin
if FUpdating then Exit;
Editor.Paragraph.Alignment := TAlignment(TControl(Sender).Tag);
end;
procedure TMainForm.FontNameChange(Sender: TObject);
begin
if FUpdating then Exit;
CurrText.Name := FontName.Items[FontName.ItemIndex];
end;
procedure TMainForm.UnderlineButtonClick(Sender: TObject);
begin
if FUpdating then Exit;
if UnderlineButton.Down then
CurrText.Style := CurrText.Style + [fsUnderline]
else
CurrText.Style := CurrText.Style - [fsUnderline];
end;
procedure TMainForm.BulletsButtonClick(Sender: TObject);
begin
if FUpdating then Exit;
Editor.Paragraph.Numbering := TNumberingStyle(BulletsButton.Down);
end;
procedure TMainForm.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
try
CheckFileSave;
except
CanClose := False;
end;
end;
{ Ruler Indent Dragging }
procedure TMainForm.RulerItemMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
FDragOfs := (TLabel(Sender).Width div 2);
TLabel(Sender).Left := TLabel(Sender).Left+X-FDragOfs;
FDragging := True;
end;
procedure TMainForm.RulerItemMouseMove(Sender: TObject; Shift: TShiftState;
X, Y: Integer);
begin
if FDragging then
TLabel(Sender).Left := TLabel(Sender).Left+X-FDragOfs
end;
procedure TMainForm.FirstIndMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
FDragging := False;
Editor.Paragraph.FirstIndent := Trunc((FirstInd.Left+FDragOfs-GutterWid) / RulerAdj);
LeftIndMouseUp(Sender, Button, Shift, X, Y);
end;
procedure TMainForm.LeftIndMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
FDragging := False;
Editor.Paragraph.LeftIndent := Trunc((LeftInd.Left+FDragOfs-GutterWid) / RulerAdj)-Editor.Paragraph.FirstIndent;
SelectionChange(Sender);
end;
procedure TMainForm.RightIndMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
FDragging := False;
Editor.Paragraph.RightIndent := Trunc((Ruler.ClientWidth-RightInd.Left+FDragOfs-2) / RulerAdj)-2*GutterWid;
SelectionChange(Sender);
end;
procedure TMainForm.UpdateCursorPos;
var
CharPos: TPoint;
begin
CharPos.Y := SendMessage(Editor.Handle, EM_EXLINEFROMCHAR, 0,
Editor.SelStart);
CharPos.X := (Editor.SelStart -
SendMessage(Editor.Handle, EM_LINEINDEX, CharPos.Y, 0));
Inc(CharPos.Y);
Inc(CharPos.X);
StatusBar.Panels[0].Text := Format(sColRowInfo, [CharPos.Y, CharPos.X]);
end;
procedure TMainForm.FormShow(Sender: TObject);
begin
UpdateCursorPos;
DragAcceptFiles(Handle, True);
RichEditChange(nil);
Editor.SetFocus;
{ Check if we should load a file from the command line }
if (ParamCount > 0) and FileExists(ParamStr(1)) then
PerformFileOpen(ParamStr(1));
end;
procedure TMainForm.WMDropFiles(var Msg: TWMDropFiles);
var
CFileName: array[0..MAX_PATH] of Char;
begin
try
if DragQueryFile(Msg.Drop, 0, CFileName, MAX_PATH) > 0 then
begin
CheckFileSave;
PerformFileOpen(CFileName);
Msg.Result := 0;
end;
finally
DragFinish(Msg.Drop);
end;
end;
procedure TMainForm.RichEditChange(Sender: TObject);
begin
SetModified(Editor.Modified);
end;
procedure TMainForm.SetModified(Value: Boolean);
begin
if Value then StatusBar.Panels[1].Text := sModified
else StatusBar.Panels[1].Text := '';
end;
procedure TMainForm.ActionList2Update(Action: TBasicAction;
var Handled: Boolean);
begin
{ Update the status of the edit commands }
EditCutCmd.Enabled := Editor.SelLength > 0;
EditCopyCmd.Enabled := EditCutCmd.Enabled;
if Editor.HandleAllocated then
begin
EditUndoCmd.Enabled := Editor.Perform(EM_CANUNDO, 0, 0) <> 0;
EditPasteCmd.Enabled := Editor.Perform(EM_CANPASTE, 0, 0) <> 0;
end;
end;
procedure TMainForm.CreateFonts;
begin
// Creating a font for a table header
TableHeaderFont := TFont.Create();
with TableHeaderFont do
begin
Color := clBlack;
Size := 12;
Name := 'Impact';
end;
// Creating a font for a simple text
TextFont := TFont.Create();
with TextFont do
begin
Color := clBlack;
Size := 12;
Name := 'Times New Roman';
end;
// Creating a font for a link text
LinkFont := TFont.Create();
with LinkFont do
begin
Color := clBlue;
Size := 12;
Name := 'Times New Roman';
end;
// Creating a font for a bold text
BoldTextFont := TFont.Create();
with BoldTextFont do
begin
Color := clBlack;
Style := Style + [fsBold];
Size := 10;
Name := 'Times New Roman';
end;
// Creating a font for a document header
HeaderFont := TFont.Create();
with HeaderFont do
begin
Color := clNavy;
Size := 12;
Style := Style + [fsBold];
Name := 'Times New Roman';
end;
end;
procedure TMainForm.DestroyFonts;
begin
TableHeaderFont.Free;
HeaderFont.Free;
TextFont.Free;
BoldTextFont.Free;
LinkFont.Free;
end;
procedure TMainForm.GeneratePDFExecute(Sender: TObject);
function CompareAttributes(First: TFont ; Second: TTextAttributes) : boolean;
begin
CompareAttributes := false;
with First do
begin
If CharSet <> Second.Charset then Exit;
If Color <> Second.Color then Exit;
If Name <> Second.Name then Exit;
If Pitch <> Second.Pitch then Exit;
If Size <> Second.Size then Exit;
If Style <> Second.Style then Exit;
CompareAttributes := true;
end;
end;
procedure AssignAttributes(Source: TTextAttributes; var Dest: TFont);
begin
with Dest do
begin
CharSet := Source.Charset;
Color := Source.Color;
Name := Source.Name;
Pitch := Source.Pitch;
Size := Source.Size;
Style := Source.Style;
end;
end;
var i: integer;
Alignment: TAlignment;
TextAlign: TRenderTextAlign;
Line: String;
Attributes: TFont;
Caret: TPoint;
HeaderTable, PricingTable: TRenderTable;
LeftPicture,
RightPicture: TPicture;
AParagraph: TRenderCell;
begin
Alignment := taLeftJustify;
TextALign := rtaLeft;
// Receiving a file name
if PDFSaveDialog.Execute then
QuickPDF1.FileName := PDFSaveDialog.FileName
else exit;
// Loading pictures
LeftPicture := TPicture.Create();
LeftPicture.LoadFromFile(ExtractFilePath(Application.ExeName) +
'\logo-ems.jpg');
RightPicture := TPicture.Create();
RightPicture.LoadFromFile(ExtractFilePath(Application.ExeName) +
'\slogan.bmp');
// Defining the document padding
QuickPDF1.Document.MainTable.Padding.Left := 28;
QuickPDF1.Document.MainTable.Padding.Right := 28;
CreateFonts;
try
// Creating a document header
HeaderTable := TRenderTable.Create(
[(QuickPDF1.Document.Section[0].InternalWidth) div 2,
(QuickPDF1.Document.Section[0].InternalWidth) div 2]);
with HeaderTable do begin
Border := -1;
AddRow;
Cell[0, 0].AddItem(0, 0, TRenderImage.Create(LeftPicture.Graphic));
Cell[1, 0].AddText('', TextFont, rtaRight);
Cell[1, 0].AddTextItem(TRenderImage.Create(RightPicture.Graphic));
end;
QuickPDF1.Document.Header.Additem(0, 0, HeaderTable);
// Adding a bookmark to the document header
QuickPDF1.Document.Header.LinkName := 'Header';
QuickPDF1.Contents.Add('Header', 'Header');
i := 0;
Editor.Enabled := false;
Caret := Editor.CaretPos;
Attributes := TFont.Create();
AssignAttributes(Editor.SelAttributes, Attributes);
// Adding a bookmark to the beginning of the document
AParagraph := QuickPDF1.Document.Section[0].AddParagraph;
AParagraph.LinkName := 'doc';
QuickPDF1.Contents.Add('Main Text', 'doc');
while i < Length(Editor.Lines.Text) do begin
// Selecting a symbol
Editor.SelStart := i;
Editor.SelLength := 1;
if (Caret.y <> Editor.CaretPos.y) then begin
// Inserting a line break
Line := Line + #10;
Caret := Editor.CaretPos;
end;
// Comparing attributes of the selected symbol with attributes of
// the previous symbol
if (CompareAttributes(Attributes, Editor.SelAttributes) and
(Alignment = Editor.Paragraph.Alignment) and
(AParagraph.Indent = Editor.Paragraph.FirstIndent) and
(AParagraph.Padding.Left = Editor.Paragraph.LeftIndent) and
(AParagraph.Padding.Right = -Editor.Paragraph.RightIndent)) then
begin
Line := Line + Editor.SelText;
inc(i);
end
else begin
// Writing a text to the document
AParagraph.AddText(Line,Attributes,TextAlign);
Line := '';
// Comparing attributes of the current paragraph with attributes of
// the previous paragraph
if ((Alignment <> Editor.Paragraph.Alignment) or
(AParagraph.Indent <> Editor.Paragraph.FirstIndent) or
(AParagraph.Padding.Left <> Editor.Paragraph.LeftIndent) or
(AParagraph.Padding.Right <> -Editor.Paragraph.RightIndent)) then
begin
Alignment := Editor.Paragraph.Alignment;
// Adding a new paragraph with new attributes
AParagraph := QuickPDF1.Document.Section[0].AddParagraph;
with AParagraph do begin
Padding.Left := Editor.Paragraph.LeftIndent;
Padding.Right := -Editor.Paragraph.RightIndent;
Indent := Editor.Paragraph.FirstIndent;
end;
case Alignment of
taLeftJustify: TextAlign := rtaLeft;
taRightJustify: TextAlign :=rtaRight;
taCenter: TextAlign := rtaCenter;
end;
end;
if not CompareAttributes(Attributes, Editor.SelAttributes)
then AssignAttributes(Editor.SelAttributes, Attributes);
end;
end;
QuickPDF1.Document.Section[0].AddText(Line,Attributes,TextAlign);
// Adding a pricing information
AParagraph := QuickPDF1.Document.Section[0].AddParagraph;
AParagraph.LinkName := 'table';
QuickPDF1.Contents.Add('Pricing Information', 'table');
AParagraph.Padding.Left := 36;
AParagraph.AddText(#10'Pricing Information'#10#10, HeaderFont, rtaLeft);
AParagraph := QuickPDF1.Document.Section[0].AddParagraph;
PricingTable := TRenderTable.Create([
(QuickPDF1.Document.Section[0].InternalWidth) div 2,
(QuickPDF1.Document.Section[0].InternalWidth) div 4,
(QuickPDF1.Document.Section[0].InternalWidth) div 4]);
with PricingTable do begin
Padding := Rect(2, 2, 2, 2);
AddRow;
Rows[0].BgColor := clSilver;
Cell[0, 0].AddText('Product Description', TableHeaderFont, rtaLeft);
Cell[1, 0].AddText('Price', TableHeaderFont, rtaCenter);
Cell[0,1].AddText('EMS QuickPDF', TextFont, rtaLeft);
Cell[1,1].AddText('$195', TextFont, rtaCenter);
Cell[2,1].AddText('Register Now!', LinkFont, rtaCenter,
'http://www.ems-hitech.com/quickpdf/purchase.phtml');
end;
AParagraph.AddItem(0, 0, PricingTable);
// Adding the last paragraph of the document
AParagraph := QuickPDF1.Document.Section[0].AddParagraph;
AParagraph.AddText(#10+'You can also purchase EMS QuickPDF in a bundle '
+ 'along with several other our products and save a lot of your '
+ 'money!'#10#10, TextFont, rtaLeft);
AParagraph.AddText('For more information please visit our site at ',
TextFont, rtaLeft);
AParagraph.AddText('http://www.ems-hitech.com/quickpdf/'#10#10, LinkFont,
rtaLeft, 'http://www.ems-hitech.com/quickpdf/');
// Generating a document
QuickPDF1.GenerateToFile;
// Opening the result document
ShellExecute(0, 'open', PChar(QuickPDF1.FileName), '', '', SW_SHOWNORMAL);
finally
DestroyFonts;
Editor.Enabled := true;
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -