TurboPower_iPro: Remove occasional empty line at top of document. Fix horizontal text alignment in table cells.

git-svn-id: trunk@50145 -
This commit is contained in:
wp 2015-10-22 20:37:40 +00:00
parent 9eae75a03b
commit bb0313a2d6
2 changed files with 104 additions and 4 deletions

View File

@ -228,6 +228,9 @@ type
{ TIpHtmlBaseLayouter }
TIpHtmlNodeIterator = procedure (ANode: TIpHtmlNode; AProps: TIpHtmlProps;
var Done: Boolean);
// Abstract base class for the HTML Layout engine
TIpHtmlBaseLayouter = class
protected
@ -236,6 +239,8 @@ type
FCurProps : TIpHtmlProps;
FBlockMin, FBlockMax : Integer;
function GetProps: TIpHtmlProps;
procedure RemoveLeadingLFs;
procedure RemoveDuplicateLFs;
public
FPageRect : TRect;
constructor Create(AOwner: TIpHtmlNodeCore); virtual;
@ -246,6 +251,7 @@ type
procedure CalcMinMaxPropWidth(RenderProps: TIpHtmlProps;
var aMin, aMax: Integer); virtual; abstract;
procedure Render(RenderProps: TIpHtmlProps); virtual; abstract;
procedure IterateParents(AProc: TIpHtmlNodeIterator);
public
property Props : TIpHtmlProps read GetProps;
end;
@ -3577,6 +3583,52 @@ begin
Result := FOwner.Props;
end;
procedure TIpHtmlBaseLayouter.IterateParents(AProc: TIpHtmlNodeIterator);
var
p: TIpHtmlNode;
done: Boolean;
begin
p := FOwner; //.FParentNode;
done := false;
while Assigned(p) do
begin
AProc(p, Props, done);
if done then
break
else
p := p.FParentNode;
end;
end;
procedure TIpHtmlBaseLayouter.RemoveLeadingLFs;
begin
while PIpHtmlElement(FElementQueue[0])^.ElementType in [etSoftLF, etHardLF] do
FElementQueue.Delete(0);
end;
procedure TIpHtmlBaseLayouter.RemoveDuplicateLFs;
var
i: Integer;
begin
i := pred(FElementQueue.Count);
while i >= 0 do begin
case PIpHtmlElement(FElementQueue[i])^.ElementType of
etSoftLF:
if (i > 0) and (PIpHtmlElement(FElementQueue[i-1])^.ElementType in [etSoftLF, etHardLF])
then FElementQueue.Delete(i);
{
etHardLF:
if (i > 0) and (PIpHtmlElement(FElementQueue[i-1])^.ElementType in [etSoftLF, etHardLF])
then begin
FElementQueue.Delete(i-1);
dec(i);
end;
}
end;
dec(i);
end;
end;
{ TIpHtmlBaseTableLayouter }
constructor TIpHtmlBaseTableLayouter.Create(AOwner: TIpHtmlNodeCore);
@ -7583,7 +7635,7 @@ end;
function TIpHtml.ParseCellAlign(Default : TIpHtmlAlign): TIpHtmlAlign;
begin
Result := GetAlignmentForStr(FindAttribute(htmlAttrALIGN), haCenter);
Result := GetAlignmentForStr(FindAttribute(htmlAttrALIGN), Default);
// if FlagErrors then
// ReportError(SHtmlInvAlign);
end;
@ -9183,7 +9235,9 @@ begin
EnqueueElement(Owner.HardLF);
end;
end;
inherited Enqueue;
if FChildren.Count > 0 then begin
if not (FParentNode is TIpHtmlNodeTD) then begin
EnqueueElement(Owner.SoftLF);
@ -10157,6 +10211,7 @@ begin
end;
}
EnqueueElement(Owner.SoftLF);
EnqueueElement(Owner.HardLF);
EnqueueElement(Element);
@ -11037,8 +11092,10 @@ begin
if FChildren.Count > 0 then
EnqueueElement(Owner.HardLF);
inherited Enqueue;
{
if FChildren.Count > 0 then
EnqueueElement(Owner.HardLF);
}
end;
{ TIpHtmlNodeBLOCKQUOTE }
@ -15627,7 +15684,6 @@ begin
FElementName := 'td';
end;
{ TIpHtmlNodeCAPTION }
constructor TIpHtmlNodeCAPTION.Create(ParentNode: TIpHtmlNode);

View File

@ -183,7 +183,13 @@ end;
procedure TIpNodeBlockLayouter.Layout(RenderProps: TIpHtmlProps; TargetRect: TRect);
begin
if EqualRect(TargetRect, FBlockOwner.PageRect) then Exit;
if EqualRect(TargetRect, FBlockOwner.PageRect) then
exit;
if FBlockOwner is TIpHtmlNodeBody then
RemoveLeadingLFs;
RemoveDuplicateLFs;
if not RenderProps.IsEqualTo(Props) then
begin
Props.Assign(RenderProps);
@ -505,7 +511,7 @@ begin
FBlockDescent := PropA.tmDescent;
end;
if (FCurProps = nil) or not BIsEqualTo(FCurProps) then begin
FAl := Alignment;
FAl := self.Props.Alignment; // was: FAl := Alignment
FVAL := VAlignment;
FBaseOffset := FontBaseline;
aPrefor := Preformatted;
@ -1358,25 +1364,63 @@ begin
inherited Destroy;
end;
procedure GetAlignment(ANode: TIpHtmlNode; AProps: TIpHtmlProps; var Done: Boolean);
begin
if (ANode is TIpHtmlNodeSpan) then
begin
if (ANode as TIpHtmlNodeSpan).Align <> haDefault then
begin
AProps.Alignment := (ANode as TIpHtmlNodeSpan).Align;
Done := true;
end;
end else
if (ANode is TIpHtmlNodeTableHeaderOrCell) then
begin
if (ANode as TIpHtmlNodeTableHeaderOrCell).Align <> haDefault then
begin
AProps.Alignment := (ANode as TIpHtmlNodeTableHeaderOrCell).Align;
Done := true;
end;
end;
end;
procedure TIpNodeTableElemLayouter.Layout(RenderProps: TIpHtmlProps; TargetRect: TRect);
begin
Props.Assign(RenderProps);
IterateParents(@GetAlignment);
if (Props.Alignment = haDefault) then
begin
if (FOwner is TIpHtmlNodeTD) then
Props.Alignment := haLeft
else
if (FOwner is TIpHtmlNodeTH) then
Props.Alignment := haCenter;
end;
{
if FTableElemOwner.Align <> haDefault then
Props.Alignment := FTableElemOwner.Align
else
if FOwner is TIpHtmlNodeTH then
Props.Alignment := haCenter;
}
if FOwner is TIpHtmlNodeTH then
Props.FontStyle := Props.FontStyle + [fsBold];
if FTableElemOwner.NoWrap then
Props.NoBreak := True;
case FTableElemOwner.VAlign of
hva3Default :;
else
Props.VAlignment := FTableElemOwner.VAlign;
end;
if FTableElemOwner.BgColor <> -1 then
Props.BgColor := FTableElemOwner.BgColor;
inherited Layout(Props, TargetRect);
end;