Page 1 of 1
Changing the fontname of text in a document
Posted: Mon Aug 20, 2007 5:38 am
by bglboss
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
Posted: Mon Aug 20, 2007 10:54 am
by Sergey Tkachenko
Code: Select all
for i :=0 to VStyles.TextStyles.Count-1 do
VRichView.Style.TextStyles[i].FontName := 'Arial Unicode MS';
VRichView.Format;
PS: currently, TRichView cannot work without Parent assigned.
So add:
Code: Select all
VRichView.Visible := False;
VRichView.Parent := <some form>
Posted: Mon Aug 20, 2007 1:11 pm
by bglboss
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;
Posted: Mon Aug 20, 2007 1:16 pm
by Sergey Tkachenko
This code must work.
But if you want to replace content of Document, call:
Code: Select all
Document.Clear;
VRichView.SaveRVFToStream( Document, False );
instead of
Code: Select all
VRichView.SaveRVFToStream( Document, True );
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:
Code: Select all
VRichView.RVFOptions := VRichView.RVFOptions + [rvfoSaveTextStyles, rvfoSaveParaStyles]
In addition, calling Format is not necessary if you do not need to display this document. Removing VRichView.Format will speed up this code.
Posted: Mon Aug 20, 2007 9:38 pm
by bglboss
Thanks Sergey , now works beautifully