> I'd like to see a solution that doesn't require the Writers to maintain a
> running tally of which fonts are open and what order they were generated
> in.
I think I need to argue once more why having the font attributes for every
single character in the document will not cause problems for the writers. Or
in other words, why having special InsetFonts or a hierarchy of font changes is
a bad idea.
First, font attributes for every single character is obviously the best
approach for the kernel part of things: When we copy characters around, move
them, apply changes, and so on, everything is local. We do not need to
consider the context at all, because all relevant information is right at hand.
In particular, we get constant time font changes at the character level, and
also constant time font quereing.
On the other hand, using InsetFonts is not as easy to handle: When we want to
change the font of something, we have to search back until the last insetfont,
and see if we are really changing things. We suddenly have to consider the
context of text before we can do font changes. What is worse: If we copy some
text, we have to introduce an extra font inset in front of the copied text,
because otherwise font information would be lost.
The hierarchy of fonts is even worse yet. Here, we have to rebalance a tree of
nested (but at the same time, non-overlapping) font-changes everytime we want
to make a font change. Also, it suffers from the same flaw that we need to
insert extra hierarchy information when we copy some text.
Now, what remains to argue is that having the font attributes locally will not
make life difficult for the Writers. All we need is a font writing module:
class LaTeXFontWriter {
public:
LaTeXFontWriter(ostream str, LyXFont const & def_font) :
stream(str), default_font(def_font), running_font(def_font)
{ }
~LaTeXFontWriter() {
use_font(default_font);
}
void use_font(LyXFont const & font) {
if (font == running_font) {
return;
}
// Here, we have logic to determine
// which font attributes to close and
// open to get the requested font
...
stream << "<bold>";
...
stream << "<\bold\";
}
private:
ostream stream;
LyXFont default_font;
LyXFont running_font;
map<LyXFontAttribute, bool> open_attributes;
}
Now, the use_font method can use any appropriate algorithm to determine how to
implement a given font change sequence.
Obviously, it can only use the information about the previously seen font
changes as it is defined here (i.e. only font history, not font future).
I'm not sure whether this is enough to ensure optimal font changes or not, but
if it turns out that we need more information, it's simply a question about
changing the interface to use iterators instead.
Greets,
Asger