PdfConverter/utils/TSParagraphWare.tsf

109 lines
2.2 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

type TSParagraphWare = class
public
function Create(components, styles, paragraph);
function Do();
function GetWords();
property Paragraph read ReadParagraph;
function ReadParagraph();
private
function SetPPr(ppr);
function SetRPr(rpr, ppr);
function SetRPrByStyleId(rpr, style_id);
function SetPPrByStyleId(ppr, style_id);
private
docx_components_;
styles_;
paragraph_;
words_;
end;
function TSParagraphWare.Create(components, styles, paragraph);
begin
docx_components_ := components;
styles_ := styles;
paragraph_ := paragraph;
words_ := array();
end;
function TSParagraphWare.Do();
begin
self.SetPPr(paragraph_.PPr); // styleid与ppr样式合并
rs := paragraph_.Rs();
for i:=0 to length(rs)-1 do
begin
r := rs[i];
self.SetRPr(r.RPr, paragraph_.PPr); // rpr样式与ppr与styleid样式合并
rpr := new RPrUnitDecorator(r.RPr);
pos := 1;
text := r.T.Text;
while pos <= length(text) do
begin
c := text[pos];
pos ++;
if ord(c) > 127 then
begin
c := text[pos-1 : pos+1];
pos += 2;
end
words_[length(words_)] := array(utf8ToAnsi(c), rpr);
end
end
paragraph_.PPr := new PPrUnitDecorator(paragraph_.PPr);
end;
function TSParagraphWare.SetPPrByStyleId(ppr, style_id);
begin
style := styles_.StyleId(style_id);
if ifObj(style) then
begin
based_on := style.BasedOn.Val;
self.SetPPrByStyleId(ppr, based_on);
ppr.Copy(style.PPr);
ppr.Rpr.Copy(style.RPr);
end
end;
function TSParagraphWare.SetPPr(ppr);
begin
new_ppr := new PPr();
style_id := ppr.PStyle.Val;
self.SetPPrByStyleId(new_ppr, style_id);
new_ppr.Copy(ppr);
ppr.Copy(new_ppr);
end;
function TSParagraphWare.SetRPrByStyleId(rpr, style_id);
begin
style := styles_.StyleId(style_id);
if ifObj(style) then
begin
based_on := style.BasedOn.Val;
self.SetRPrByStyleId(rpr, based_on);
rpr.Copy(style.RPr);
end
end;
function TSParagraphWare.SetRPr(rpr, ppr);
begin
// rpr先继承ppr再继承样式最后继承自己
new_rpr := new RPr();
style_id := rpr.RStyle.Val;
new_rpr.Copy(ppr.RPr);
self.SetRPrByStyleId(new_rpr, style_id);
new_rpr.Copy(rpr);
rpr.Copy(new_rpr);
end;
function TSParagraphWare.GetWords();
begin
return words_;
end;
function TSParagraphWare.ReadParagraph();
begin
return paragraph_;
end