Hello
This should be simple but seems to be so difficult.
I have a document in a stream.
I load the document into a TRichview
VRichView := TRichView.Create( nil );
VStyles := TRVStyle.Create( nil );
VRichView.Style := VStyles;
VRichView.RVFParaStylesReadMode := {rvf_sIgnore;//}rvf_sInsertMerge;
VRichView.RVFTextStylesReadMode := {rvf_sIgnore;//}rvf_sInsertMerge;
VRichView.LoadRVFFromStream( Document );
I now want to change the font for all the text in the document
VRichView.Style.TextStyles[0].FontName := 'Arial Unicode MS';
This does not seem to work.
Pls advise
Changing the fontname of text in a document
-
- Site Admin
- Posts: 17557
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
Code: Select all
for i :=0 to VStyles.TextStyles.Count-1 do
VRichView.Style.TextStyles[i].FontName := 'Arial Unicode MS';
VRichView.Format;
So add:
Code: Select all
VRichView.Visible := False;
VRichView.Parent := <some form>
Sergey
Thanks for your prompt reply but this did not seem to fix the problem
My code as it stands now:
VRichView := TRichView.Create( nil );
VStyles := TRVStyle.Create( nil );
VRichView.Visible := False;
VRichView.Parent := Form6;
VRichView.Style := VStyles;
VRichView.RVFParaStylesReadMode := rvf_sInsertMerge;
VRichView.RVFTextStylesReadMode := rvf_sInsertMerge;
VRichView.LoadRVFFromStream( Document );
for i :=0 to VStyles.TextStyles.Count-1 do
VRichView.Style.TextStyles.FontName := 'Arial Unicode MS';
VRichView.Format;
VRichView.SaveRVFToStream( Document, True );
VRichView.free;
Thanks for your prompt reply but this did not seem to fix the problem
My code as it stands now:
VRichView := TRichView.Create( nil );
VStyles := TRVStyle.Create( nil );
VRichView.Visible := False;
VRichView.Parent := Form6;
VRichView.Style := VStyles;
VRichView.RVFParaStylesReadMode := rvf_sInsertMerge;
VRichView.RVFTextStylesReadMode := rvf_sInsertMerge;
VRichView.LoadRVFFromStream( Document );
for i :=0 to VStyles.TextStyles.Count-1 do
VRichView.Style.TextStyles.FontName := 'Arial Unicode MS';
VRichView.Format;
VRichView.SaveRVFToStream( Document, True );
VRichView.free;
-
- Site Admin
- Posts: 17557
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
This code must work.
But if you want to replace content of Document, call:
instead of
Without clearing the stream, new information will be written to the end of the existing content. It may produce incorrect RVF. Besides, you call SaveRVFToStream( Document, True ), so only selection is saved. In your code, the selection is empty.
In addition, add the following line before saving:
In addition, calling Format is not necessary if you do not need to display this document. Removing VRichView.Format will speed up this code.
But if you want to replace content of Document, call:
Code: Select all
Document.Clear;
VRichView.SaveRVFToStream( Document, False );
Code: Select all
VRichView.SaveRVFToStream( Document, True );
In addition, add the following line before saving:
Code: Select all
VRichView.RVFOptions := VRichView.RVFOptions + [rvfoSaveTextStyles, rvfoSaveParaStyles]
Last edited by Sergey Tkachenko on Tue Aug 21, 2007 4:45 am, edited 1 time in total.