{
* This Source Code Form is subject to the terms of the Mozilla Public License,
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
* obtain one at http://mozilla.org/MPL/2.0/
*
* Copyright (C) 2007-2013, Peter Johnson (www.delphidabbler.com).
*
* $Rev$
* $Date$
*
* Provides interface and classes that can generate output suitable for printing
* using print engine.
}
unit UPrintDocuments;
interface
uses
// Delphi
Classes,
// Project
DB.UCategory,
DB.USnippet,
URTFUtils;
type
/// <summary>Interface supported by classes that can generate a print
/// document suitable for processing by the print engine.</summary>
/// <remarks>The print engine prints documents rendered in rich text format.
/// </remarks>
IPrintDocument = interface(IInterface)
['{56E4CA97-7F04-427A-A95F-03CE55910DC0}']
/// <summary>Generates and returns print document.</summary>
function Generate: TRTF;
end;
type
/// <summary>Class that generates a print document that describes a snippet.
/// </summary>
TSnippetPrintDocument = class(TInterfacedObject,
IPrintDocument
)
strict private
var
/// <summary>Reference to snippet described by print document.</summary>
fSnippet: TSnippet;
public
/// <summary>Constructs object to create print document for given snippet.
/// </summary>
constructor Create(const Snippet: TSnippet);
/// <summary>Generates and returns print document.</summary>
/// <remarks>Method of IPrintDocument.</remarks>
function Generate: TRTF;
end;
type
/// <summary>Class that generates a print document that describes a category.
/// </summary>
TCategoryPrintDocument = class(TInterfacedObject,
IPrintDocument
)
strict private
var
/// <summary>Reference to category described by print document.</summary>
fCategory: TCategory;
public
/// <summary>Constructs object to create print document for given category.
/// </summary>
constructor Create(const Category: TCategory);
/// <summary>Generates and returns print document.</summary>
/// <remarks>Method of IPrintDocument.</remarks>
function Generate: TRTF;
end;
implementation
uses
// Project
CS.Config,
CS.SourceCode.Languages,
CS.SourceCode.Hiliter.Brushes,
URTFCategoryDoc,
URTFSnippetDoc,
UPreferences,
UPrintInfo;
{ TSnippetPrintDocument }
constructor TSnippetPrintDocument.Create(const Snippet: TSnippet);
begin
inherited Create;
fSnippet := Snippet;
end;
function TSnippetPrintDocument.Generate: TRTF;
var
Doc: TRTFSnippetDoc; // object that renders snippet document in RTF
Language: TSourceCodeLanguage; // programming language used by snippet
Brush: TSyntaxHiliterBrush; // brush used to syntax highlight snippet
begin
Language := TConfig.Instance.SourceCodeLanguages[fSnippet.Language];
if (poSyntaxHilite in PrintInfo.PrintOptions) then
Brush := TSyntaxHiliterBrushes.CreateBrush(Language.HiliterBrushID)
else
Brush := TSyntaxHiliterBrushes.CreateNullBrush;
try
Doc := TRTFSnippetDoc.Create(
TConfig.Instance.HiliterThemes[
Preferences.CurrentHiliteThemeIds[htkPrint]
],
Brush,
poUseColour in PrintInfo.PrintOptions
);
try
Result := TRTF.Create(Doc.Generate(fSnippet));
finally
Doc.Free;
end;
finally
Brush.Free;
end;
end;
{ TCategoryPrintDocument }
constructor TCategoryPrintDocument.Create(const Category: TCategory);
begin
inherited Create;
fCategory := Category;
end;
function TCategoryPrintDocument.Generate: TRTF;
var
Doc: TRTFCategoryDoc; // object that renders category document in RTF
begin
Doc := TRTFCategoryDoc.Create(poUseColour in PrintInfo.PrintOptions);
try
Result := TRTF.Create(Doc.Generate(fCategory));
finally
Doc.Free;
end;
end;
end.