1 Attachment(s)
[MathML] problem displaying a math expression
Hello,
Despite all my research on the web, I'm still failing to display correctly a math expression using the MathML engine of Qwt. So far, I created a minimalist "testing project", aiming to only display a MathML-formatted text fed in via a text file in the execution directory :
Code:
// includes erased here for clarity
int main(int argc, char** argv)
{
ifstream ifs("text");
std::string fullText="";
while(!ifs.eof())
{
std::string line;
getline(ifs,line);
fullText += line + "\n";
}
QTextCodec::setCodecForCStrings(QTextCodec::codecForName("utf-8"));
// Strings in files are UTF-8 encoded
QString locale
= QLocale::system().
name().
section('_',
0,
0);
// Installs a translator to the user's locale a.installTranslator(&translator);
lbl->setMinimumHeight(100);
lbl->setMinimumWidth(200);
lbl->show();
return a.exec();
}
My "text" file contains a MathML expression directly copy/pasted from Wikipedia, to display the solutions of a quadratic equation, which - I suppose - is syntaxically correct : http://pastebin.com/Nq6gYkvf.
This code results displaying only letters, not formatted at all, as seen in this screenshot :
Attachment 8985
What am I doing wrong?
Thanks for your help,
Tobast.
Re: [MathML] problem displaying a math expression
The MathML renderer is taken from the former Qt solutions package. I'm not sure how complete and powerful it is myself - but AFAIR the package ( no idea where to find it today ) contained a more advanced formula.
Uwe
Re: [MathML] problem displaying a math expression
Hello,
So, you would say that my implementation is right, but the engine cannot display that formula?
Thanks, Tobast
Re: [MathML] problem displaying a math expression
Your code is o.k. - at least the way how you use Qwt - so I would expect to find the reason in the syntax of the string you are passing. To be honest I have forgotten about the details of this renderer and - as I said before - it would be best to find the example in the Qt solution package.
But as I'm interested myself I will try to write an example using MathML labels, so that it won't get lost anymore.
Uwe
Re: [MathML] problem displaying a math expression
Tobast/Uwe,
I was wondering whether any of you guys had managed to get the MathML renderer to work 'properly' using Qwt's MathML engine? FWIW, I was able to get things to work fine using QtMmlWidget (but I have decided to drop it in favour of Qwt).
Cheers, Alan.
Re: [MathML] problem displaying a math expression
FWIW, the MathML code given by Tobast is content MathML while it would seem that Qwt's MathML engine only accepts presentation MathML, which would explain the rendering Tobast got...
Re: [MathML] problem displaying a math expression
Quote:
Originally Posted by
Uwe
But as I'm interested myself I will try to write an example using MathML labels, so that it won't get lost anymore.
Uwe, I have had another look at the MathML renderer in Qwt and spotted several issues with it. I know it has never been fully tested, so it doesn't come as a big surprise to me.
Still, since you are interested in this issue, I was wondering whether you had had a chance to do anything about it or are planning to do something about it? It's just that I really need the MathML renderer to work in Qwt. So, either I wait for you to fix things or I do it myself (and then send you the code, of course, for possible revision and inclusion in Qwt). Just let me know.
Re: [MathML] problem displaying a math expression
Quote:
Originally Posted by
agarny
Uwe, I have had another look at the MathML renderer in Qwt and spotted several issues with it. I know it has never been fully tested, so it doesn't come as a big surprise to me.
This code is a leftover from the former Qt solutions package - all I did is to make it available as an option for being used as a QwtText plugin. In fact I don't know much about MathML myself and the quality of this renderer.
Unfortunately I havn't seen any better option for rendering formulas for Qt so far.
Quote:
So, either I wait for you to fix things or I do it myself (and then send you the code, of course, for possible revision and inclusion in Qwt). Just let me know.
Please go ahead with whatever you believe that improves the implementation.
Uwe
Re: [MathML] problem displaying a math expression
Quote:
Originally Posted by
Uwe
Please go ahead with whatever you believe that improves the implementation.
Ok, I shall then. I just wanted to make sure that you were not already working on it.
Re: [MathML] problem displaying a math expression
Ok, I had a bit of time yesterday to look into it and I now have Qwt's MathML renderer working with QwtTextLabel in a way which is similar to what could be done with the now discontinued QtMmlWidget.
You can find 'my' version of Qwt's MathML renderer at https://github.com/opencor/opencor/t...engines/mathml. I 'cleaned' the code a bit, but nothing major.
I have tried the renderer with some presentation MathML code and it's working fine. At least, as fine as QtMmlWidget. Indeed, I noticed some issues with the renderer itself (see https://github.com/opencor/opencor/issues/225). I will try to fix them when I have a bit more time.
Re: [MathML] problem displaying a math expression
I had a quick look at your changes and IMHO it seems to me like you are working around issues that have to do with rounding errors because of an integer based implementation. Your patches somehow fix these problems by adding some margins here changing a factor there. This might be a solution when using a formula with QwtTextLabel, but when scaling comes into the game ( f.e. a formula on the canvas painted with QwtPlotRenderer to PDF ) your approach will not be enough.
IMO a more promising approach would be to modify the renderer being completely floating point based ?
Uwe
Re: [MathML] problem displaying a math expression
I must confess that, so far, I have been working on getting the original QtMmlWidget's MathML renderer to work within Qwt (which is now the case). From there, I have been working on fixing some issues I have found with the original MathML renderer (still working on it).
This being said, I agree that a floating point based approach would be better. Maybe I should go through the code and, who knows, it might mean I don't have 'patch' certain things. Then again, there are some factors that were just plain wrong, so I had no choice but to 'fix' them. For example, say that you have x with i as a sub-script and j as a super-script. In this case, the MathML render uses g_script_size_multiplier to scale those scripts. However, the original value of g_script_size_multiplier is such that i and j would always overlap, hence I modified that value to 0.5 (from 0.7071) and as expected now everything is fine.
Anyway, it's still very much work in progress, but I am hoping to be done with it within the next few days. (I can't afford to spend too much time on this.) From there, I leave it to you to incorporate 'my' version of the MathML render to Qwt or not. What is certain is that you are better placed than I am to test the renderer for use within Qwt (my use of Qwt is somewhat limited).
Re: [MathML] problem displaying a math expression
What about starting this way: I will set up a test application ( in qwt/playground/mathml ), where a MathML text is displayed in the center of a widget using the MathML renderer in its paint event. It will be using a transformation, that can be modified by the mouse ( scale factor + maybe a rotation ). Your contribution would be to set up a reasonable collection of MathML formulas, that can be loaded into the application.
Then we can see easily where the renderer needs polishing.
Uwe
Re: [MathML] problem displaying a math expression
Seems like a sensible approach to me. We should start by using a version of QtMmlWidget's MathML renderer that works with Qwt, but doesn't contain my 'fixes'/'patches'. From there, we should convert the code to use a floating point based approach. Finally, based on the results we get from the test application, we can see whether any of my 'fixes'/'patches' are still needed.
Re: [MathML] problem displaying a math expression
I suggest we leave the forum and continue by Email. Please send me a couple of MathML formulas I can use as a start for the test application.
Uwe
Re: [MathML] problem displaying a math expression
Sorry, but I can't seem to find how to send a private message on here. Anyway, you can find some formulas here and then my email address from my GitHub account.
Re: [MathML] problem displaying a math expression
Guys, what is the status of Your current development? Is it ready to use: http://www.qtcentre.org/threads/6610...orkable-in-Qwt ?
Re: [MathML] problem displaying a math expression
Uwe and I did exchange quite a few emails, and I ended up reworking the MathML engine quite a bit. I haven't done anything about it for quite a while, so I can't remember whether the version at https://github.com/uwerat/qwt-mml-dev is still up to date. So, just in case, you can find 'my' version at https://github.com/opencor/opencor/t...engines/mathml. What is sure is that the equation you mention at http://www.qtcentre.org/threads/6610...orkable-in-Qwt can now safely be rendered.
Re: [MathML] problem displaying a math expression
Quote:
Originally Posted by
agarny
agarny, so You version mentioned above works fine, correct? Will try to replace qwt sources by Your version and rebuild. Thanks!
Re: [MathML] problem displaying a math expression
agarny, Your sources works fine. Thank You very much!!!
Some bugs however:
- formula background is white, need to be gray as button default color. autoFillBackground does not help.
- Aslo font color changing through palette propery has effect: only for plain text, for MathML engine still black.
- QwtText::setColor() has no effect
- QwtText::setBackgroundBrush() has no effect
- QwtText::setPaintAttribute() for color or background true or false has no effect
Any way to fix?
Note: need to add qwt_mml_entity_table.h/cpp files to mathml.pro also.
Uwe, any chance to include this patches into official version? Thanks!