On Mon, Oct 20, 2003 at 10:06:58PM +0000, Angus Leeming wrote: > I'm a bit pissed off with the way we handle fonts and strings.
Good starting point. > It seems to me that we are duplicating code in the inset metrics and > draw functions. Only in the very inner block of code do things > differ, one ascertaining the width of the string in this particular > font and the other calling the painter with this info. > > As an example, I append the code from render_graphic.C to print out a > diagnostic message. > > It seems to me that this mess could be avoided if we had some > container that could contain both the string and the font information. > Indeed, the STL stream classes do something very similar. > > I can imagine code like: > > void RenderGraphic::metrics(MetricsInfo & mi, Dimension & dim) const > { > if (!image_ready) > lyx::rendered_stringstream rss; > create_message(rss); > dim.wid = std::max(50, rss.width() + 15); > } > } > > RenderGraphic::draw(PainterInfo & pi, int x, int y) const > { > if (!image_ready) > lyx::rendered_stringstream rss; > create_message(rss); > pi.pain.text(x + InsetOld::TEXT_TO_INSET_OFFSET + 6, y - 4, > rss); > } > } > > where the magical helper function contained code like: > > void RenderGraphic::create_message(lyx::rendered_stringstream & rss) > { > rss << setFont(mi.base.font) > << setFamily(LyXFont::SANS_FAMILY); > > string const justname = OnlyFilename(params_.filename); > if (!justname.empty()) { > rss << setSize(LyXFont::SIZE_FOOTNOTE) > << justname; > } > > string const msg = statusMessage(loader_.status()); > if (!msg.empty()) { > rss << setSize(LyXFont::SIZE_TINY) > << msg; > } > } > > Is this just a wild flight of fancy, or does anybody else think that > it's a sensible proposal? I think this could be handled on a case-by-case base by using some helper functions in the insets that really need it. Most insets are simple enough not to need such a thing, so any generic solution is like to complicate matters. However, we certainly _have_ a font problem. I'll ask a question in the next mail ;-} IMNSHO the optimal solution would be "font insets" but we'd need Asger's three-box model for insets implemented to go this route... > ps, current code follows... That's indeed a case that could make use a local helper function. But I don't think this very helper would be useful for, say, MathSqrtInset. Andre'