Equation font in TfrmRVMathEditor: strange behavior

General TRichView support forum. Please post your questions here
Vitalii
Posts: 22
Joined: Sat Oct 20, 2018 2:55 pm
Location: Ukraine
Contact:

Equation font in TfrmRVMathEditor: strange behavior

Post by Vitalii » Sun Sep 22, 2019 7:39 pm

Hi,
a question about TfrmRVMathEditor. If I get you right, method Init after opening this form sets values of the "Font > Default values" section. But what about values in "Font > This equation" section? If I just set individual properties, then OK — these properties apply to the equation. But when I reopen form, this properties are not shown (Font, Size, Text color — empty). Also, when I save and reload RVF through the stream, equation properties are reset to the default values, and section "This equation" also empty.

I would like to better understand the logic of the form and how to save/load individual font properties of equation(s).

Sergey Tkachenko
Site Admin
Posts: 14722
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Equation font in TfrmRVMathEditor: strange behavior

Post by Sergey Tkachenko » Mon Sep 23, 2019 7:53 am

Do you use this form separately from action? Normally, this form is called by TrvActionInsertEquation (for insertion) and TrvActionItemProperties (for changing).
TrvActionItemProperties calls form.SetItem, then shows the form, then calls form.GetItem.
SetItem/GetItem process this equation font properties.

Sorry, I cannot reproduce the problem, both with the dialog and with RVF saving. I tried with the compiled ActionTest demo from https://www.trichview.com/download/demo.html

What TRichView version do you use? If it is not the newest version, please upgrade.
If you use the newest version, please give me step-by-step instructions or a simple project to reproduce the problems.

Vitalii
Posts: 22
Joined: Sat Oct 20, 2018 2:55 pm
Location: Ukraine
Contact:

Re: Equation font in TfrmRVMathEditor: strange behavior

Post by Vitalii » Mon Sep 23, 2019 5:53 pm

Thanks Sergey, the situation cleared up a bit.

Indeed, instead of TrvActionItemProperties I used TrvActionInsertEquation. Action TrvActionItemProperties works fine, but there is one problem: if equation contained an error symbol, editor form will show an empty string. This happens in method SetItem, line "Memo1.Lines.Text := Item.Text;".

Is it possible to make an erroneous equation editable in this form?

P. S. Question with RVF is solved automatically)

Sergey Tkachenko
Site Admin
Posts: 14722
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Equation font in TfrmRVMathEditor: strange behavior

Post by Sergey Tkachenko » Mon Sep 23, 2019 6:29 pm

I think that disabling OK button for incorrect equations would be a better solution.

(
TRVMathItemInfo's Text provides access to TRVMathItemInfo's Equation.Text, where Equation is TMathEquation.
TMathEquation is implemented by Adit and I do not want to change it. It does not allow to assign incorrect Text. So the problem with empty text instead of incorrect text occurs when assigning from memo to math item, not from math item to memo.
)

Vitalii
Posts: 22
Joined: Sat Oct 20, 2018 2:55 pm
Location: Ukraine
Contact:

Re: Equation font in TfrmRVMathEditor: strange behavior

Post by Vitalii » Mon Sep 23, 2019 8:39 pm

Hmm, but if the user wants to return to editing equation later? Maybe I need to create descendant class of TRVMathItemInfo, save equation text in a separate property and use it in the TfrmRVMathEditor?

Sergey Tkachenko
Site Admin
Posts: 14722
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Equation font in TfrmRVMathEditor: strange behavior

Post by Sergey Tkachenko » Wed Sep 25, 2019 10:37 am

Ok, in the next update, it will be possible to get and set erroneous text in TRVMathItemInfo, without exceptions.

Vitalii
Posts: 22
Joined: Sat Oct 20, 2018 2:55 pm
Location: Ukraine
Contact:

Re: Equation font in TfrmRVMathEditor: strange behavior

Post by Vitalii » Wed Sep 25, 2019 7:38 pm

Sergey Tkachenko wrote:
Wed Sep 25, 2019 10:37 am
Ok, in the next update, it will be possible to get and set erroneous text in TRVMathItemInfo, without exceptions.
it will be great!

