1. 重构部分表格代码
2. 支持表格的边框样式`single`和`dashed` 3. 遇到不支持的项目符号采用数字代替
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
type TSPdfBordersRange = class(TSPdfBasicRange)
|
||||
uses TSColorToolKit;
|
||||
public
|
||||
function Create();
|
||||
function Do();override;
|
||||
public
|
||||
TcPr: TcPr;
|
||||
Left: boolean;
|
||||
Top: boolean;
|
||||
Right: boolean;
|
||||
Bottom: boolean;
|
||||
|
||||
private
|
||||
function SetDash(val: string);
|
||||
function DrawLine(border: Border; x1: real; y1: real; x2: real; y2: real);
|
||||
end;
|
||||
|
||||
function TSPdfBordersRange.Create();
|
||||
begin
|
||||
class(TSPdfBasicRange).Create();
|
||||
{self.}TcPr := nil;
|
||||
{self.}Left := false;
|
||||
{self.}Top := false;
|
||||
{self.}Right := false;
|
||||
{self.}Bottom := false;
|
||||
end;
|
||||
|
||||
function TSPdfBordersRange.Do();override;
|
||||
begin
|
||||
// println("Left = {}, Top = {}, Right = {}, Bottom = {}, Tl2Br = {}, Tr2Bl = {}", Left, Top, Right, Bottom, Tl2Br, Tr2Bl);
|
||||
if {self.}TcPr.Shd.Fill then
|
||||
begin
|
||||
[r, g, b] := array(0, 0, 0);
|
||||
if {self.}TcPr.Shd.Fill <> "auto" then [r, g, b] := TSColorToolKit.HexToRGB({self.}TcPr.Shd.Fill);
|
||||
{self.}TSPage.PdfPage.SetRGBFill(r/255, g/255, b/255);
|
||||
{self.}TSPage.PdfPage.Rectangle({self.}EndX, {self.}EndY - {self.}DynamicHeight, {self.}Width, {self.}DynamicHeight);
|
||||
{self.}TSPage.PdfPage.Fill();
|
||||
{self.}TSPage.PdfPage.SetRGBFill(0, 0, 0);
|
||||
{self.}Left := true;
|
||||
end
|
||||
borders := {self.}TcPr.TcBorders;
|
||||
if {self.}Left then
|
||||
{self.}DrawLine(borders.Left, {self.}EndX, {self.}EndY, {self.}EndX, {self.}EndY - {self.}DynamicHeight);
|
||||
if {self.}Top then
|
||||
{self.}DrawLine(borders.Top, {self.}EndX, {self.}EndY, {self.}EndX + {self.}Width, {self.}EndY);
|
||||
if {self.}Right then
|
||||
{self.}DrawLine(borders.Right, {self.}EndX + {self.}Width, {self.}EndY, {self.}EndX + {self.}Width, {self.}EndY - {self.}DynamicHeight);
|
||||
if {self.}Bottom then
|
||||
{self.}DrawLine(borders.Bottom, {self.}EndX, {self.}EndY - {Self.}DynamicHeight, {self.}EndX + {self.}Width, {self.}EndY - {self.}DynamicHeight);
|
||||
if borders.Tl2Br then
|
||||
{self.}DrawLine(borders.Tl2Br, {self.}EndX, {self.}Y, {self.}EndX + {self.}Width, {self.}EndY - {self.}DynamicHeight);
|
||||
if borders.Tr2Bl then
|
||||
{self.}DrawLine(borders.Tr2Bl, {self.}EndX + {self.}Width, {self.}Y, {self.}EndX, {self.}EndY - {self.}DynamicHeight);
|
||||
end;
|
||||
|
||||
function TSPdfBordersRange.SetDash(val: string);
|
||||
begin
|
||||
if val = "single" or ifnil(val) then
|
||||
{self.}TSPage.PdfPage.SetDash(array(), 0, 0);
|
||||
if val = "dashed" then
|
||||
{self.}TSPage.PdfPage.SetDash(array(1), 1, 0);
|
||||
end;
|
||||
|
||||
function TSPdfBordersRange.DrawLine(border: Border; x1: real; y1: real; x2: real; y2: real);
|
||||
begin
|
||||
[r, g, b] := array(0, 0, 0);
|
||||
line_width := border.Sz ?: 0.5;
|
||||
{self.}SetDash(border.Val);
|
||||
if border.Color and border.Color <> "auto" then [r, g, b] := TSColorToolKit.HexToRGB(border.Color);
|
||||
{self.}TSPage.PdfPage.SetRGBStroke(r, g, b);
|
||||
{self.}TSPage.PdfPage.SetLineWidth(line_width);
|
||||
{self.}TSPage.PdfPage.MoveTo(x1, y1);
|
||||
{self.}TSPage.PdfPage.LineTo(x2, y2);
|
||||
{self.}TSPage.PdfPage.Stroke();
|
||||
{self.}TSPage.PdfPage.SetRGBStroke(0, 0, 0);
|
||||
end;
|
||||
@@ -1,33 +0,0 @@
|
||||
type TSPdfRectangleRange = class(TSPdfBasicRange)
|
||||
uses TSColorToolKit;
|
||||
public
|
||||
function Create();
|
||||
function Do();override;
|
||||
public
|
||||
TcPr: TcPr;
|
||||
end;
|
||||
|
||||
function TSPdfRectangleRange.Create();
|
||||
begin
|
||||
class(TSPdfBasicRange).Create();
|
||||
end;
|
||||
|
||||
function TSPdfRectangleRange.Do();override;
|
||||
begin
|
||||
// {self.}Page.SetRGBStroke(1.0, 0.0, 0.0);
|
||||
// println("page = {}, endx = {}, endy = {}, DynamicHeight = {}, Width = {}", {self.}Page, {self.}EndX, {self.}EndY, {self.}DynamicHeight, {self.}Width);
|
||||
if {self.}TcPr.Shd.Fill then
|
||||
begin
|
||||
[r, g, b] := array(0, 0, 0);
|
||||
if {self.}TcPr.Shd.Fill <> "auto" then [r, g, b] := TSColorToolKit.HexToRGB({self.}TcPr.Shd.Fill);
|
||||
{self.}TSPage.PdfPage.SetRGBFill(r/255, g/255, b/255);
|
||||
{self.}TSPage.PdfPage.Rectangle({self.}EndX, {self.}EndY - {self.}DynamicHeight, {self.}Width, {self.}DynamicHeight);
|
||||
{self.}TSPage.PdfPage.Fill();
|
||||
{self.}TSPage.PdfPage.SetRGBFill(0, 0, 0);
|
||||
end
|
||||
{self.}TSPage.PdfPage.SetGrayStroke(0.5);
|
||||
{self.}TSPage.PdfPage.SetLineWidth(0.25);
|
||||
{self.}TSPage.PdfPage.Rectangle({self.}EndX, {self.}EndY - {self.}DynamicHeight, {self.}Width, {self.}DynamicHeight);
|
||||
{self.}TSPage.PdfPage.Stroke();
|
||||
{self.}TSPage.PdfPage.SetGrayStroke(0);
|
||||
end;
|
||||
Reference in New Issue
Block a user