📄 updfgraphics.pas
字号:
{Draws an arrow.
~param Src the start point of the arrow
~param Dest the end point of the arrow
~param Arr1, Arr2 the end points of the arrow head
~param FilledArrowHead whether the arrow head should be filled
~param ThickLine whether the arrow should be painted thickly
~param LineStyle the style of the line, either psSolid, psDash or
psDashDot }
procedure TPDFDiagramDrawer.DrawArrow(Src, Dest, Arr1, Arr2: TPoint;
FilledArrowHead: Boolean;
ThickLine: Boolean;
LineStyle: TPenStyle);
begin
SetTextMode(False); //make sure not in text mode
if LineStyle <> psSolid then //if not a solid line, set the pattern
if LineStyle = psDash then
FWriter.DoLowLevelDrawingCommand('[' + PDFNumberToStr(2 * FImageScale) +
' ' + PDFNumberToStr(2 * FImageScale) +
'] 0 d')
else
FWriter.DoLowLevelDrawingCommand('[' + PDFNumberToStr(2 * FImageScale) +
' ' + PDFNumberToStr(2 * FImageScale) +
' ' + PDFNumberToStr(1 * FImageScale) +
' ' + PDFNumberToStr(2 * FImageScale) +
'] 0 d');
if ThickLine then
//set the width of lines to 2 (times the scaling factor)
FWriter.DoLowLevelDrawingCommand(PDFNumberToStr(2 * FImageScale) + ' w');
//draw the main line
//move to starting point
FWriter.DoLowLevelDrawingCommand(PDFNumberToStr(FOffset.x +
Src.x * FImageScale) + ' ' +
PDFNumberToStr(FOffset.y -
Src.y * FImageScale) + ' m');
//draw line to ending point
FWriter.DoLowLevelDrawingCommand(PDFNumberToStr(FOffset.x +
Dest.x * FImageScale) + ' ' +
PDFNumberToStr(FOffset.y -
Dest.y * FImageScale) + ' l');
FWriter.DoLowLevelDrawingCommand('S'); //and draw this line
if ThickLine then
//set the width of lines to 1 (times the scaling factor)
FWriter.DoLowLevelDrawingCommand(PDFNumberToStr(1 * FImageScale) + ' w');
if LineStyle <> psSolid then //not a solid line?
//make lines solid again
FWriter.DoLowLevelDrawingCommand('[] 0 d');
//make path for the two lines of the arrow head
//set command to draw the arrow head
//move to starting point
FWriter.DoLowLevelDrawingCommand(PDFNumberToStr(FOffset.x +
Arr1.x * FImageScale) + ' ' +
PDFNumberToStr(FOffset.y -
Arr1.y * FImageScale) + ' m');
//draw line to head of arrow
FWriter.DoLowLevelDrawingCommand(PDFNumberToStr(FOffset.x +
Dest.x * FImageScale) + ' ' +
PDFNumberToStr(FOffset.y -
Dest.y * FImageScale) + ' l');
//draw line to ending point
FWriter.DoLowLevelDrawingCommand(PDFNumberToStr(FOffset.x +
Arr2.x * FImageScale) + ' ' +
PDFNumberToStr(FOffset.y -
Arr2.y * FImageScale) + ' l');
if FilledArrowHead then //arrow head should be filled?
begin
FWriter.SetColor($D0D0D0); //set color for the arrow head
FWriter.DoLowLevelDrawingCommand('b'); //fill the arrow head
// FWriter.SetColor(clBlack); //reset the color
end
else
FWriter.DoLowLevelDrawingCommand('S'); //draw the two short lines
end;
{Draws the rectangle of a module and its name.
~param Left, Top, Right, Bottom the sides of the rectangle of the module
~param Rounding by how much the rectangle should be rounded
~param ModuleName the name of the module to be drawn
~param TextOffset the offset of the text from the upper left
corner
~param Monochrome whether the diagram is drawn monochrome }
procedure TPDFDiagramDrawer.DrawModule(Left, Top, Right, Bottom: Integer;
Rounding: Integer;
const ModuleName: String;
TextOffset: Integer;
Monochrome: Boolean);
begin
//modules are currently not shown in automatically created diagrams
Assert(False);
SetTextMode(False); //make sure not in text mode
FWriter.SetColor(clSilver);
FWriter.DoLowLevelDrawingCommand( //draw region of the module
GetPDFCommandRoundedRectanglePath(FOffset.x + Left * FImageScale,
FOffset.y - Top * FImageScale,
FOffset.x + Right * FImageScale,
FOffset.y - Bottom * FImageScale,
Rounding / 2, False));
FWriter.DoLowLevelDrawingCommand('b');
FWriter.SetColor(clBlack);
SetTextMode(True); //now enter text mode
FWriter.SetTextPoint(FOffset.x + (Left + TextOffset) * FImageScale,
FOffset.y - (Top + TextOffset) * FImageScale -
FBaseLineOffset);
FWriter.ShowText(ModuleName); //and show the name of the module
end;
{Draws a box of a file or class in the diagram.
~param Left, Top, Right, Bottom the sides of the rectangle of the box
~param Rounding by how much the rectangle should be rounded }
procedure TPDFDiagramDrawer.DrawBox(Left, Top, Right, Bottom: Integer;
Rounding: Integer);
begin
SetTextMode(False); //make sure not in text mode
FWriter.SetColor(clWhite);
FWriter.DoLowLevelDrawingCommand( //draw the box
GetPDFCommandRoundedRectanglePath(FOffset.x + Left * FImageScale,
FOffset.y - Top * FImageScale,
FOffset.x + Right * FImageScale,
FOffset.y - Bottom * FImageScale,
Rounding / 2, False));
FWriter.DoLowLevelDrawingCommand('b');
end;
{Draws selection markers at a box of a file or class in the diagram.
~param Left, Top, Right, Bottom the sides of the rectangle of the box
~param HalfSize the half size of the selection markers }
procedure TPDFDiagramDrawer.DrawBoxSelection(Left, Top, Right, Bottom: Integer;
HalfSize: Integer);
begin
Assert(False); //should never be drawn while exporting
end;
{Draws some text.
~param Top the vertical position where the text should be drawn
~param Left the horizontal position where the text should be drawn, or if
Center is true the left position where to center it in
~param Right only relevant if Center is true, the right position to center the
text in
~param Text the text to be drawn
~param Center whether the text should be centered between the left and right
margin, of not it is drawn at the left position
~param Style the font style to use, one or more of fsBold, fsItalic and
fsUnderline is possible
~param Color the color to draw the text in, clBlack is the default }
procedure TPDFDiagramDrawer.DrawText(Top, Left, Right: Integer;
const Text: String; Center: Boolean;
Style: TFontStyles; Color: TColor);
var Styles :TPDFFontStyles; //the PDF font style
Width :TPDFValue; //the width of the text
TextLeft :TPDFValue; //horizontal position of the text
begin
Styles := []; //set specified font (style) and color
if fsBold in Style then
Include(Styles, pfsBold);
if fsItalic in Style then
Include(Styles, pfsItalic);
FWriter.SetFont(FWriter.FontType, FWriter.Size, Styles);
FWriter.SetColor(Color);
Width := FWriter.TextWidth(Text); //get the width of the text
//calculate starting point of the text
if Center then
TextLeft := ((Right + Left) * FImageScale - Width) / 2
else
TextLeft := Left * FImageScale;
TextLeft := TextLeft + FOffset.x;
SetTextMode(True); //enter text mode
FWriter.SetTextPoint(TextLeft,
FOffset.y - Top * FImageScale - FBaseLineOffset);
FWriter.ShowText(Text); //and draw the text
if fsUnderline in Style then //if the text should be underlined
begin
SetTextMode(False); //exit the text mode again
if Color <> clBlack then //underline in same color as the text
FWriter.SetStrokeColor(Color);
//draw the line under the text
//move to starting point
FWriter.DoLowLevelDrawingCommand(PDFNumberToStr(TextLeft) + ' ' +
PDFNumberToStr(FOffset.y -
Top * FImageScale -
FWriter.Size) + ' m');
//draw line to ending point
FWriter.DoLowLevelDrawingCommand(PDFNumberToStr(TextLeft + Width) + ' ' +
PDFNumberToStr(FOffset.y -
Top * FImageScale -
FWriter.Size) + ' l');
FWriter.DoLowLevelDrawingCommand('S'); //and draw this line
if Color <> clBlack then //restore default color
FWriter.SetStrokeColor(clBlack);
end;
end;
{Draws a line.
~param Xs, Ys the starting point of the line
~param Xe, Ye the end point of the line }
procedure TPDFDiagramDrawer.DrawLine(Xs, Ys, Xe, Ye: Integer);
begin
SetTextMode(False); //exit the text mode
//draw the line under the text
//move to starting point
FWriter.DoLowLevelDrawingCommand(PDFNumberToStr(FOffset.x +
Xs * FImageScale) + ' ' +
PDFNumberToStr(FOffset.y -
Ys * FImageScale) + ' m');
//draw line to ending point
FWriter.DoLowLevelDrawingCommand(PDFNumberToStr(FOffset.x +
Xe * FImageScale) + ' ' +
PDFNumberToStr(FOffset.y -
Ye * FImageScale) + ' l');
FWriter.DoLowLevelDrawingCommand('S'); //and draw this line
end;
{Draws an icon representing a scope of a member of a record-like type.
~param X, Y the position where to draw the icon
~param Scope the scope, whose icon should be drawn }
procedure TPDFDiagramDrawer.DrawScopeIcon(X, Y: Integer; Scope: TScope);
begin
SetTextMode(False); //make sure not in text mode
FWriter.SetColor(clSilver);
FWriter.DoLowLevelDrawingCommand( //draw the rectangle around the character
GetPDFCommandRoundedRectanglePath(FOffset.x + X * FImageScale -
0.05 * FWriter.Size,
FOffset.y - Y * FImageScale +
0.05 * FWriter.Size,
FOffset.x + X * FImageScale +
0.95 * FWriter.Size,
FOffset.y - Y * FImageScale -
0.95 * FWriter.Size,
0.15 * FWriter.Size, False));
FWriter.DoLowLevelDrawingCommand('b');
FWriter.SetColor(clBlack);
SetTextMode(True); //now enter text mode
FWriter.SetFont(FWriter.FontType, FWriter.Size, [pfsBold]); //icons in bold
//draw the character inside
FWriter.SetTextPoint(FOffset.x + X * FImageScale + 0.1 * FWriter.Size,
FOffset.y - Y * FImageScale - 0.9 * FBaseLineOffset);
FWriter.ShowText(MemberScopeCharacters[Scope]);
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -