Here is my test. It assumes you have RichViewEdit1 linked with RVStyle1.
Code: Select all
function GetNoWrapPara(RVStyle: TRVStyle): Integer;
var
ParaStyle: TParaInfo;
begin
ParaStyle := TParaInfo.Create(nil);
ParaStyle.Options := [rvpaoNoWrap];
Result := RVStyle.FindParaStyle(ParaStyle);
ParaStyle.Free;
end;
function GetTextStyle(RVStyle: TRVStyle; Size: Integer): Integer;
var
TextStyle: TFontInfo;
begin
TextStyle := TFontInfo.Create(nil);
TextStyle.Assign(RVStyle.TextStyles[0]);
TextStyle.Size := Size;
Result := RVStyle.FindTextStyle(TextStyle);
TextStyle.Free;
end;
procedure TForm3.ToolButton63Click(Sender: TObject);
var
Table: TRVTableItemInfo;
ParaNo, StyleNo: Integer;
procedure MakeAutoSize;
begin
Table.Cells[0,0].BestHeight := RVStyle1.PixelsToUnits(Table.Cells[0,0].DocumentWidth);
Table.Cells[0,1].BestHeight := RVStyle1.PixelsToUnits(Table.Cells[0,1].DocumentWidth);
Table.Cells[0,0].BestWidth := RVStyle1.PixelsToUnits(Table.Cells[0,0].DocumentHeight);
Table.Cells[0,1].BestWidth := RVStyle1.PixelsToUnits(Table.Cells[0,1].DocumentHeight);
end;
procedure MakeSmallSize;
begin
Table.Cells[0,0].BestHeight := 1;
Table.Cells[0,1].BestHeight := 1;
Table.Cells[0,0].BestWidth := 1;
Table.Cells[0,1].BestWidth := 1;
end;
begin
ParaNo := GetNoWrapPara(RVStyle1);
StyleNo := GetTextStyle(RVStyle1, 20);
Table := TRVTableItemInfo.CreateEx(1, 2, RichViewEdit1.RVData);
Table.CellBorderWidth := RVStyle1.PixelsToUnits(1);
Table.BorderWidth := RVStyle1.PixelsToUnits(1);
Table.CellPadding := RVStyle1.PixelsToUnits(20);
Table.Cells[0,0].Rotation := rvrot90;
Table.Cells[0,0].Clear;
Table.Cells[0,0].AddNL('Hello world!!!', StyleNo, ParaNo);
Table.Cells[0,1].Rotation := rvrot90;
Table.Cells[0,1].Clear;
Table.Cells[0,1].AddNL('Good bye!', StyleNo, ParaNo);
Table.Cells[0,1].AddNL('Good bye!', StyleNo, ParaNo);
MakeSmallSize;
if not RichViewEdit1.InsertItem('', Table) then
exit;
MakeAutoSize;
RichViewEdit1.Reformat;
Application.MessageBox('Making text smaller', 'Table Test');
MakeSmallSize;
StyleNo := GetTextStyle(RVStyle1, 10);
Table.Cells[0, 0].GetItem(0).StyleNo := StyleNo;
Table.Cells[0, 1].GetItem(0).StyleNo := StyleNo;
Table.Cells[0, 1].GetItem(1).StyleNo := StyleNo;
RichViewEdit1.Reformat;
MakeAutoSize;
RichViewEdit1.Reformat;
Application.MessageBox('Making text larger', 'Table Test');
MakeSmallSize;
StyleNo := GetTextStyle(RVStyle1, 30);
Table.Cells[0, 0].GetItem(0).StyleNo := StyleNo;
Table.Cells[0, 1].GetItem(0).StyleNo := StyleNo;
Table.Cells[0, 1].GetItem(1).StyleNo := StyleNo;
RichViewEdit1.Reformat;
MakeAutoSize;
RichViewEdit1.Reformat;
end;
For simplicity, this code uses Reformat to reformat the document. A more efficient way to reformat is using BeginItemModify and EndItemModify.
Update: I added calls to PixelsToUnits, so this code works when sizes are measured in twips as well.