抽象page为tspage对象,增加索引
This commit is contained in:
parent
d3f9431b26
commit
cfc2d74ab8
|
|
@ -5,12 +5,11 @@ public
|
|||
function SaveToFile(alias: string; file: string): integer;
|
||||
function Transform();
|
||||
|
||||
function GetCurrentPage(): PdfPage;
|
||||
function GetCurrentPoint(): Point;
|
||||
function GetCachePath(image_path: string): string;
|
||||
function GetPdf(): PdfFile;
|
||||
function GetNextPage(page: PdfPage): PdfPage;
|
||||
function AddPage(sect_ware: TSSectWare): PdfPage;
|
||||
function GetNextPage(page: TSPage): TSPage;
|
||||
function AddPage(sect_ware: TSSectWare): TSPage;
|
||||
|
||||
property Font read ReadFont;
|
||||
function ReadFont();
|
||||
|
|
@ -35,10 +34,9 @@ private
|
|||
cache_path_: string; // 临时目录,用来存放临时文件
|
||||
sect_ware_array_: array of TSSectWare; // 页面布局组件数组
|
||||
font_ware_: TSFontWare; // 字体部件
|
||||
current_page_: PdfPage;
|
||||
current_page_: TSPage;
|
||||
point_: TSPoint; // 定位坐标点
|
||||
page_array_: array of PdfPage;
|
||||
page_index_: tableArray;
|
||||
page_array_: array of TSPage;
|
||||
end;
|
||||
|
||||
function TSDocxToPdf.Create(alias: string; file: string);
|
||||
|
|
@ -84,11 +82,6 @@ begin
|
|||
end
|
||||
end;
|
||||
|
||||
function TSDocxToPdf.GetCurrentPage(): PdfPage;
|
||||
begin
|
||||
return current_page_;
|
||||
end;
|
||||
|
||||
function TSDocxToPdf.GetCurrentPoint(): Point;
|
||||
begin
|
||||
return point_;
|
||||
|
|
@ -171,27 +164,28 @@ begin
|
|||
// println("sect_ware_array_ = {}", sect_ware_array_);
|
||||
end;
|
||||
|
||||
function TSDocxToPdf.AddPage(sect_ware: TSSectWare): PdfPage;
|
||||
function TSDocxToPdf.AddPage(sect_ware: TSSectWare): TSPage;
|
||||
begin
|
||||
current_page_ := pdf_.AddPage();
|
||||
current_page_.SetWidth(sect_ware.SectPr.PgSz.W);
|
||||
current_page_.SetHeight(sect_ware.SectPr.PgSz.H);
|
||||
page := pdf_.AddPage();
|
||||
page.SetWidth(sect_ware.SectPr.PgSz.W);
|
||||
page.SetHeight(sect_ware.SectPr.PgSz.H);
|
||||
{self.}ResetCoordinates(sect_ware);
|
||||
|
||||
len := length(page_array_);
|
||||
current_page_ := new TSPage();
|
||||
current_page_.Index := len;
|
||||
current_page_.PdfPage := page;
|
||||
page_array_[len] := current_page_;
|
||||
page_index_[current_page_] := len;
|
||||
|
||||
if sysparams["_PDF_PAGE_GRID_DEBUG_"] then
|
||||
{self.}PrintGrid(current_page_, sect_ware);
|
||||
{self.}PrintGrid(page, sect_ware);
|
||||
|
||||
return current_page_;
|
||||
end;
|
||||
|
||||
function TSDocxToPdf.GetNextPage(page: PdfPage);
|
||||
function TSDocxToPdf.GetNextPage(page: TSPage);
|
||||
begin
|
||||
pos := page_index_[page];
|
||||
return page_array_[pos + 1];
|
||||
return page_array_[page.Index + 1];
|
||||
end;
|
||||
|
||||
function TSDocxToPdf.ResetCoordinates(sect_ware: TSSectWare);
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
type TSPdfCellRange = class(TSPdfBasicRange)
|
||||
public
|
||||
function Create(docx_to_pdf: TSDocxToPdf; pg: PdfPage; components: TSDocxComponentsWare; sect_ware: TSSectWare; tc: Tc; tbl_pr: TblPr);
|
||||
function Create(docx_to_pdf: TSDocxToPdf; pg: TSPage; components: TSDocxComponentsWare; sect_ware: TSSectWare; tc: Tc; tbl_pr: TblPr);
|
||||
function Calc();
|
||||
function AlignHeight(height: real; surplus: real);
|
||||
function GetLastPage();
|
||||
|
|
@ -8,7 +8,7 @@ public
|
|||
|
||||
private
|
||||
[weakref]docx_to_pdf_: TSDocxToPdf;
|
||||
page_: PdfPage;
|
||||
[weakref]page_: TSPage;
|
||||
[weakref]docx_components_ware_: TSDocxComponentsWare;
|
||||
[weakref]sect_ware_: TSSectWare;
|
||||
[weakref]tc_: Tc;
|
||||
|
|
@ -27,7 +27,7 @@ type Region = class
|
|||
RangeArr: array of TSPdfAbstractRange;
|
||||
end;
|
||||
|
||||
function TSPdfCellRange.Create(docx_to_pdf: TSDocxToPdf; pg: PdfPage; components: TSDocxComponentsWare; sect_ware: TSSectWare; tc: Tc; tbl_pr: TblPr);
|
||||
function TSPdfCellRange.Create(docx_to_pdf: TSDocxToPdf; pg: TSPage; components: TSDocxComponentsWare; sect_ware: TSSectWare; tc: Tc; tbl_pr: TblPr);
|
||||
begin
|
||||
docx_to_pdf_ := docx_to_pdf;
|
||||
page_ := pg;
|
||||
|
|
@ -36,7 +36,7 @@ begin
|
|||
tc_ := tc;
|
||||
tbl_pr_ := tbl_pr;
|
||||
region_array_ := array();
|
||||
{self.}Page := page_;
|
||||
{self.}TSPage := page_;
|
||||
end;
|
||||
|
||||
function TSPdfCellRange.Calc();
|
||||
|
|
@ -46,7 +46,7 @@ begin
|
|||
region.RectangleRange.EndY := {self.}StartY;
|
||||
region.RectangleRange.Width := {self.}Width;
|
||||
region.RectangleRange.FixedHeight := {self.}FixedHeight;
|
||||
region.RectangleRange.Page := page_;
|
||||
region.RectangleRange.TSPage := page_;
|
||||
region_array_[length(region_array_)] := region;
|
||||
|
||||
{self.}EndX := {self.}StartX;
|
||||
|
|
@ -108,7 +108,7 @@ begin
|
|||
arr := region.RangeArr;
|
||||
region.RangeArr := array();
|
||||
span := sect_ware_.SectPr.PgSz.H - sect_ware_.SectPr.PgMar.Top - sect_ware_.SectPr.PgMar.Bottom;
|
||||
hash := array(region.RectangleRange.Page: region);
|
||||
hash := array(region.RectangleRange.TSPage.Index: region);
|
||||
while surplus > span do
|
||||
begin
|
||||
page_ := docx_to_pdf_.GetNextPage(page_);
|
||||
|
|
@ -117,10 +117,10 @@ begin
|
|||
region.RectangleRange.EndY := {self.}StartY;
|
||||
region.RectangleRange.Width := {self.}Width;
|
||||
region.RectangleRange.DynamicHeight := span;
|
||||
region.RectangleRange.Page := page_;
|
||||
region.RectangleRange.TSPage := page_;
|
||||
region_array_[length(region_array_)] := region;
|
||||
surplus -= span;
|
||||
hash[region.RectangleRange.Page] := region;
|
||||
hash[region.RectangleRange.TSPage.Index] := region;
|
||||
end
|
||||
if surplus > 1e-6 then
|
||||
begin
|
||||
|
|
@ -130,14 +130,14 @@ begin
|
|||
region.RectangleRange.EndY := sect_ware_.SectPr.PgSz.H - sect_ware_.SectPr.PgMar.Top;
|
||||
region.RectangleRange.Width := {self.}Width;
|
||||
region.RectangleRange.DynamicHeight := surplus;
|
||||
region.RectangleRange.Page := page_;
|
||||
region.RectangleRange.TSPage := page_;
|
||||
region_array_[length(region_array_)] := region;
|
||||
hash[region.RectangleRange.Page] := region;
|
||||
hash[region.RectangleRange.TSPage.Index] := region;
|
||||
{self.}EndY := region.RectangleRange.EndY - surplus;
|
||||
end
|
||||
for _,range in arr do
|
||||
begin
|
||||
region := hash[range.Page];
|
||||
region := hash[range.TSPage.Index];
|
||||
region.RangeArr[length(region.RangeArr)] := range;
|
||||
end
|
||||
end;
|
||||
|
|
|
|||
|
|
@ -1,18 +1,18 @@
|
|||
type TSPdfLineRange = class(TSPdfBasicRange)
|
||||
public
|
||||
function Create(pg: PdfPage);
|
||||
function Create(pg: TSPage);
|
||||
function Do();override;
|
||||
function AddRange(range: TSPdfBasicRange);
|
||||
function SetAllRangeProp(pg: PdfPage; sx: real; sy: real; ex: real; ey: real; w: real; fh: real; dh: real);
|
||||
function SetAllRangeProp(pg: TSPage; sx: real; sy: real; ex: real; ey: real; w: real; fh: real; dh: real);
|
||||
function Align(jc: string);
|
||||
|
||||
private
|
||||
range_array_: array of TSPdfBasicRange;
|
||||
end;
|
||||
|
||||
function TSPdfLineRange.Create(pg: PdfPage);
|
||||
function TSPdfLineRange.Create(pg: TSPage);
|
||||
begin
|
||||
{self.}Page := pg;
|
||||
{self.}TSPage := pg;
|
||||
range_array_ := array();
|
||||
end;
|
||||
|
||||
|
|
@ -27,11 +27,11 @@ begin
|
|||
range.Do();
|
||||
end;
|
||||
|
||||
function TSPdfLineRange.SetAllRangeProp(pg: PdfPage; sx: real; sy: real; ex: real; ey: real; w: real; fh: real; dh: real);
|
||||
function TSPdfLineRange.SetAllRangeProp(pg: TSPage; sx: real; sy: real; ex: real; ey: real; w: real; fh: real; dh: real);
|
||||
begin
|
||||
for _,range in range_array_ do
|
||||
begin
|
||||
if not ifnil(pg) then range.Page := pg;
|
||||
if not ifnil(pg) then range.TSPage := pg;
|
||||
if not ifnil(sx) then range.StartX := sx;
|
||||
if not ifnil(sy) then range.StartY := sy;
|
||||
if not ifnil(ex) then range.EndX := ex;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
type TSPdfParagraphRange = class(TSPdfBasicRange)
|
||||
public
|
||||
function Create(docx_to_pdf: TSDocxToPdf; pg: PdfPage; components: TSDocxComponentsWare; sect_ware: TSSectWare; paragraph: P);
|
||||
function Create(docx_to_pdf: TSDocxToPdf; pg: TSPage; components: TSDocxComponentsWare; sect_ware: TSSectWare; paragraph: P);
|
||||
function Calc();
|
||||
function Do();override;
|
||||
function SetExtraStyleId(style_id: string);
|
||||
|
|
@ -28,13 +28,13 @@ private
|
|||
[weakref]docx_components_ware_: TSDocxComponentsWare;
|
||||
[weakref]sect_ware_: TSSectWare;
|
||||
[weakref]paragraph_: P;
|
||||
page_: PdfPage;
|
||||
[weakref]page_: TSPage;
|
||||
extra_style_id_: string;
|
||||
range_array_: array of TSPdfBasicRange;
|
||||
line_range_array_: array of TSPdfLineRange;
|
||||
end;
|
||||
|
||||
function TSPdfParagraphRange.Create(docx_to_pdf: TSDocxToPdf; pg: PdfPage; components: TSDocxComponentsWare; sect_ware: TSSectWare; paragraph: P);
|
||||
function TSPdfParagraphRange.Create(docx_to_pdf: TSDocxToPdf; pg: TSPage; components: TSDocxComponentsWare; sect_ware: TSSectWare; paragraph: P);
|
||||
begin
|
||||
docx_to_pdf_ := docx_to_pdf;
|
||||
page_ := pg;
|
||||
|
|
@ -44,7 +44,7 @@ begin
|
|||
extra_style_id_ := "";
|
||||
range_array_ := array();
|
||||
line_range_array_ := array();
|
||||
{self.}Page := page_;
|
||||
{self.}TSPage := page_;
|
||||
end;
|
||||
|
||||
function TSPdfParagraphRange.Calc(): tableArray;
|
||||
|
|
@ -130,7 +130,7 @@ begin
|
|||
begin
|
||||
offset := line_space > max_y ? (line_space - max_size) / 2 + max_size - max_size / 5 : max_y;
|
||||
max_value := max(line_space, max_y);
|
||||
line_range.Page := page_;
|
||||
line_range.TSPage := page_;
|
||||
line_range.EndY := {self.}EndY - max_value;
|
||||
line_range.DynamicHeight := max_value;
|
||||
line_range.SetAllRangeProp(pg: page_, ey: {self.}EndY - offset);
|
||||
|
|
@ -155,7 +155,7 @@ begin
|
|||
begin
|
||||
offset := line_space > max_y ? (line_space - max_size) / 2 + max_size - max_size / 5 : max_y;
|
||||
max_value := max(line_space, max_y) + ppr.Spacing.After;
|
||||
line_range.Page := page_;
|
||||
line_range.TSPage := page_;
|
||||
line_range.EndY := {self.}EndY - max_value;
|
||||
line_range.DynamicHeight := max_value;
|
||||
line_range.SetAllRangeProp(pg: page_, ey: {self.}EndY - offset);
|
||||
|
|
@ -219,8 +219,9 @@ begin
|
|||
font_name := rpr.RFonts.EastAsia ? rpr.RFonts.EastAsia : rpr.RFonts.Ascii;
|
||||
font_obj := docx_to_pdf_.Font.GetFont(font_name, rpr.B, rpr.I);
|
||||
if not rpr.Sz.Val then rpr.Sz.Val := rpr.SzCs.Val ? rpr.SzCs.Val : docx_to_pdf_.Font.GetDefaultSz();
|
||||
page_.SetFontAndSize(font_obj, rpr.Sz.Val);
|
||||
word_width := page_.TextWidth(word);
|
||||
// println("page_.PdfPage = {}, font_obj = {}, sz = {}", page_.PdfPage, font_obj, rpr.Sz.Val);
|
||||
page_.PdfPage.SetFontAndSize(font_obj, rpr.Sz.Val);
|
||||
word_width := page_.PdfPage.TextWidth(word);
|
||||
text_range := new TSPdfTextRange();
|
||||
text_range.RPr := rpr;
|
||||
text_range.Text := word;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
type TSPdfTableRange = class(TSPdfBasicRange)
|
||||
public
|
||||
function Create(docx_to_pdf: TSDocxToPdf; pg: PdfPage; components: Components; sect_ware: TSSectWare; paragraph: P);
|
||||
function Create(docx_to_pdf: TSDocxToPdf; pg: TSPage; components: Components; sect_ware: TSSectWare; paragraph: P);
|
||||
function Calc();
|
||||
function Do();override;
|
||||
|
||||
|
|
@ -20,7 +20,7 @@ private
|
|||
[weakref]docx_components_ware_: Components;
|
||||
[weakref]sect_ware_: TSSectWare;
|
||||
[weakref]table_: Tbl;
|
||||
page_: PdfPage;
|
||||
[weakref]page_: TSPage;
|
||||
[weakref]range_array_: tableArray;
|
||||
point_: TSPoint;
|
||||
end;
|
||||
|
|
@ -33,7 +33,7 @@ begin
|
|||
sect_ware_ := sect_ware;
|
||||
table_ := table;
|
||||
range_array_ := array();
|
||||
{self.}Page := page_;
|
||||
{self.}TSPage := page_;
|
||||
end;
|
||||
|
||||
function TSPdfTableRange.Calc();
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ public
|
|||
Width: real;
|
||||
FixedHeight: real;
|
||||
DynamicHeight: real;
|
||||
Page: PdfPage;
|
||||
[weakref]TSPage: TSPage;
|
||||
end;
|
||||
|
||||
function TSPdfBasicRange.Create();
|
||||
|
|
@ -23,5 +23,5 @@ begin
|
|||
{self.}Width := 0;
|
||||
{self.}FixedHeight := 0;
|
||||
{self.}DynamicHeight := 0;
|
||||
{self.}Page := nil;
|
||||
{self.}TSPage := nil;
|
||||
end;
|
||||
|
|
|
|||
|
|
@ -16,13 +16,13 @@ end;
|
|||
function TSPdfImageRange.Do();
|
||||
begin
|
||||
// println("image = {}, x = {}, y = {}, w = {}, h = {}", {self.}image, {self.}endx, {self.}endy, {self.}width, {self.}DynamicHeight);
|
||||
{self.}Page.DrawImage({self.}Image, {self.}EndX, {self.}EndY, {self.}Width, {self.}DynamicHeight);
|
||||
{self.}TSPage.PdfPage.DrawImage({self.}Image, {self.}EndX, {self.}EndY, {self.}Width, {self.}DynamicHeight);
|
||||
|
||||
if sysparams["_PDF_IMAGE_DEBUG_"] then
|
||||
begin
|
||||
{self.}Page.SetLineWidth(0.1);
|
||||
{self.}Page.SetRGBStroke(0.8, 0.8, 0);
|
||||
{self.}Page.Rectangle({self.}EndX, {self.}EndY, {self.}Width, {self.}DynamicHeight);
|
||||
{self.}Page.Stroke();
|
||||
{self.}TSPage.PdfPage.SetLineWidth(0.1);
|
||||
{self.}TSPage.PdfPage.SetRGBStroke(0.8, 0.8, 0);
|
||||
{self.}TSPage.PdfPage.Rectangle({self.}EndX, {self.}EndY, {self.}Width, {self.}DynamicHeight);
|
||||
{self.}TSPage.PdfPage.Stroke();
|
||||
end
|
||||
end;
|
||||
|
|
|
|||
|
|
@ -14,9 +14,9 @@ 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);
|
||||
{self.}Page.SetGrayStroke(0.5);
|
||||
{self.}Page.SetLineWidth(0.5);
|
||||
{self.}Page.Rectangle({self.}EndX, {self.}EndY - {self.}DynamicHeight, {self.}Width, {self.}DynamicHeight);
|
||||
{self.}Page.Stroke();
|
||||
{self.}Page.SetGrayStroke(0);
|
||||
{self.}TSPage.PdfPage.SetGrayStroke(0.5);
|
||||
{self.}TSPage.PdfPage.SetLineWidth(0.5);
|
||||
{self.}TSPage.PdfPage.Rectangle({self.}EndX, {self.}EndY - {self.}DynamicHeight, {self.}Width, {self.}DynamicHeight);
|
||||
{self.}TSPage.PdfPage.Stroke();
|
||||
{self.}TSPage.PdfPage.SetGrayStroke(0);
|
||||
end;
|
||||
|
|
|
|||
|
|
@ -23,21 +23,21 @@ begin
|
|||
// println("text = {}, endx = {}, endy = {}, width = {}, page = {}", ansiToUtf8(text), endx, endy, width, page);
|
||||
[r, g, b] := array(0, 0, 0);
|
||||
if {self.}RPr.Color.Val then [r, g, b] := TSColorToolKit.HexToRGB({self.}RPr.Color.Val);
|
||||
{self.}Page.SetRGBFill(r / 255, g / 255, b / 255);
|
||||
{self.}Page.SetFontAndSize({self.}Font, {self.}RPr.Sz.Val);
|
||||
{self.}Page.BeginText();
|
||||
{self.}Page.TextOut({self.}EndX, {self.}EndY, {self.}Text);
|
||||
{self.}Page.EndText();
|
||||
{self.}Page.SetRGBFill(0, 0, 0);
|
||||
{self.}TSPage.PdfPage.SetRGBFill(r / 255, g / 255, b / 255);
|
||||
{self.}TSPage.PdfPage.SetFontAndSize({self.}Font, {self.}RPr.Sz.Val);
|
||||
{self.}TSPage.PdfPage.BeginText();
|
||||
{self.}TSPage.PdfPage.TextOut({self.}EndX, {self.}EndY, {self.}Text);
|
||||
{self.}TSPage.PdfPage.EndText();
|
||||
{self.}TSPage.PdfPage.SetRGBFill(0, 0, 0);
|
||||
|
||||
|
||||
if sysparams["_PDF_TEXT_DEBUG_"] then
|
||||
begin
|
||||
{self.}Page.SetLineWidth(0.1);
|
||||
{self.}Page.SetRGBStroke(1.0, 0.5, 0.0);
|
||||
{self.}Page.MoveTo(0, {self.}EndY);
|
||||
{self.}Page.LineTo(600, {self.}EndY);
|
||||
{self.}Page.Stroke();
|
||||
{self.}TSPage.PdfPage.SetLineWidth(0.1);
|
||||
{self.}TSPage.PdfPage.SetRGBStroke(1.0, 0.5, 0.0);
|
||||
{self.}TSPage.PdfPage.MoveTo(0, {self.}EndY);
|
||||
{self.}TSPage.PdfPage.LineTo(600, {self.}EndY);
|
||||
{self.}TSPage.PdfPage.Stroke();
|
||||
end
|
||||
end;
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,5 @@
|
|||
type TSPage = class
|
||||
public
|
||||
PdfPage;
|
||||
Index;
|
||||
end;
|
||||
Loading…
Reference in New Issue