Loading RVF into table

General TRichView support forum. Please post your questions here
Post Reply
piotr_jarmolowicz
Posts: 2
Joined: Wed Nov 26, 2008 2:39 pm

Loading RVF into table

Post by piotr_jarmolowicz »

Hi,
I have some problems with loading rvf into table. I have five RVF files containing short texts ( font Time New Roman, various font size ). When I try to load them into TRichViewEdit using this code

Code: Select all

void __fastcall TForm1::btn2Click(TObject *Sender)
{
        for ( int i = 0; i < 5; i++ )
        {
                String sFileName( ExtractFilePath( Application->ExeName) + "rv\\an_" + IntToStr( i ) + ".dat" );

                TFileStream * fs = new TFileStream( sFileName, fmOpenRead );

                rve->AppendRVFFromStream( dynamic_cast<TStream*>( fs ), 0 );
                rve->Format( );

                delete fs;
                fs = 0;
        }
}
everything works fine - fonts ( and fontsize ) are correct. But when I try to do the same thing with table, it doesn't work.

Code: Select all

void __fastcall TForm1::btn3Click(TObject *Sender)
{
        TRVTableItemInfo * table = new TRVTableItemInfo( 5, 1, rve->RVData );

        for ( int i = 0; i < 5; i++ )
        {
                String sFileName( ExtractFilePath( Application->ExeName) + "rv\\an_" + IntToStr( i ) + ".dat" );

                TFileStream * fs = new TFileStream( sFileName, fmOpenRead );

                table->Cells[ i ][ 0 ]->Clear( );
                table->Cells[ i ][ 0 ]->DeleteUnusedStyles( true, true, true );
                table->Cells[ i ][ 0 ]->AppendRVFFromStream( dynamic_cast<TStream*>( fs ), -1, 0, 0 );
                table->Cells[ i ][ 0 ]->Format( true );

                delete fs;
                fs = 0;
        }
        
        rve->InsertItem( "table", table );
}
In first cell font is correct, but in last four cells I get Arial ( font size 10 ), so it looks like text styles are loaded incorrectly.

Another thing, that I don't understand is after successful loading rvf files ( directly into RichViewEdit, not into table ), when I check font in text styles:

Code: Select all

void __fastcall TForm1::btn5Click(TObject *Sender)
{
        String sMesg( "" );
        for ( int i = 0; i < rve->Style->TextStyles->Count; i++ )
        {
                sMesg += rve->Style->TextStyles->Items[ 0 ]->FontName + " : ";
                sMesg += IntToStr( rve->Style->TextStyles->Items[ 0 ]->Size ) + "\n";
        }

        ShowMessage( sMesg );
}
I can see that all text styles have font set to Arial and fontsize set to 10, even though texts in RichViewEdit have Times New Roman.

TRichVeiw settings are:
Styles - Allow adding styles dynamically
RVF Saving - all options checked
RVF Loading - DocProperties, Convert invalid style indices to 0 and Convert invalid imagelist indices to 0 checked, the rest unchecked.

Thanks for any help.

Piotr Jarmo³owicz
Sergey Tkachenko
Site Admin
Posts: 17559
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

In the current version of TRichView, cells do not support loading RVF containing styles.
Workaround is the following:
1) Create a hidden TRichView linked to the same TRVStyle component as rve: rvHidden.
2) This TRichView must not save styles in RVF, so exclude rvfoSaveTextStyles and rvfoSaveParaStyles from rvHidden->RVFOptions.
3) Before loading RVF in cell, load in in rvHidden using this code:
rvHidden->Clear();
rvHidden->InsertRVFFromStream(Stream, 0);
3) Save RVF from rvHidden to Stream. This RVF will not contain collections of styles, but all indices of styles will be correct, because rvHidden and rve are linked to the same RVStyle
4) Load this RVF in cell.
piotr_jarmolowicz
Posts: 2
Joined: Wed Nov 26, 2008 2:39 pm

Post by piotr_jarmolowicz »

Thanks for Your prompt answer.

Now it works perfect.

Regards

Piotr Jarmo³owicz
Post Reply