From: Alban R. <a.r...@im...> - 2009-04-08 14:09:28
|
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 |