Andre Poenitz wrote:
On Fri, Dec 01, 2006 at 04:12:25PM -0000, [EMAIL PROTECTED] wrote:
+int GuiFontMetrics::ascent(char_type c) const
+{
+ unsigned short val = static_cast<unsigned short>(c);
+ if (metrics_cache_[val].ascent == -1000)
+ fillCache(val);
+
+ return metrics_cache_[val].ascent
+}
How does that work with characters outside the 16 bit range?
That won't work of course. But it can be made to work with a proper
conversion from ucs4 to ucs2. Since then, I've changed this code with a
FIXME and an assertion, but because of your time shifted answering you
probably didn't see that.
Please, let's just concentrate on the 16bits range for now and make sure
that LyX is fine with that. And to answer Georg post in another thread,
I've replaced the unicode conversion with simple cast because:
1) we don't know yet how to deal with more than 16 bits char with Qt4
(yet). From my initial reading of Qt docs, this is not clear how this
could be supported and I don't have the time to investigate more.
2) the iconv conversion were awfully slow! At least on windows, so a
solution using iconv in ucs4_to_qchar() is out of the question.
IMHO a rock solid and fast LyX supporting the 16 bit range is more than
enough for 1.5. But if you or Georg want to do handle full ucs4, be my
guest.
+#ifdef USE_LYX_FONTCACHE
+ /// fill in \c metrics_cache_ at specified value.
+ void fillCache(unsigned short val) const;
/// Cache of char widths
- mutable int widthcache_[65536];
+ /** This cache adds 20Mo of memory to the LyX executable when
+ * loading UserGuide.lyx which contains a good number of fonts. If
+ * this turns out to be too much, we can switch to a \c QHash based
+ * solution.
+ **/
+ mutable CharMetrics metrics_cache_[65536];
20Mb is too expensive in my opinion. WHy don't we restrict the cache to
the ascii range?
Because there people using LyX outside of latin world? Why these people
should have a really slow LyX?
Besides...
1) this has been reduced to 10Mo now and this is number is only for a
document using lots of fonts (UserGuide.lyx), typical documents won't be
affected that much and this does not depend on the number of opened
documents.
2) The cache is enabled only on Mac and Windows. Speacking for Windows,
37 Mo when dealing with a document as complex as the UserGuide is quite
reasonable IMHO.
3) If this really is a problem, then we can switch to a QHash solution
or even the map solution used in 1.4. The speed impact is very negligible.
Modified: lyx-devel/trunk/src/dimension.h
URL: http://www.lyx.org/trac/file/lyx-devel/trunk/src/dimension.h?rev=16124
==============================================================================
--- lyx-devel/trunk/src/dimension.h (original)
+++ lyx-devel/trunk/src/dimension.h Fri Dec 1 17:12:24 2006
@@ -12,6 +12,7 @@
#ifndef DIMENSION_H
#define DIMENSION_H
+#include "support/types.h"
namespace lyx {
I am not too happy with additional includes in the basic headers.
Me neither but I wanted to fix the problem with a minimal change in the
code. As we decide that big cleanups should wait for 1.6, I think this
is a good compromise. Besises, "type.h" is only type definitions and is
already included mostly everywhere. AFAIK, basic types (POD) like
char_type cannot be forward declared but maybe I'm wrong here.
@@ -25,6 +26,8 @@
/// initialize data
Dimension(int w, int a, int d) : wid(w), asc(a), des(d) {}
+ Dimension(LyXFont const & font, char_type c) { set(font, c); }
What is wrong with the standalon function we used earlier
(mathed_char_dim or such, name could be changed, of course)
Three things:
1) It was mathed specific. This code is general and can be useful elsewhere.
2) All use of mathed_char_dim() was like this:
Dimesion dim;
mathed_char_dim(font, c, dim);
With my change, it is now only:
Dimesion dim(font, c, dim);
3) Dimension already knew about FontMetrics and LyXFont in its clear()
method.
That said, I would really prefer to let Dimension just be a simple 3-int
structure without any method and let theFontMetrics() construct that
and deliver it on demand. The last example will then become:
Dimension dim = theFontMetrics(font).dimension(c);
I guess I prefer explicit rather than implicit and using Dimension() or
mathed_char_dim() just hide what we are asking for without any reason.
Modified: lyx-devel/trunk/src/rowpainter.C
URL: http://www.lyx.org/trac/file/lyx-devel/trunk/src/rowpainter.C?rev=16124
==============================================================================
--- lyx-devel/trunk/src/rowpainter.C (original)
+++ lyx-devel/trunk/src/rowpainter.C Fri Dec 1 17:12:24 2006
@@ -949,7 +949,7 @@
rp.paintChangeBar();
if (rit == rb)
rp.paintFirst();
- rp.paintText();
+ rp.paintText();
if (rit + 1 == re)
rp.paintLast();
Why that?
There was a space in between two tabs. It's written in the log.
Abdel.