📄 rvrtfprops.pas
字号:
c1, c2: TColor;
begin
inc(info.CellCount);
Cell.Color := Props.Color;
if RowProps.RichViewSpecial then
Cell.BestHeight := Props.BestHeight
else if RowProps.HeightTw>0 then
Cell.BestHeight := Round(RowProps.HeightTw*PixelsPerTwip);
for side := Low(TRVRTFSide) to High(TRVRTFSide) do begin
if Props.Border.Sides[side].BorderType<>rtf_brdr_None then begin
inc(info.CellBorderCount);
inc(info.CellBorderWidthTw, Props.Border.Sides[side].WidthTw);
end;
end;
Cell.VisibleBorders.Left := Props.Border.Sides[rtf_side_Left].BorderType<>rtf_brdr_None;
Cell.VisibleBorders.Top := Props.Border.Sides[rtf_side_Top].BorderType<>rtf_brdr_None;
Cell.VisibleBorders.Right := Props.Border.Sides[rtf_side_Right].BorderType<>rtf_brdr_None;
Cell.VisibleBorders.Bottom := Props.Border.Sides[rtf_side_Bottom].BorderType<>rtf_brdr_None;
GetBorderColors(Props.Border,c1,c2);
Cell.BorderColor := c1;
Cell.BorderLightColor := c2;
info.CellFlatBorder := info.CellFlatBorder and ((c1=c2) or (c1=clNone) or (c2=clNone));
if RowProps.RichViewSpecial then
Cell.BestWidth := Props.BestWidth
else begin
info.Word2000 := info.Word2000 or (Props.BestWidth<>0);
if not info.Word2000 then begin
w := info.HRules[RuleIndex2]-info.HRules[RuleIndex1];
Cell.BestWidth := Round(w*PixelsPerTwip)
end
else
if Props.BestWidth>0 then begin
w := Props.BestWidth;
Cell.BestWidth := Round(w*PixelsPerTwip)
end
else
Cell.BestWidth := Props.BestWidth div 50;
end;
case Props.VAlign of
rtf_val_Top:
Cell.VAlign := rvcTop;
rtf_val_Bottom:
Cell.VAlign := rvcBottom;
rtf_val_Center:
Cell.VAlign := rvcMiddle;
end;
end;
{............................................................}
procedure HideBorders(Row,Col: Integer);
var Cell: TRVTableCellData;
begin
Cell := info.table.Cells[Row,Col];
if Cell<>nil then begin
Cell.VisibleBorders.SetAll(False);
Cell.Clear;
Cell.AddNL('',GetEmptyStyleNo,GetEmptyParaNo(rvaLeft));
end;
end;
{............................................................}
begin
info := TTableInfo(Tables[Tables.Count-1]);
info.table.InsertRows(info.table.Rows.Count,1,-1);
if info.table.Rows[0].Count<info.lastrow.Rows[0].Count then begin
c := info.table.Rows[0].Count;
span := info.lastrow.Rows[0].Count-info.table.Rows[0].Count+1;
info.table.InsertCols(c,span,-1);
if CurrentRow>1 then begin
info.table.MergeCells(0,c,span,info.table.Rows.Count,True);
HideBorders(0,c);
end;
end;
RowProps := Reader.RTFState.RowProps;
if RowProps.Heading then
info.table.HeadingRowCount := info.table.Rows.Count;
//assigning table attributes
if RowProps.UseSpacing[rtf_side_Top] then
if CurrentRow=0 then
info.VBorderSpacing1Tw := RowProps.SpacingTw[rtf_side_Top]
else
inc(info.VSpacingTw, RowProps.SpacingTw[rtf_side_Top]);
inc(info.VSpacingTw, info.VBorderSpacing2Tw);
info.UseHSpacing := info.UseHSpacing or RowProps.UseSpacing[rtf_side_Left] or
RowProps.UseSpacing[rtf_side_Right];
info.UseVSpacing := info.UseVSpacing or RowProps.UseSpacing[rtf_side_Top] or
RowProps.UseSpacing[rtf_side_Bottom];
if RowProps.UseSpacing[rtf_side_Bottom] then
info.VBorderSpacing2Tw := RowProps.SpacingTw[rtf_side_Bottom];
if RowProps.UseSpacing[rtf_side_Left] then
inc(info.HSpacingTw, RowProps.SpacingTw[rtf_side_Left])
else begin
inc(info.HSpacingTw, RowProps.GapHTw);
if RowProps.UsePadding[rtf_side_Left] then
dec(info.HSpacingTw, RowProps.PaddingTw[rtf_side_Left]);
end;
if RowProps.UseSpacing[rtf_side_Right] then
inc(info.HSpacingTw, RowProps.SpacingTw[rtf_side_Right])
else begin
inc(info.HSpacingTw, RowProps.GapHTw);
if RowProps.UsePadding[rtf_side_Right] then
dec(info.HSpacingTw, RowProps.PaddingTw[rtf_side_Right]);
end;
for side := Low(TRVRTFSide) to High(TRVRTFSide) do begin
if RowProps.Border.Sides[side].BorderType<>rtf_brdr_None then begin
inc(info.BorderWidthTw, RowProps.Border.Sides[side].WidthTw);
inc(info.BorderCount);
end;
if RowProps.UsePadding[side] then
inc(info.CellPaddingTw, RowProps.PaddingTw[side]);
inc(info.CellPaddingCount);
end;
if RowProps.RichViewSpecial then begin
info.BestWidth := RowProps.BestWidth;
info.RichViewSpecial := True;
end
else
if ((info.BestWidth<=0) and (RowProps.BestWidth<info.BestWidth)) or
((info.BestWidth>=0) and (RowProps.BestWidth>info.BestWidth)) then
info.BestWidth := RowProps.BestWidth;
GetBorderColors(RowProps.Border,c1,c2);
if c1<>clNone then
info.table.BorderLightColor := c1;
if c2<>clNone then
info.table.BorderColor := c2;
// assigning cells
if CurrentRow=0 then begin
info.HRules.Add(RowProps.LeftTw);
for i := 0 to RowProps.CellProps.Count-1 do
info.HRules.Add(RowProps.CellProps[i].RightBoundaryTw);
end;
strt := 0;
if CurrentRow>0 then begin
val := RowProps.LeftTw;
idx := GetIndex(info.HRules, val);
if idx=0 then begin
if abs(info.HRules[idx]-val)>RV_TableGridEps then begin
info.HRules.Insert(0, val);
info.table.InsertCols(0,1,-1);
info.table.Cells[CurrentRow,0].Clear;
info.table.Cells[CurrentRow,0].AssignAttributesFrom(info.table.Cells[CurrentRow,1],True,1,1);
info.table.Rows.MergeCells(0,0,1,CurrentRow,True,False);
HideBorders(0,0);
strt := 0;
end;
end
else if idx=info.HRules.Count then begin
info.HRules.Add(val);
info.table.InsertCols(idx-1,2,-1);
info.table.Rows.MergeCells(0,idx,1,CurrentRow,True,False);
HideBorders(0,idx);
MergeCol(info.table,idx-1);
info.table.Rows.MergeCells(CurrentRow,0,idx,1,True,False);
HideBorders(CurrentRow,0);
if info.table.Cells[CurrentRow,0]<>nil then
info.table.Cells[CurrentRow,0].BestWidth := Round((info.HRules[idx]-info.HRules[0]-RowProps.GapHTw*2)*PixelsPerTwip);
strt := idx;
end
else begin
if abs(info.HRules[idx]-val)>RV_TableGridEps then begin
info.HRules.Insert(idx, val);
info.HRules.Sort;
info.table.InsertCols(idx-1,1,-1);
HideBorders(CurrentRow,idx-1);
MergeCol(info.table,idx-1);
end;
info.table.Rows.MergeCells(CurrentRow,0,idx,1,True,False);
strt := idx;
end;
for i := 0 to RowProps.CellProps.Count-1 do begin
val := RowProps.CellProps[i].RightBoundaryTw;
if RowProps.CellProps[i].HMerge=rtf_cm_First then
if strt<info.HRules.Count-1 then begin
val := info.HRules[strt+1];
if val>RowProps.CellProps[i+1].RightBoundaryTw then
val := RowProps.CellProps[i+1].RightBoundaryTw;
end
else
val := RowProps.CellProps[i+1].RightBoundaryTw;
idx := GetIndex(info.HRules, val);
if (idx=info.HRules.Count) then begin
if strt<info.HRules.Count-1 then begin
info.table.InsertCols(idx-1,1,-1);
end;
info.HRules.Add(val);
info.table.Rows.MergeCells(0,idx-1,1,CurrentRow,True,False);
HideBorders(0,idx-1);
end
else if abs(info.HRules[idx]-val)>RV_TableGridEps then begin
info.HRules.Insert(idx, val);
info.HRules.Sort;
info.table.InsertCols(idx-1,1,-1);
MergeCol(info.table,idx-1);
end;
info.table.Rows.MergeCells(CurrentRow,strt,idx-strt,1,True,False);
if (strt>0) and (RowProps.CellProps[i].HMerge=rtf_cm_Merged) then begin
info.table.Rows.GetMainCell(CurrentRow,strt-1,r,c);
info.table.Rows.MergeCells(r,c,idx-c,CurrentRow-r+1,True,False);
end;
if RowProps.CellProps[i].VMerge=rtf_cm_Merged then begin
info.table.Rows.GetMainCell(CurrentRow-1,strt,r,c);
span := idx-c;
if info.table.Cells[r,c].ColSpan>span then
span := info.table.Cells[r,c].ColSpan;
info.table.Rows.MergeCells(r,c,span,CurrentRow-r+1,True,False);
end;
if info.table.Cells[CurrentRow,strt]<>nil then begin
AssignCellProperties(info.table.Cells[CurrentRow,strt],RowProps.CellProps[i],strt,idx);
info.table.Cells[CurrentRow,strt].Clear;
info.table.Cells[CurrentRow,strt].DrainFrom(info.lastrow.Cells[0,i]);
end;
strt := idx;
end;
for i := strt to info.table.Rows[CurrentRow].Count-1 do
HideBorders(CurrentRow,i);
end
else // CurrentRow=0
for i := 0 to RowProps.CellProps.Count-1 do begin
if RowProps.CellProps[i].HMerge=rtf_cm_Merged then begin
info.table.Rows.GetMainCell(CurrentRow,i-1,r,c);
info.table.Rows.MergeCells(r,c,i-c+1,1,True,False);
end;
if info.table.Cells[CurrentRow,i]<>nil then begin
AssignCellProperties(info.table.Cells[CurrentRow,i], RowProps.CellProps[i],i,i+1);
info.table.Cells[CurrentRow,i].Clear;
info.table.Cells[CurrentRow,i].DrainFrom(info.lastrow.Cells[0,i]);
end;
end;
info.PrevColCount := info.table.Rows[0].Count-1;
end;
{------------------------------------------------------------------------------}
procedure TRVRTFReaderProperties.ReaderTable(Sender: TRVRTFReader;
WhatHappens: TRVRTFTableEventKind);
var info: TTableInfo;
i: Integer;
PrevRVData:TCustomRVData;
s: String;
begin
case WhatHappens of
rvf_tbl_TableStart:
begin
if Tables=nil then
Tables := TRVList.Create;
info := TTableInfo.Create;
info.table := TRVTableItemInfo.CreateEx(0,0,CurrentRVData);
info.table.BeforeLoading(rvlfRTF);
info.table.Color := clNone;
info.table.BorderStyle := rvtbRaisedColor;
info.table.CellBorderStyle := rvtbLoweredColor;
info.table.CellBorderColor := clWindowText;
info.table.BorderColor := clWindowText;
info.table.BorderLightColor := clWindowText;
info.table.CellBorderLightColor := clWindowText;
info.lastrow := TRVTableItemInfo.CreateEx(1,1,CurrentRVData);
info.lastrow.BeforeLoading(rvlfRTF);
info.ParentRow := CurrentRow;
info.ParentCol := CurrentCol;
CurrentRow := 0;
CurrentCol := 0;
CurrentRVData := info.lastrow.Cells[0,0];
CurrentRVData.Clear;
Tables.Add(info);
end;
rvf_tbl_TableEnd:
begin
info := TTableInfo(Tables[Tables.Count-1]);
if Tables.Count=1 then
case HFType of
rtf_hf_Header:
PrevRVData := FHeaderRVData;
rtf_hf_Footer:
PrevRVData := FFooterRVData;
else
PrevRVData := RVData;
end
else
PrevRVData := TTableInfo(Tables[Tables.Count-2]).lastrow.Cells[0,info.ParentCol];
info.Finalize(PixelsPerTwip, TableBorderGlueMode, GetEmptyStyleNo, GetEmptyParaNo(rvaLeft),
ExplicitTableWidth, AutoHideTableGridLines);
CurrentRVData := PrevRVData;
CurrentRow := info.ParentRow;
CurrentCol := info.ParentCol;
info.table.DeleteCols(info.HRules.Count-1,info.table.Rows[0].Count-info.HRules.Count+1,False);
info.table.ParaNo := GetEmptyParaNo(TRVAlignment(ord(Reader.RTFState.RowProps.Alignment)));
s := '';
if (info.table.Rows.Count=0) or (info.table.Rows[0].Count=0) then begin
info.table.Free;
info.table := nil
end
else
InsertItem(s, info.table, rtf_ts_NewPara);
if not info.RowFinished then begin
{$IFNDEF RVDONOTUSELISTS}
IgnoreLists := True;
{$ENDIF}
try
for i := 0 to info.lastrow.Cells[0,0].Items.Count-1 do begin
s := info.lastrow.Cells[0,0].Items[i];
InsertItem(s, info.lastrow.Cells[0,0].GetItem(i), rtf_ts_NewPara);
info.lastrow.Cells[0,0].Items.Objects[i] := nil;
end;
finally
{$IFNDEF RVDONOTUSELISTS}
IgnoreLists := False;
LastMarkerIndex := -1;
{$ENDIF}
end;
end;
Tables.Delete(Tables.Count-1);
end;
rvf_tbl_CellEnd:
begin
info := TTableInfo(Tables[Tables.Count-1]);
if info.lastrow.Cells[0,CurrentCol].Items.Count=0 then
NewReaderText(Sender,'',rtf_ts_NewPara);
inc(CurrentCol);
if CurrentCol=info.lastrow.Rows[0].Count then
info.lastrow.InsertCols(CurrentCol,1,-1);
CurrentRVData := info.lastrow.Cells[0,CurrentCol];
CurrentRVData.Clear;
end;
rvf_tbl_RowEnd:
begin
AssignRowProperties;
info := TTableInfo(Tables[Tables.Count-1]);
info.RowFinished := True;
inc(CurrentRow);
CurrentCol := 0;
info.lastrow.Rows.Reset(1,1);;
CurrentRVData := info.lastrow.Cells[0,CurrentCol];
CurrentRVData.Clear;
end;
end;
end;
{$ENDIF}
{------------------------------------------------------------------------------}
function TRVRTFReaderProperties.CreateTextItem(const Text: String;
{$IFDEF RICHVIEWCBDEF3}
const WideText: WideString;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -