Alan W. Irwin wrote:
> On 2009-04-07 09:56-0700 Alan W. Irwin wrote:
>
> Hi again, Alban:
>
> I have done a bit more research on these issues, and now I am not sure any
> more of what the real issue is. :-(
>
> I looked at the model of how cairo.c processes strings since it seems to
> deal with all issues correctly. Notice there, that
> ucs4_to_pango_markup_format gives results which are a mixture of glyph codes
> (UTF8 in this case) and pango markup codes. That mixture of glyphs and
> markup commands is then further processed natively by libpango/libcairo to
> actually render the text. So this approach automatically allows changing
> fonts in the middle of strings.
>
> It would be great if we could use a similar approach (to mix glyph codes and
> markup commands that Qt processes further in native mode) with Qt, but I
> have not seen anything like that in the Qt documentation. However, I think
> your present approach (to break up strings into subsets with constant fonts
> and other markup) should handle the case of changing the font in the middle
> of strings correctly. Thus, I don't understand why the vertical
> misalignment is happening for this case for example 3.
>
> Just to explore possibilities some more, I applied the following temporary
> patch which makes the symbol font be serif rather than sans.
>
> Index: qt.cpp
> ===================================================================
> --- qt.cpp (revision 9780)
> +++ qt.cpp (working copy)
> @@ -268,7 +268,8 @@
> switch(fontFamily) {
> case 1: f.setFamily("Times"); f.setStyleHint(QFont::Serif);
> break;
> case 2: f.setFamily("Courier"); f.setStyleHint(QFont::TypeWriter);
> break;
> - case 0: case3: case4: default: f.setFamily("Helvetica");
> f.setStyleHint(QFont::SansSerif); break;
> + //case 0: case3: case4: default: f.setFamily("Helvetica");
> f.setStyleHint(QFont::SansSerif); break;
> + case 0: case3: case4: default: f.setFamily("Times");
> f.setStyleHint(QFont::Serif); break;
> }
> if(fontStyle) f.setItalic(true);
> if(fontWeight) f.setWeight(QFont::Bold);
>
> For this case (which is obviously not the general fix we want), the example
> 3 thetas are aligned correctly!
>
> Note that in example 3 the string we are dealing with is "#frPLplot Example
> 3 - r(#gh)=sin 5#gh". The #fr is an old-fashioned escape sequence to switch
> to font case 1 e.g., Times/serif, and the #gh is an old-fashioned escape
> sequence the does three things: (1) switch to case 4 font in PLplot core,
> (2) asks the device driver to render a unicode Greek theta, and (3) switch
> back to the original font (case 1 font in this case) in the PLplot core. Why
> should vertical alignment be affected by whether case 4 is serif (the
> original font for this particular string) or sans?
>
> I hope the additional background I have given you here and in previous posts
> in this thread will help you to answer that key question.
>
> Alan
> __________________________
> Alan W. Irwin
>
> Astronomical research affiliation with Department of Physics and Astronomy,
> University of Victoria (astrowww.phys.uvic.ca).
>
> Programming affiliations with the FreeEOS equation-of-state implementation
> for stellar interiors (freeeos.sf.net); PLplot scientific plotting software
> package (plplot.org); the libLASi project (unifont.org/lasi); the Loads of
> Linux Links project (loll.sf.net); and the Linux Brochure Project
> (lbproject.sf.net).
> __________________________
>
> Linux-powered Science
> __________________________
>
Hi Alan,
Experimenting around this bug, I've found a way to get everything
working properly (at least on my system), though I do not understand
clearly what's going on. If I set explicitly a family name for the
fonts, the bounding boxes sometimes get messed up for some characters:
theta gets a smaller bounding box than the rest of the characters and
gets glued on the top boundary of its box whereas it has a large margin
beneath it for example (hence the offset).
However, the StyleHint parameter is used by the Qt font engine to
determine which font to use in case the explicitly defined family is not
available. Defining the good style hint and asking Qt to get a
non-existing font (I called it "foo"), thus letting it choose (and
parameter something with?) the fonts, everything seems to work fine:
Sans-serif, Serif and Monotype fonts are used where required, and no
offset is noticed on my system (OpenSuse 11.1, Qt 4.4.3).
I've compared the results of the whole set of tests between qtwidget and
xcairo, they look similar. I've reduced a little the Qt font size to
better match Cairo's (1.6 factor to 1.45).
I propose the attached patch based on revision 9796. Due to the rather
fuzzy nature of the bug (and the proposed fix), reports on other systems
are welcome!
For your information, Imperial College closes tonight for Easter and
re-opens Wednesday next week. I will be away during this period.
Cheers,
Alban
Index: drivers/qt.cpp
===================================================================
--- drivers/qt.cpp (revision 9796)
+++ drivers/qt.cpp (working copy)
@@ -266,17 +266,28 @@
f.setPointSizeF(currentFontSize*currentFontScale<4 ? 4 :
currentFontSize*currentFontScale);
switch(fontFamily) {
- case 1: f.setFamily("Times"); f.setStyleHint(QFont::Serif);
break;
- case 2: f.setFamily("Courier"); f.setStyleHint(QFont::TypeWriter);
break;
- case 0: case3: case4: default: f.setFamily("Helvetica");
f.setStyleHint(QFont::SansSerif); break;
+ case 1:
+ f.setStyleHint(QFont::Serif);
+// f.setFamily("Times");
+ break;
+ case 2:
+ f.setStyleHint(QFont::TypeWriter);
+// f.setFamily("Courier");
+ break;
+ case 0: case3: case4:default:
+ f.setStyleHint(QFont::SansSerif);
+// f.setFamily("Helvetica");
+ break;
}
+ f.setFamily("foo"); // dummy family name, forcing Qt to find an
appropriate font by itself
+
if(fontStyle) f.setItalic(true);
if(fontWeight) f.setWeight(QFont::Bold);
else f.setWeight(QFont::Normal);
f.setUnderline(underlined);
f.setOverline(overlined);
-
+
return f;
}
@@ -287,12 +298,15 @@
QPicture tempPic;
QPainter tempPainter(&tempPic);
tempPainter.setFont(p->font());
- QRectF rect(0., 0., 1., 1.);
+ QRectF rect(0., 0., 0., 0.);
QRectF bounding;
tempPainter.drawText(rect,
Qt::AlignHCenter|Qt::AlignVCenter|Qt::TextDontClip, text, &bounding);
- bounding.adjust(-0.5, bounding.height(), -0.5, -bounding.height()/5.);
// Empiric adjustment of the true bounding box
+// tempPainter.drawLine(bounding.left()+1, bounding.bottom(),
bounding.right()-1, bounding.bottom());
+// tempPainter.drawLine(bounding.left()+1, bounding.top(), bounding.right()-1,
bounding.top());
+// bounding.adjust(-0.5, bounding.height(), -0.5, -bounding.height()/5.);
// Empiric adjustment of the true bounding box
+
tempPainter.end();
p->drawPicture(xOffset+bounding.width()/2., -yOffset, tempPic);
@@ -321,7 +335,7 @@
// have the same character size as cairo results (taking into account
// the slightly different actual glyph sizes for the different
// default fonts found by cairo and qt).
- currentFontSize=chrht*POINTS_PER_INCH/25.4*1.6;
+ currentFontSize=chrht*POINTS_PER_INCH/25.4*1.45;
currentFontScale=1.;
underlined=false;
overlined=false;
------------------------------------------------------------------------------
This SF.net email is sponsored by:
High Quality Requirements in a Collaborative Environment.
Download a free trial of Rational Requirements Composer Now!
http://p.sf.net/sfu/www-ibm-com
_______________________________________________
Plplot-devel mailing list
Plplot-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/plplot-devel