Sergey, I want to ask also about TrvActionInsertEquation: this action does not call the methods SetItem/GetItem, only Init method? If "Font > This equation" properties are "empty" in TfrmRVMathEditor, does this mean that the equation always uses only default settings?

Sergey Tkachenko
Site Admin
Posts: 14722
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Equation font in TfrmRVMathEditor: strange behavior

Post by Sergey Tkachenko » Wed Sep 25, 2019 7:47 pm

It does not use SetItem (because there is no existing item to set to the form), it does not use GetItem (because it uses GetNewItem instead)

Vitalii
Posts: 22
Joined: Sat Oct 20, 2018 2:55 pm
Location: Ukraine
Contact:

Re: Equation font in TfrmRVMathEditor: strange behavior

Post by Vitalii » Thu Sep 26, 2019 8:42 am

Sergey, one more question. When loading a document from a stream using InsertRVFFromStream (not LoadRVFFromStream) equations are rolled back to the original formatting. I read the help about DocObjects and the idea is clear, but I need to use InsertRVFFromStream due to working with styles templates. What do you recommend that math equation formatting (and other DocObjects) load correctly in my case?

Now I use next scheme:

Edit.Clear;
Edit.LoadRVFFromStream(Data.RVF);
Edit.Format;
Edit.SelectAll;
Edit.DeleteSelection;
Data.RVF.Position := 0;
if Edit.InsertRVFFromStream(Data.RVF, 0) then
Edit.Format;

Maybe there is a simpler way to load doc properties, without LoadRVFFromStream?

Sergey Tkachenko
Site Admin
Posts: 14722
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Equation font in TfrmRVMathEditor: strange behavior

Post by Sergey Tkachenko » Fri Sep 27, 2019 6:49 am

Yes, insertion methods ignore "default equation settings", inserted equation use settings of the target document.
Your code is correct.

Vitalii
Posts: 22
Joined: Sat Oct 20, 2018 2:55 pm
Location: Ukraine
Contact:

Re: Equation font in TfrmRVMathEditor: strange behavior

Post by Vitalii » Fri Sep 27, 2019 8:09 am

Thanks, Sergey!

I try to create my own form to set default equation settings and see that in TfrmRVMathEditor.FormCreate comboboxes initiates with 'Arial' font. Is this correct or I need to set init values 'Cambria Math'?

Sergey Tkachenko
Site Admin
Posts: 14722
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Equation font in TfrmRVMathEditor: strange behavior

Post by Sergey Tkachenko » Fri Sep 27, 2019 7:53 pm

'Arial' cannot be used as font for equations. Only special math fonts can be used. See TRVMathItemInfo.FontName

Vitalii
Posts: 22
Joined: Sat Oct 20, 2018 2:55 pm
Location: Ukraine
Contact:

Re: Equation font in TfrmRVMathEditor: strange behavior

Post by Vitalii » Sat Sep 28, 2019 6:50 am

Sergey Tkachenko wrote:
Fri Sep 27, 2019 7:53 pm
'Arial' cannot be used as font for equations. Only special math fonts can be used
Yeah, I know that, but the original code in RVMathEditorFrm.pas just confused me)

procedure TfrmRVMathEditor.FormCreate(Sender: TObject);
begin
...
cmbFontSize.FontName := 'Arial';
cmbDefFontSize.FontName := 'Arial';
end;

Sergey Tkachenko
Site Admin
Posts: 14722
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Equation font in TfrmRVMathEditor: strange behavior

Post by Sergey Tkachenko » Sat Sep 28, 2019 11:34 am

This font name is assigned for combo boxes that display font sizes. If you assign any TrueType font to their FontName property, they are initialized with predefined set of font sizes. So Arial is as good as any other TT font.
All math fonts are TT fonts.

Vitalii
Posts: 22
Joined: Sat Oct 20, 2018 2:55 pm
Location: Ukraine
Contact:

Re: Equation font in TfrmRVMathEditor: strange behavior

Post by Vitalii » Sat Sep 28, 2019 7:35 pm

Ok, thanks!

Post Reply