公式基准调整
This commit is contained in:
parent
600ce2e358
commit
5121a94b15
|
|
@ -135,6 +135,7 @@ private
|
|||
function FldSimple(fld_simple: fldSimple);
|
||||
function Hyperlink(hyperlink: Hyperlink);
|
||||
function OMathPara(o_math_para: OMathPara);
|
||||
function OMath(o_math: OMath);
|
||||
|
||||
private
|
||||
[weakref]docx_to_pdf_: TSDocxToPdf;
|
||||
|
|
@ -236,7 +237,7 @@ public
|
|||
function AdjustOffset(x: real; y: real);override;
|
||||
|
||||
public
|
||||
BaseY: real; // 基准Y值
|
||||
BaseHeight: real; // 基准高度
|
||||
|
||||
private
|
||||
[weakref]docx_to_pdf_: TSDocxToPdf;
|
||||
|
|
@ -254,8 +255,9 @@ public
|
|||
function SetMathSize();
|
||||
|
||||
public
|
||||
BaseY: real; // 基准Y值
|
||||
BaseHeight: real; // 基准高度
|
||||
BaseSz: real; // 基准字体大小
|
||||
SingleLine: boolean; // 是否单行公式
|
||||
|
||||
private
|
||||
[weakref]docx_to_pdf_: TSDocxToPdf;
|
||||
|
|
@ -272,7 +274,7 @@ public
|
|||
function AdjustOffset(x: real; y: real);overload;
|
||||
|
||||
public
|
||||
BaseY: real; // 基准Y值
|
||||
BaseHeight: real; // 基准高度
|
||||
BaseSz: real; // 基准字体大小
|
||||
|
||||
private
|
||||
|
|
@ -290,7 +292,7 @@ public
|
|||
function AdjustOffset(x: real; y: real);overload;
|
||||
|
||||
public
|
||||
BaseY: real; // 基准Y值
|
||||
BaseHeight: real; // 基准高度
|
||||
BaseSz: real; // 基准字体大小
|
||||
|
||||
private
|
||||
|
|
@ -308,7 +310,7 @@ public
|
|||
function AdjustOffset(x: real; y: real);overload;
|
||||
|
||||
public
|
||||
BaseY: real; // 基准Y值
|
||||
BaseHeight: real; // 基准高度
|
||||
BaseSz: real; // 基准字体大小
|
||||
|
||||
private
|
||||
|
|
@ -326,7 +328,7 @@ public
|
|||
function AdjustOffset(x: real; y: real);overload;
|
||||
|
||||
public
|
||||
BaseY: real; // 基准Y值
|
||||
BaseHeight: real; // 基准高度
|
||||
BaseSz: real; // 基准字体大小
|
||||
|
||||
private
|
||||
|
|
@ -344,7 +346,7 @@ public
|
|||
function AdjustOffset(x: real; y: real);overload;
|
||||
|
||||
public
|
||||
BaseY: real; // 基准Y值
|
||||
BaseHeight: real; // 基准高度
|
||||
BaseSz: real; // 基准字体大小
|
||||
|
||||
private
|
||||
|
|
@ -362,7 +364,7 @@ public
|
|||
function AdjustOffset(x: real; y: real);overload;
|
||||
|
||||
public
|
||||
BaseY: real; // 基准Y值
|
||||
BaseHeight: real; // 基准高度
|
||||
BaseSz: real; // 基准字体大小
|
||||
|
||||
private
|
||||
|
|
@ -380,7 +382,7 @@ public
|
|||
function AdjustOffset(x: real; y: real);overload;
|
||||
|
||||
public
|
||||
BaseY: real; // 基准Y值
|
||||
BaseHeight: real; // 基准高度
|
||||
BaseSz: real; // 基准字体大小
|
||||
|
||||
private
|
||||
|
|
@ -398,7 +400,7 @@ public
|
|||
function AdjustOffset(x: real; y: real);overload;
|
||||
|
||||
public
|
||||
BaseY: real; // 基准Y值
|
||||
BaseHeight: real; // 基准高度
|
||||
BaseSz: real; // 基准字体大小
|
||||
|
||||
private
|
||||
|
|
@ -634,7 +636,7 @@ begin
|
|||
y_offset := {self.}StartY - offset;
|
||||
for _,range in range_array_ do
|
||||
begin
|
||||
if range is class(OMathParaRange) then // 公式不是y值,需要处理公式
|
||||
if range is class(OMathRange) then // 公式不是y值,需要处理公式
|
||||
range.Offset(x, y, page);
|
||||
// range.Offset(0, 841.9, page);
|
||||
else
|
||||
|
|
@ -803,10 +805,7 @@ begin
|
|||
else if element.LocalName = "oMath" then
|
||||
begin
|
||||
// 公式嵌入段落
|
||||
o_math_para := new OMathPara();
|
||||
o_math_para.XmlChildOMath := element;
|
||||
// o_math_para.OMath.Copy(element);
|
||||
{self.}OMathPara(o_math_para);
|
||||
{self.}OMath(element);
|
||||
end
|
||||
end
|
||||
{self.}RangesToLines();
|
||||
|
|
@ -1078,10 +1077,23 @@ end;
|
|||
|
||||
function PRange.OMathPara(o_math_para: OMathPara);
|
||||
begin
|
||||
math_range := new OMathParaRange(docx_to_pdf_, o_math_para);
|
||||
math_range.Width := {self.}Width;
|
||||
math_para_range := new OMathParaRange(docx_to_pdf_, o_math_para);
|
||||
math_para_range.Width := 0;
|
||||
math_para_range.Parent := self;
|
||||
math_para_range.Calc();
|
||||
body_range_array_[length(body_range_array_)] := math_para_range;
|
||||
end;
|
||||
|
||||
function PRange.OMath(o_math: OMath);
|
||||
begin
|
||||
math_range := new OMathRange(docx_to_pdf_, o_math);
|
||||
math_range.Width := 0;
|
||||
math_range.Parent := self;
|
||||
math_range.XOffset := 0;
|
||||
math_range.YOffset := 0;
|
||||
math_range.SetMathSize();
|
||||
math_range.Calc();
|
||||
math_range.AdjustOffset(0, -math_range.DynamicHeight);
|
||||
body_range_array_[length(body_range_array_)] := math_range;
|
||||
end;
|
||||
|
||||
|
|
@ -1209,7 +1221,8 @@ begin
|
|||
if range is class(TextRange) and range.RPr.Sz.Val > pline_range.TextMaxSize then
|
||||
pline_range.TextMaxSize := range.RPr.Sz.Val;
|
||||
if range.DynamicHeight > pline_range.DynamicHeight then pline_range.DynamicHeight := range.DynamicHeight;
|
||||
range.XOffset := pline_range.XOffset;
|
||||
range.AdjustOffset(pline_range.XOffset, 0);
|
||||
// range.XOffset := pline_range.XOffset;
|
||||
range.Parent := pline_range;
|
||||
pline_range.AddRange(range);
|
||||
pline_range.XOffset += range.Width;
|
||||
|
|
@ -2285,6 +2298,7 @@ begin
|
|||
o_math_range_.Parent := self;
|
||||
o_math_range_.XOffset := 0;
|
||||
o_math_range_.YOffset := 0;
|
||||
o_math_range_.SingleLine := true;
|
||||
o_math_range_.SetMathSize();
|
||||
o_math_range_.Calc();
|
||||
o_math_range_.AdjustOffset(0, -o_math_range_.DynamicHeight);
|
||||
|
|
@ -2295,7 +2309,7 @@ end;
|
|||
function OMathParaRange.AdjustOffset(x: real; y: real);override;
|
||||
begin
|
||||
class(BasicRange).AdjustOffset(x, y);
|
||||
o_math_para_.AdjustOffset(x, y);
|
||||
o_math_range_.AdjustOffset(x, y);
|
||||
end;
|
||||
|
||||
function OMathRange.Create(docx_to_pdf: TSDocxToPdf; element: OpenXmlElement);
|
||||
|
|
@ -2303,8 +2317,9 @@ begin
|
|||
class(AdvancedRange).Create();
|
||||
docx_to_pdf_ := docx_to_pdf;
|
||||
element_ := element;
|
||||
{self.}BaseY := 0;
|
||||
{self.}BaseHeight := 0;
|
||||
{self.}BaseSz := 0;
|
||||
{self.}SingleLine := false;
|
||||
end;
|
||||
|
||||
function OMathRange.Do();override;
|
||||
|
|
@ -2333,6 +2348,7 @@ begin
|
|||
x := {self.}XOffset;
|
||||
y := {self.}YOffset;
|
||||
elements := element_.Elements();
|
||||
up_h := 0;
|
||||
for _,element in elements do
|
||||
begin
|
||||
range := nil;
|
||||
|
|
@ -2344,7 +2360,7 @@ begin
|
|||
else if element.LocalName = "f" then
|
||||
begin
|
||||
range := new OMathFRange(docx_to_pdf_, element);
|
||||
range.BaseSz := {self.}BaseSz;
|
||||
range.BaseSz := {self.}SingleLine ? {self.}BaseSz : 0.7 * {self.}BaseSz;
|
||||
end
|
||||
else if element.LocalName = "rad" then
|
||||
begin
|
||||
|
|
@ -2389,15 +2405,18 @@ begin
|
|||
x += range.Width; // 下一个元素偏移位置
|
||||
{self.}Width += range.Width;
|
||||
|
||||
if {self.}DynamicHeight < range.DynamicHeight then
|
||||
{self.}DynamicHeight := range.DynamicHeight;
|
||||
if range.BaseHeight > {self.}BaseHeight then
|
||||
{self.}BaseHeight := range.BaseHeight;
|
||||
if range.DynamicHeight - range.BaseHeight > up_h then
|
||||
up_h := range.DynamicHeight - range.BaseHeight;
|
||||
// if range.DynamicHeight > {self.}DynamicHeight then
|
||||
// {self.}DynamicHeight := range.DynamicHeight;
|
||||
|
||||
range_array_[length(range_array_)] := range;
|
||||
end
|
||||
{self.}DynamicHeight := {self.}BaseHeight + up_h;
|
||||
for _,range in range_array_ do
|
||||
begin
|
||||
h := ({self.}DynamicHeight - range.DynamicHeight) / 2;
|
||||
range.AdjustOffset(0, h);
|
||||
end
|
||||
range.AdjustOffset(0, {self.}BaseHeight - range.BaseHeight);
|
||||
end;
|
||||
|
||||
function OMathRange.SetMathSize();
|
||||
|
|
@ -2445,8 +2464,7 @@ end;
|
|||
|
||||
function OMathFRange.Calc();override;
|
||||
begin
|
||||
bar_margin := {self.}BaseSz * 0.1;
|
||||
x := {self.}XOffset + bar_margin;
|
||||
x := {self.}XOffset;
|
||||
y := {self.}YOffset;
|
||||
|
||||
// 分子分母单独计算高度,最后再合并
|
||||
|
|
@ -2464,7 +2482,7 @@ begin
|
|||
num_range.YOffset := y;
|
||||
num_range.Calc(); // 需要得到高宽
|
||||
|
||||
max_len := max(den_range.Width, num_range.Width) + 2*bar_margin;
|
||||
max_len := max(den_range.Width, num_range.Width);
|
||||
|
||||
xo := (max_len - num_range.Width) / 2;
|
||||
num_range.AdjustOffset(xo, den_range.DynamicHeight + 0.3 * {self.}BaseSz);
|
||||
|
|
@ -2479,9 +2497,12 @@ begin
|
|||
line_range.LineWidth := 0.04 * {self.}BaseSz;
|
||||
|
||||
{self.}DynamicHeight := num_range.DynamicHeight + den_range.DynamicHeight + 0.3 * {self.}BaseSz;
|
||||
{self.}Width := line_range.Width + bar_margin;
|
||||
{self.}Width := line_range.Width;
|
||||
|
||||
range_array_ union= array(den_range, num_range, line_range);
|
||||
|
||||
// 分式的基准在line处
|
||||
{self.}BaseHeight := den_range.DynamicHeight;
|
||||
end;
|
||||
|
||||
function OMathFRange.AdjustOffset(x: real; y: real);override;
|
||||
|
|
@ -2613,6 +2634,7 @@ begin
|
|||
range_array_[length(range_array_)] := text_range;
|
||||
{self.}Width += text_range.Width;
|
||||
end
|
||||
{self.}BaseHeight := {self.}BaseSz / 4;
|
||||
end;
|
||||
|
||||
function OMathNaryRange.Create(docx_to_pdf: TSDocxToPdf; nary: Nary);
|
||||
|
|
@ -2670,13 +2692,13 @@ begin
|
|||
symbol_range.DynamicHeight := size;
|
||||
|
||||
sub_range := new OMathRange(docx_to_pdf_, nary_.Sub);
|
||||
sub_range.BaseSz := {self.}BaseSz * 0.5;
|
||||
sub_range.BaseSz := {self.}BaseSz / 2;
|
||||
sub_range.XOffset := x;
|
||||
sub_range.YOffset := y;
|
||||
sub_range.Calc();
|
||||
|
||||
sup_range := new OMathRange(docx_to_pdf_, nary_.Sup);
|
||||
sup_range.BaseSz := {self.}BaseSz * 0.5;
|
||||
sup_range.BaseSz := {self.}BaseSz / 2;
|
||||
sup_range.XOffset := x;
|
||||
sup_range.YOffset := y;
|
||||
sup_range.Calc(); // 需要得到高宽
|
||||
|
|
@ -2709,6 +2731,7 @@ begin
|
|||
|
||||
{self.}Width += e_range.Width;
|
||||
{self.}DynamicHeight := max({self.}DynamicHeight, e_range.DynamicHeight);
|
||||
{self.}BaseHeight := symbol_range.DynamicHeight / 4 + sub_range.DynamicHeight;
|
||||
end;
|
||||
|
||||
function OMathRadRange.Create(docx_to_pdf: TSDocxToPdf; rad: Rad);
|
||||
|
|
@ -2740,11 +2763,11 @@ end;
|
|||
|
||||
function OMathRadRange.Calc();override;
|
||||
begin
|
||||
x := {self.}XOffset + 0.2*{self.}BaseSz;
|
||||
x := {self.}XOffset;
|
||||
y := {self.}YOffset;
|
||||
|
||||
deg_range := new OMathRange(docx_to_pdf_, rad_.Deg);
|
||||
deg_range.BaseSz := {self.}BaseSz * 0.5;
|
||||
deg_range.BaseSz := {self.}BaseSz / 2;
|
||||
deg_range.XOffset := x;
|
||||
deg_range.YOffset := y;
|
||||
deg_range.Calc();
|
||||
|
|
@ -2771,7 +2794,7 @@ begin
|
|||
symbol_range.RPr.Sz.Val := size;
|
||||
symbol_range.DynamicHeight := size;
|
||||
|
||||
deg_range.AdjustOffset(0, -e_range.DynamicHeight * 0.5);
|
||||
deg_range.AdjustOffset(0, -e_range.DynamicHeight / 2);
|
||||
symbol_range.AdjustOffset(deg_range.Width, 0);
|
||||
e_range.AdjustOffset(size*0.3 + deg_range.Width, 0);
|
||||
|
||||
|
|
@ -2785,6 +2808,8 @@ begin
|
|||
|
||||
{self.}Width := deg_range.Width + symbol_range.Width + e_range.Width + 0.3*size;
|
||||
{self.}DynamicHeight := symbol_range.DynamicHeight;
|
||||
|
||||
{self.}BaseHeight := symbol_range.DynamicHeight / 2;
|
||||
end;
|
||||
|
||||
function OMathSSupRange.Create(docx_to_pdf: TSDocxToPdf; s_sup: SSup);
|
||||
|
|
@ -2816,7 +2841,7 @@ end;
|
|||
|
||||
function OMathSSupRange.Calc();override;
|
||||
begin
|
||||
x := {self.}XOffset + 0.2*{self.}BaseSz;
|
||||
x := {self.}XOffset;
|
||||
y := {self.}YOffset;
|
||||
|
||||
e_range := new OMathRange(docx_to_pdf_, s_sup_.E);
|
||||
|
|
@ -2830,13 +2855,14 @@ begin
|
|||
sup_range.XOffset := x;
|
||||
sup_range.YOffset := y;
|
||||
sup_range.Calc();
|
||||
sup_range.AdjustOffset(e_range.Width, e_range.DynamicHeight * 0.5);
|
||||
sup_range.AdjustOffset(e_range.Width, e_range.DynamicHeight / 2);
|
||||
|
||||
range_array_ union= array(e_range, sup_range);
|
||||
|
||||
{self.}Width := e_range.Width + sup_range.Width;
|
||||
h := sup_range.DynamicHeight + e_range.DynamicHeight * 0.5;
|
||||
h := sup_range.DynamicHeight + e_range.DynamicHeight / 2;
|
||||
{self.}DynamicHeight := max(h, e_range.DynamicHeight);
|
||||
{self.}BaseHeight := e_range.BaseHeight;
|
||||
end;
|
||||
|
||||
function OMathSSubRange.Create(docx_to_pdf: TSDocxToPdf; s_sub: SSub);
|
||||
|
|
@ -2889,6 +2915,7 @@ begin
|
|||
{self.}Width += e_range.Width + sub_range.Width;
|
||||
h := e_range.DynamicHeight + sub_range.DynamicHeight - {self.}BaseSz * 0.4;
|
||||
{self.}DynamicHeight := max(h, e_range.DynamicHeight);
|
||||
{self.}BaseHeight := e_range.BaseHeight;
|
||||
end;
|
||||
|
||||
function OMathDRange.Create(docx_to_pdf: TSDocxToPdf; d: D);
|
||||
|
|
@ -2966,6 +2993,7 @@ begin
|
|||
range_array_ union= array(beg_range, e_range, end_range);
|
||||
{self.}Width := beg_range.Width + e_range.Width + end_range.Width;
|
||||
{self.}DynamicHeight := max_h;
|
||||
{self.}BaseHeight := {self.}DynamicHeight / 2;
|
||||
end;
|
||||
|
||||
function OMathFuncRange.Create(docx_to_pdf: TSDocxToPdf; func: Func);
|
||||
|
|
@ -3021,6 +3049,7 @@ begin
|
|||
|
||||
{self.}Width += f_name_range.Width + e_range.Width;
|
||||
{self.}DynamicHeight := max(f_name_range.DynamicHeight, e_range.DynamicHeight);
|
||||
{self.}BaseHeight := f_name_range.BaseHeight;
|
||||
end;
|
||||
|
||||
end.
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue