On Thu, Apr 07, 2005 at 03:58:00PM +0200, Jean-Marc Lasgouttes wrote:
> >>>>> "Martin" == Martin Vermeer <[EMAIL PROTECTED]> writes:

...

> The source is full of bugs due to two persons having different idea of
> how things are supposed to work and half-implementing it[*]. This is
> where we see that we are lacking proper documentation of the kernel.
> 
> JMarc
> 
> [*] if you want to have fun, try to understand where LyXText::font_
> and LyXText::defaultfont_, which are use to resolve against in text2.C
> get initialized. Answer: it is never done! One way to solve this is to
> nuke all code that refers to them; the other is to know what they were
> good for and how to fix them. This used to use outerFont, but it is
> now commented out, killing existing functionality.

Interesting indeed.

This prompted me to look at bug 1766: Font display in insets broken.
There is also bug 1809 somewhat related: footnotes are inheriting their
parent's font (for all other insets this would be great :-). 

(And I could also refer to John's fine writeup on charstyles at bug
1056.)

Yes, this is a disaster area. I did come up with a fix  of sorts,
however, attached. It works... it really does. With a few loose ends.

1) Sometimes it doesn't draw right, i.e., the text is not in register
with either the cursor or the inset frame. This happens when creating an
empty inset and then filling it. Entering a letter, deleting it and
starting over again causes register to be restored. It must be a
refresh issue; apparently the metrics are working OK. When inserting an
inset "around" a selection this phenomenon does not happen.

2) For some reason the "stacking" of the surrounding font and the
inset-specific default font (like red latex in ERT) using
resolve/realize has, in some insets, only to be done in the metrics
method, not in draw as well. Doing it in both will lead to
misdrawings. I thoroughly don't understand this :-(

3) An unrelated issue is that inserting, by selection replacement, an
inset like Footnote or CharStyle into a sectional header, will by
default make the paragraph inside the inset also become a sectional
header (with number). Irritating but probably easy to fix.

I am not even pretending that I understand this problem field. Does
anyone else? And is this patch, trial-and-error as it is, welcome in 
1.4.0cvs?

- Martin

? insets/1799.diff
? insets/extlines-13x.diff
? insets/setpos.diff
? insets/x.diff
? insets/z.diff
Index: rowpainter.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/rowpainter.C,v
retrieving revision 1.143
diff -u -r1.143 rowpainter.C
--- rowpainter.C        22 Mar 2005 10:57:10 -0000      1.143
+++ rowpainter.C        9 Apr 2005 13:13:27 -0000
@@ -115,6 +115,9 @@
        double separator_;
        double hfill_;
        double label_hfill_;
+
+       // Hack to get 1.4cvs working
+       LyXFont font_;
 };
 
 
@@ -122,7 +125,7 @@
        LyXText const & text, pit_type pit, Row const & row, int x, int y)
        : bv_(*pi.base.bv), pain_(pi.pain), text_(text), 
pars_(text.paragraphs()),
          row_(row), pit_(pit), par_(text.paragraphs()[pit]),
-         xo_(x), yo_(y), width_(text_.width())
+         xo_(x), yo_(y), width_(text_.width()), font_(pi.base.font)
 {
        RowMetrics m = text_.computeRowMetrics(pit, row_);
        x_ = m.x + xo_;
@@ -142,7 +145,10 @@
 /// "temporary"
 LyXFont const RowPainter::getFont(pos_type pos) const
 {
-       return text_.getFont(par_, pos);
+       LyXFont lf(font_);
+       lf.reduce(LyXFont(LyXFont::ALL_SANE));
+       lf.realize(text_.getFont(par_, pos)); 
+       return lf;
 }
 
 
Index: insets/insetcharstyle.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetcharstyle.C,v
retrieving revision 1.30
diff -u -r1.30 insetcharstyle.C
--- insets/insetcharstyle.C     22 Feb 2005 13:19:11 -0000      1.30
+++ insets/insetcharstyle.C     9 Apr 2005 13:13:27 -0000
@@ -102,6 +102,8 @@
 {
        LyXFont tmpfont = mi.base.font;
        getDrawFont(mi.base.font);
+       mi.base.font.reduce(LyXFont(LyXFont::ALL_SANE));
+       mi.base.font.realize(tmpfont);
        mi.base.textwidth -= 2 * TEXT_TO_INSET_OFFSET;
        InsetText::metrics(mi, dim);
        mi.base.font = tmpfont;
Index: insets/insetert.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetert.C,v
retrieving revision 1.202
diff -u -r1.202 insetert.C
--- insets/insetert.C   3 Feb 2005 17:24:40 -0000       1.202
+++ insets/insetert.C   9 Apr 2005 13:13:27 -0000
@@ -373,6 +373,7 @@
 {
        LyXFont tmpfont = mi.base.font;
        getDrawFont(mi.base.font);
+       mi.base.font.realize(tmpfont);
        InsetCollapsable::metrics(mi, dim);
        mi.base.font = tmpfont;
        dim_ = dim;
Index: insets/insetfootlike.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetfootlike.C,v
retrieving revision 1.32
diff -u -r1.32 insetfootlike.C
--- insets/insetfootlike.C      25 Nov 2004 19:13:04 -0000      1.32
+++ insets/insetfootlike.C      9 Apr 2005 13:13:27 -0000
@@ -42,6 +42,25 @@
 }
 
 
+void InsetFootlike::metrics(MetricsInfo & mi, Dimension & dim) const
+{
+       LyXFont tmpfont = mi.base.font;
+       mi.base.font = LyXFont(LyXFont::ALL_SANE);
+       InsetCollapsable::metrics(mi, dim);
+       mi.base.font = tmpfont;
+       dim_ = dim;
+}
+
+
+void InsetFootlike::draw(PainterInfo & pi, int x, int y) const
+{
+       LyXFont tmpfont = pi.base.font;
+       pi.base.font = LyXFont(LyXFont::ALL_SANE);
+       InsetCollapsable::draw(pi, x, y);
+       pi.base.font = tmpfont;
+}
+
+
 void InsetFootlike::write(Buffer const & buf, ostream & os) const
 {
        os << getInsetName() << "\n";
Index: insets/insetfootlike.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetfootlike.h,v
retrieving revision 1.24
diff -u -r1.24 insetfootlike.h
--- insets/insetfootlike.h      25 Nov 2004 19:13:04 -0000      1.24
+++ insets/insetfootlike.h      9 Apr 2005 13:13:27 -0000
@@ -24,6 +24,10 @@
        ///
        InsetFootlike(InsetFootlike const &);
        ///
+       void metrics(MetricsInfo &, Dimension &) const;
+       ///
+       void draw(PainterInfo & pi, int x, int y) const;
+       ///
        void write(Buffer const & buf, std::ostream & os) const;
        ///
        bool insetAllowed(InsetBase::Code) const;

Attachment: pgpQtHEGIe7LG.pgp
Description: PGP signature

Reply via email to