📄 uvectorgraphics.pas
字号:
{$IFNDEF LINUX}
{Creates the object and the meta file object.
~param FileName the name of the file the diagram should be saved as }
constructor TEMFFormatHandler.Create(const FileName: String);
begin
inherited Create(FileName); //create the object
FMetafile := TMetafile.Create; //create Windows Meta File object
FMetafile.Width := 200; //set a default size (will be adjusted)
FMetafile.Height := 200;
end;
{Frees the object and the meta file object. }
destructor TEMFFormatHandler.Destroy;
begin
FMetafile.Free; //free Windows Meta File object
inherited Destroy; //and this object
end;
{Called before ~[link GetTextExtent] is called to allow the set-up for the
measurement. GetTextExtent may be called several times. }
procedure TEMFFormatHandler.PrepareTextMeasuring;
begin
//create a (dummy) canvas to determine the text size
FCanvas := TMetaFileCanvas.Create(FMetafile, 0);
FCanvas.Font.Name := 'Verdana';
end;
{Measures the size of a text in the diagram in the format.
~param Text the text whose size should be measured
~result the size of the text }
function TEMFFormatHandler.GetTextExtent(const Text: String): TSize;
begin
Result := FCanvas.TextExtent(Text); //get the text size from the canvas
end;
{Called after ~[link GetTextExtent] has been called (multiple times) to
allow the tear down after the measurement. }
procedure TEMFFormatHandler.EndTextMeasuring;
begin
FCanvas.Free; //free canvas again
end;
{Called before the actual image is being drawn.
~param ImageWidth, ImageHeight the dimensions of the image of the diagram
~param ImageTitle the title of the diagram and image }
procedure TEMFFormatHandler.InitImageObjects(ImageWidth, ImageHeight: Integer;
const ImageTitle: String);
begin
//create a Window Meta File canvas with the correct size
FMetafile.Width := ImageWidth;
FMetafile.Height := ImageHeight;
FCanvas := TMetaFileCanvas.CreateWithComment(FMetafile, 0,
'JADD - Just Another DelphiDoc',
ImageTitle);
FCanvas.Font.Name := 'Verdana';
end;
{Called after the actual image has been drawn. }
procedure TEMFFormatHandler.FinalizeImageObjects;
begin
FCanvas.Free; //free the canvas
FMetafile.SaveToFile(FFileName); //save this figure to the file
end;
{Draws a text and a rectangle behind it.
~param Text the text to be written in a box
~param X,Y the position to draw it at
~param BoxSize the size of the rectangle behind the text }
procedure TEMFFormatHandler.DrawBoxedText(const Text: String;
X, Y: Integer; BoxSize: TSize);
begin
FCanvas.Brush.Color := clWhite; //white background for the names
EMFDrawBoxedString(FCanvas, Text, X, Y, BoxSize); //draw a box with the text
end;
{Draws an arrow.
~param Src the starting point of the arrow
~param Dest the ending point of the arrow
~param Arr1, Arr2 the positions of both sides of the head of the arrow
~param BoldArrow whether the arrow should be "bold", the head filled }
procedure TEMFFormatHandler.DrawArrow(Src, Dest, Arr1, Arr2: TPoint;
BoldArrow: Boolean);
begin
FCanvas.Brush.Color := clBlack; //fill arrowheads (with black)
EMFDrawArrow(FCanvas, Src, Dest, Arr1, Arr2, BoldArrow); //draw the arrow
end;
{Draws a line.
~param Xs, Ys starting position of the line
~param Xe, Ye end point of the line }
procedure TEMFFormatHandler.DrawLine(Xs, Ys, Xe, Ye: Integer);
begin
EMFDrawLine(FCanvas, Xs, Ys, Xe, Ye); //just draw the line
end;
{$ENDIF}
{Creates the object, opens the SVG file and saves whether it can contain links.
~param FileName the name of the file the diagram should be saved as
~param CanContainLinks whether the image can (will) contain links }
constructor TSVGFormatHandler.Create(const FileName: String;
CanContainLinks: Boolean);
begin
inherited Create(FileName); //create the object
FCanContainLinks := CanContainLinks; //save parameter
FSVGFile := TBufferStream.CreateFile(FileName); //create the SVG file
end;
{Closes the SVG file and frees the object. }
destructor TSVGFormatHandler.Destroy;
begin
FSVGFile.Free; //close the SVG file and free the stream
inherited Destroy; //and this object
end;
{Sets the link target for the next box to be drawn. Should only be called once
for each box, if not called or with an empty string no link will be generated
on the box.
~param Target the target the box should link to }
procedure TSVGFormatHandler.SetNextTextBoxesLinkTarget(const Target: String);
begin
FNextLinkTarget := Target; //just save the link target
end;
{Called before ~[link GetTextExtent] is called to allow the set-up for the
measurement. GetTextExtent may be called several times. }
procedure TSVGFormatHandler.PrepareTextMeasuring;
begin
//create a (dummy) canvas to determine the text size
FMeasureBMP := TBitmap.Create;
FMeasureBMP.Canvas.Font.Name := SVGFontName; //use a "scalable" TrueType font
FMeasureBMP.Canvas.Font.Size := SVGFontSize;
end;
{Measures the size of a text in the diagram in the format.
~param Text the text whose size should be measured
~result the size of the text }
function TSVGFormatHandler.GetTextExtent(const Text: String): TSize;
begin
//get the text size from the canvas
Result := FMeasureBMP.Canvas.TextExtent(Text);
Inc(Result.cx, Result.cx div 5); //but we need some extra space
Inc(Result.cy, Result.cy div 5);
// Result.cx := 250 - 10; //or use a constant size?
// Result.cy := 2 * SVGFontSize - 10;
end;
{Called after ~[link GetTextExtent] has been called (multiple times) to
allow the tear down after the measurement. }
procedure TSVGFormatHandler.EndTextMeasuring;
begin
FMeasureBMP.Free; //free canvas used to measure
end;
{Called before the actual image is being drawn.
~param ImageWidth, ImageHeight the dimensions of the image of the diagram
~param ImageTitle the title of the diagram and image }
procedure TSVGFormatHandler.InitImageObjects(ImageWidth, ImageHeight: Integer;
const ImageTitle: String);
begin
//start the SVG file
SVGStartFile(FSVGFile, ImageTitle, ImageWidth, ImageHeight, FCanContainLinks);
end;
{Called after the actual image is being drawn. It is ensured that this
method will be called after a call to ~[link InitImageObjects]. }
procedure TSVGFormatHandler.FinalizeImageObjects;
begin
SVGEndFile(FSVGFile); //end the SVG file
end;
{Draws a text and a rectangle behind it.
~param Text the text to be written in a box
~param X,Y the position to draw it at
~param BoxSize the size of the rectangle behind the text }
procedure TSVGFormatHandler.DrawBoxedText(const Text: String; X, Y: Integer;
BoxSize: TSize);
begin
//just draw the box, the text, and create a link around it if specified
SVGDrawBoxedString(FSVGFile, Text, X, Y, BoxSize, FNextLinkTarget);
FNextLinkTarget := ''; //link has been used, so clear it now
end;
{Draws an arrow.
~param Src the starting point of the arrow
~param Dest the ending point of the arrow
~param Arr1, Arr2 the positions of both sides of the head of the arrow
~param BoldArrow whether the arrow should be "bold", the head filled }
procedure TSVGFormatHandler.DrawArrow(Src, Dest, Arr1, Arr2: TPoint;
BoldArrow: Boolean);
begin //just draw the arrow
SVGDrawArrow(FSVGFile, Src, Dest, Arr1, Arr2, BoldArrow);
end;
{Draws a line.
~param Xs, Ys starting position of the line
~param Xe, Ye end point of the line }
procedure TSVGFormatHandler.DrawLine(Xs, Ys, Xe, Ye: Integer);
begin
SVGDrawLine(FSVGFile, Xs, Ys, Xe, Ye); //just draw the line
end;
{Writes an EMF file of all files and their dependance among each other.
~param FFiles the list of files to be drawn
~param FileName the name of the file the EMF should be saved as }
procedure WriteFileEMF(FFiles: TFileList; const FileName: String);
begin
{$IFNDEF LINUX}
if not FFiles.IsEmpty then //list not empty?
//create the drawer of the diagram and specify a handler to draw it as EMF
with TVectorFileDrawer.Create(FFiles, TEMFFormatHandler.Create(FileName),
nil) do
try
DrawFile; //draw the diagram of the files
finally
Free; //free the drawer object
end;
{$ENDIF}
end;
{Writes an SVG file of all files and their dependance among each other.
~param FFiles the list of files to be drawn
~param FileName the name of the file the SVG should be saved as
~param URLCallBack if not nil, determines the URL to link each file to }
procedure WriteFileSVG(FFiles: TFileList; const FileName: String;
URLCallBack: TGetFileURLCallBack);
begin
if not FFiles.IsEmpty then //list not empty?
//create the drawer of the diagram and specify a handler to draw it as SVG
with TVectorFileDrawer.Create(FFiles,
TSVGFormatHandler.Create(FileName,
Assigned(URLCallBack)),
URLCallBack) do
try
DrawFile; //draw the diagram of the files
finally
Free; //free the drawer object
end;
end;
{Writes an EMF file of all classes of that kind and their inheritance from
each other.
TopLevelClasses is a list classes with no parent or that are unknown. It is
the root of all classes. The string contains the name of the class, the object
contains either a ~[link TIdentifierList] of all inheriting classes if the
class is unknown, or the identifier (of class ~[link TIdentifier]) of the
class.
~param TopLevelClasses the list of classes with no parent or that are unknown
~param FileName the name of the file to save the diagram to }
procedure WriteClassesEMFTree(TopLevelClasses: TStrings;
const FileName: String);
begin
{$IFNDEF LINUX}
if TopLevelClasses.Count <> 0 then //list not empty?
//create the drawer of the diagram and specify a handler to draw it as EMF
with TVectorClassDrawer.Create(TopLevelClasses,
TEMFFormatHandler.Create(FileName), nil) do
try
DrawFile; //draw the diagram of the classes
finally
Free; //free the drawer object
end;
{$ENDIF}
end;
{Writes an SVG file of all classes of that kind and their inheritance from
each other.
TopLevelClasses is a list classes with no parent or that are unknown. It is
the root of all classes. The string contains the name of the class, the object
contains either a ~[link TIdentifierList] of all inheriting classes if the
class is unknown, or the identifier (of class ~[link TIdentifier]) of the
class.
~param TopLevelClasses the list of classes with no parent or that are unknown
~param FileName the name of the file to save the diagram to
~param URLCallBack method pointer to get the target of links for each
class }
procedure WriteClassesSVGTree(TopLevelClasses: TStrings;
const FileName: String;
URLCallBack: TGetClassURLCallBack);
begin
if TopLevelClasses.Count <> 0 then //list not empty?
//create the drawer of the diagram and specify a handler to draw it as SVG
with TVectorClassDrawer.Create(TopLevelClasses,
TSVGFormatHandler.Create(FileName,
Assigned(URLCallBack)),
URLCallBack) do
try
DrawFile; //draw
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -