📄 rvrtfprops.pas
字号:
end;
rtf_brdr_Triple:
begin
// WidthRTF = width of line = width of space
StyleRV := rvbTriple;
WidthRV := Round(WidthRTF*PixelPerTwips);
IntWidthRV := WidthRV*2-1;
end;
rtf_brdr_Hairline:
begin
StyleRV := rvbSingle;
WidthRV := 1;
end;
rtf_brdr_ThickThinSmall:
begin
// original: one-pixel thin line, one-pixel space, WidthRTF thick line
if InvertSides then
StyleRV := rvbThickInside
else
StyleRV := rvbThickOutside;
WidthRV := Round(WidthRTF*PixelPerTwips/2);
IntWidthRV := WidthRV+(WidthRV+1) div 2;
end;
rtf_brdr_ThickThinMed:
begin
// original: WidthRTF thick line, thin line - half (?), space = thin line,
if InvertSides then
StyleRV := rvbThickInside
else
StyleRV := rvbThickOutside;
WidthRV := Round(WidthRTF*PixelPerTwips/2);
IntWidthRV := WidthRV*2+(WidthRV+1) div 2;
end;
rtf_brdr_ThickThinLarge:
begin
// original: one-pixel thin line, two-pixel thick line (?), WidthRTF space
if InvertSides then
StyleRV := rvbThickInside
else
StyleRV := rvbThickOutside;
WidthRV := 1;
IntWidthRV := Round(WidthRTF*PixelPerTwips)+1;
end;
rtf_brdr_ThinThickSmall:
begin
if not InvertSides then
StyleRV := rvbThickInside
else
StyleRV := rvbThickOutside;
IntWidthRV := 1+Round(WidthRTF*PixelPerTwips*3/8);
IntWidthRV := WidthRV+(WidthRV+1) div 2;
end;
rtf_brdr_ThinThickMed:
begin
if not InvertSides then
StyleRV := rvbThickInside
else
StyleRV := rvbThickOutside;
WidthRV := Round(WidthRTF*PixelPerTwips/2);
IntWidthRV := WidthRV*2+(WidthRV+1) div 2;
end;
rtf_brdr_ThinThickLarge:
begin
if not InvertSides then
StyleRV := rvbThickInside
else
StyleRV := rvbThickOutside;
WidthRV := 1;
IntWidthRV := Round(WidthRTF*PixelPerTwips)+1;
end;
rtf_brdr_ThinThickThinSmall:
begin
StyleRV := rvbTriple;
WidthRV := Round(WidthRTF*PixelPerTwips/3);
IntWidthRV := WidthRV*2-1;;
end;
rtf_brdr_ThinThickThinMed:
begin
StyleRV := rvbTriple;
WidthRV := Round(WidthRTF*PixelPerTwips/2);
IntWidthRV := WidthRV*3-1;
end;
rtf_brdr_ThinThickThinLarge:
begin
StyleRV := rvbTriple;
WidthRV := 1;
IntWidthRV := Round(WidthRTF*PixelPerTwips);
end;
end;
end;
{------------------------------------------------------------------------------}
function GetStyleSSType(VShift: Integer): TRVRTFSScriptType;
begin
if VShift=0 then
Result := rtf_ss_Normal
else if VShift<0 then
Result := rtf_ss_Subscript
else
Result := rtf_ss_Superscript;
end;
{$ENDIF}
{=========================== TRVRTFReaderProperties ===========================}
constructor TRVRTFReaderProperties.Create;
begin
inherited Create;
FUnicodeMode := rvruNoUnicode;
FTextStyleMode := rvrsUseClosest;
FParaStyleMode := rvrsUseClosest;
FIgnorePictures := False;
FSkipHiddenText := True;
FTableBorderGlueMode := rvbgNegativeSpacing;
FHideTableGridLines := False;
AllowNewPara := True;
{$IFNDEF RVDONOTUSERTFIMPORT}
FConvertHighlight := rtfhlColorTable;
{$ENDIF}
end;
{------------------------------------------------------------------------------}
procedure TRVRTFReaderProperties.Assign(Source: TPersistent);
begin
if Source is TRVRTFReaderProperties then begin
FUnicodeMode := TRVRTFReaderProperties(Source).FUnicodeMode;
FTextStyleMode := TRVRTFReaderProperties(Source).FTextStyleMode;
FParaStyleMode := TRVRTFReaderProperties(Source).FParaStyleMode;
FIgnorePictures := TRVRTFReaderProperties(Source).FIgnorePictures;
FParaNo := TRVRTFReaderProperties(Source).FParaNo;
FStyleNo := TRVRTFReaderProperties(Source).FStyleNo;
FUseHypertextStyles := TRVRTFReaderProperties(Source).FUseHypertextStyles;
end
else
inherited Assign(Source);
end;
{------------------------------------------------------------------------------}
function TRVRTFReaderProperties.ReadFromFile(const AFileName: String;
ARVData: TCustomRVData): TRVRTFErrorCode;
begin
{$IFNDEF RVDONOTUSERTFIMPORT}
try
RVData := ARVData;
EditFlag := False;
InsertPoint := RVData.Items.Count;
Index := -1;
Reader := TRVRTFReader.Create(nil);
try
InitReader;
Result := Reader.ReadFromFile(AFileName);
ErrorCode := Result;
finally
DoneReader;
Reader.Free;
end;
except
Result := rtf_ec_Exception;
end;
{$ELSE}
Result := rtf_ec_OK;
{$ENDIF}
end;
{------------------------------------------------------------------------------}
function TRVRTFReaderProperties.ReadFromStream(AStream: TStream;
ARVData: TCustomRVData): TRVRTFErrorCode;
begin
{$IFNDEF RVDONOTUSERTFIMPORT}
try
RVData := ARVData;
Reader := TRVRTFReader.Create(nil);
EditFlag := False;
InsertPoint := RVData.Items.Count;
Index := -1;
try
InitReader;
Result := Reader.ReadFromStream(AStream);
ErrorCode := Result;
finally
DoneReader;
Reader.Free;
end;
except
Result := rtf_ec_Exception;
end;
{$ELSE}
Result := rtf_ec_OK;
{$ENDIF}
end;
{------------------------------------------------------------------------------}
function TRVRTFReaderProperties.InsertFromStreamEd(AStream: TStream;
ARVData: TCustomRVData; var AIndex: Integer): TRVRTFErrorCode;
begin
{$IFNDEF RVDONOTUSERTFIMPORT}
RVData := ARVData;
Reader := TRVRTFReader.Create(nil);
EditFlag := True;
InsertPoint := AIndex;
Index := -1;
try
InitReader;
Result := Reader.ReadFromStream(AStream);
ErrorCode := Result;
finally
Reader.Free;
DoneReader;
AIndex := Index;
end;
{$ELSE}
Result := rtf_ec_OK;
{$ENDIF}
end;
{------------------------------------------------------------------------------}
procedure TRVRTFReaderProperties.SetParaNo(const Value: Integer);
begin
if Value<0 then
raise Exception.Create(errNegative);
FParaNo := Value;
end;
{------------------------------------------------------------------------------}
procedure TRVRTFReaderProperties.SetStyleNo(const Value: Integer);
begin
if Value<0 then
raise Exception.Create(errNegative);
FStyleNo := Value;
end;
{------------------------------------------------------------------------------}
{$IFNDEF RVDONOTUSERTFIMPORT}
procedure TRVRTFReaderProperties.SetFooter(RVData: TCustomRVData);
begin
FFooterRVData := RVData;
end;
{------------------------------------------------------------------------------}
procedure TRVRTFReaderProperties.SetHeader(RVData: TCustomRVData);
begin
FHeaderRVData := RVData;
end;
{------------------------------------------------------------------------------}
procedure TRVRTFReaderProperties.NewReaderPicture(Sender: TRVRTFReader;
RTFPicture: TRVRTFPicture; Graphic: TGraphic; Position: TRVRTFPosition);
var item: TCustomRVItemInfo;
Target, Extras: String;
StyleNo, ItemTag,v: Integer;
ItemName: String;
Hyp, FreeGraphic: Boolean;
begin
ItemName := '';
if Assigned(OnCustomImageItem) then begin
Hyp := IsHypertext(Target, Extras);
item := nil;
FreeGraphic := False;
OnCustomImageItem(CurrentRVData, Graphic, Hyp, item, FreeGraphic, RTFPicture);
if FreeGraphic then
Graphic.Free;
if item<>nil then
RVData.ReadHyperlink(Target, Extras, rvlfRTF, item.StyleNo, item.Tag, ItemName);
end
else begin
if Graphic=nil then begin
Graphic := RV_CreateGraphics(TGraphicClass(RVStyle.InvalidPicture.Graphic.ClassType));
Graphic.Assign(RVStyle.InvalidPicture.Graphic);
end;
StyleNo := rvsPicture;
ItemTag := 0;
if IsHypertext(Target, Extras) then begin
RVData.ReadHyperlink(Target, Extras, rvlfRTF, StyleNo, ItemTag, ItemName);
item := CreateRichViewItem(StyleNo,RVData) as TRVGraphicItemInfo;
TRVGraphicItemInfo(item).Image := Graphic;
TRVGraphicItemInfo(item).Tag := ItemTag;
end
else
item := TRVGraphicItemInfo.CreateEx(CurrentRVData, Graphic, rvvaBaseline);
end;
if item<>nil then begin
if (item is TRVGraphicItemInfo) and (RTFPicture<>nil) then begin
if (TRVGraphicItemInfo(item).Image is TMetafile) or (RTFPicture.PicScaleX<>100) then begin
if RTFPicture.SuggestedWidth>0 then
v := RTFPicture.SuggestedWidth
else
v := TRVGraphicItemInfo(item).Image.Width;
TRVGraphicItemInfo(item).ImageWidth := MulDiv(v, RTFPicture.PicScaleX, 100);
end;
if (TRVGraphicItemInfo(item).Image is TMetafile) or (RTFPicture.PicScaleY<>100) then begin
if RTFPicture.SuggestedWidth>0 then
v := RTFPicture.SuggestedHeight
else
v := TRVGraphicItemInfo(item).Image.Height;
TRVGraphicItemInfo(item).ImageHeight := MulDiv(v, RTFPicture.PicScaleY, 100);
end;
end;
item.ParaNo := ReturnParaNo(Position);
item.BeforeLoading(rvlfRTF);
InsertItem(ItemName, item, Position);
end;
end;
{------------------------------------------------------------------------------}
function GetIndex(List: TRVIntegerList; Value: Integer): Integer;
var i: Integer;
begin
for i := 0 to List.Count-1 do
if List[i]>=Value then begin
Result := i;
exit;
end;
Result := List.Count;
end;
{$IFNDEF RVDONOTUSETABLES}
{------------------------------------------------------------------------------}
procedure MergeCol(table: TRVTableItemInfo; c: Integer);
var r: Integer;
begin
if c>=table.Rows[0].Count-2 then
exit;
for r := 0 to table.Rows.Count-2 do
if table.Cells[r,c]<>nil then
table.Cells[r,c].Clear;
for r := 0 to table.Rows.Count-2 do
if (table.Cells[r,c]<>nil) and (table.Cells[r,c+1]<>nil) then begin
table.Cells[r,c].AssignAttributesFrom(table.Cells[r,c+1], True,1,1);
table.Rows.MergeCells(r,c, table.Cells[r,c+1].ColSpan+1,table.Cells[r,c+1].RowSpan,True,False);
end;
end;
{------------------------------------------------------------------------------}
procedure GetBorderColors(Border: TRVRTFParaBorder; var c1, c2: TColor);
begin
c1 := clNone;
c2 := clNone;
if Border.Sides[rtf_side_Left].BorderType<>rtf_brdr_None then
c1 := Border.Sides[rtf_side_Left].Color
else if Border.Sides[rtf_side_Top].BorderType<>rtf_brdr_None then
c1 := Border.Sides[rtf_side_Top].Color;
if Border.Sides[rtf_side_Right].BorderType<>rtf_brdr_None then
c2 := Border.Sides[rtf_side_Right].Color
else if Border.Sides[rtf_side_Bottom].BorderType<>rtf_brdr_None then
c2 := Border.Sides[rtf_side_Bottom].Color;
end;
{------------------------------------------------------------------------------}
procedure TRVRTFReaderProperties.AssignRowProperties;
var info: TTableInfo;
i,span,r,c,idx,val,strt: Integer;
RowProps: TRVRTFRowProperties;
side: TRVRTFSide;
c1,c2: TColor;
{............................................................}
procedure AssignCellProperties(Cell: TRVTableCellData; Props: TRVRTFCellProperties; RuleIndex1,RuleIndex2: Integer);
var side: TRVRTFSide;
w: Integer;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -