mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-08 10:51:03 +00:00
* GuiFontMetrics
- add constants instead of hard-coded values. - add assertions and comments for out of range values. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@16126 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
15d7c9000b
commit
5f4e6d9a7c
@ -24,15 +24,20 @@ using std::string;
|
||||
namespace lyx {
|
||||
namespace frontend {
|
||||
|
||||
namespace {
|
||||
// Used for checking initialisation state of the C-ish metrics table.
|
||||
const int BadMetrics = -1000;
|
||||
}
|
||||
|
||||
|
||||
GuiFontMetrics::GuiFontMetrics(QFont const & font)
|
||||
: metrics_(font), smallcaps_metrics_(font), smallcaps_shape_(false)
|
||||
{
|
||||
#ifdef USE_LYX_FONTCACHE
|
||||
for (int i = 0; i != 65536; ++i) {
|
||||
metrics_cache_[i].width = -1000;
|
||||
metrics_cache_[i].ascent = -1000;
|
||||
metrics_cache_[i].descent = -1000;
|
||||
for (int i = 0; i != MaxCharType; ++i) {
|
||||
metrics_cache_[i].width = BadMetrics;
|
||||
metrics_cache_[i].ascent = BadMetrics;
|
||||
metrics_cache_[i].descent = BadMetrics;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@ -193,8 +198,13 @@ void GuiFontMetrics::fillCache(unsigned short val) const
|
||||
|
||||
int GuiFontMetrics::width(char_type c) const
|
||||
{
|
||||
// FIXME: The following cast is not a real conversion but it work
|
||||
// for the ucs2 subrange of unicode. Instead of an assertion we should
|
||||
// give the metrics of some special characters that indicates that
|
||||
// its display is not supported.
|
||||
BOOST_ASSERT(c < MaxCharType);
|
||||
unsigned short val = static_cast<unsigned short>(c);
|
||||
if (metrics_cache_[val].width == -1000)
|
||||
if (metrics_cache_[val].width == BadMetrics)
|
||||
metrics_cache_[val].width = metrics_.width(QChar(val));
|
||||
|
||||
return metrics_cache_[val].width;
|
||||
@ -203,8 +213,13 @@ int GuiFontMetrics::width(char_type c) const
|
||||
|
||||
int GuiFontMetrics::ascent(char_type c) const
|
||||
{
|
||||
// FIXME: The following cast is not a real conversion but it work
|
||||
// for the ucs2 subrange of unicode. Instead of an assertion we should
|
||||
// give the metrics of some special characters that indicates that
|
||||
// its display is not supported.
|
||||
BOOST_ASSERT(c < MaxCharType);
|
||||
unsigned short val = static_cast<unsigned short>(c);
|
||||
if (metrics_cache_[val].ascent == -1000)
|
||||
if (metrics_cache_[val].ascent == BadMetrics)
|
||||
fillCache(val);
|
||||
|
||||
return metrics_cache_[val].ascent;
|
||||
@ -213,8 +228,13 @@ int GuiFontMetrics::ascent(char_type c) const
|
||||
|
||||
int GuiFontMetrics::descent(char_type c) const
|
||||
{
|
||||
// FIXME: The following cast is not a real conversion but it work
|
||||
// for the ucs2 subrange of unicode. Instead of an assertion we should
|
||||
// give the metrics of some special characters that indicates that
|
||||
// its display is not supported.
|
||||
BOOST_ASSERT(c < MaxCharType);
|
||||
unsigned short val = static_cast<unsigned short>(c);
|
||||
if (metrics_cache_[val].descent == -1000)
|
||||
if (metrics_cache_[val].descent == BadMetrics)
|
||||
fillCache(val);
|
||||
|
||||
return metrics_cache_[val].descent;
|
||||
|
@ -27,6 +27,8 @@
|
||||
namespace lyx {
|
||||
namespace frontend {
|
||||
|
||||
size_t const MaxCharType = 65536;
|
||||
|
||||
struct CharMetrics
|
||||
{
|
||||
int width;
|
||||
@ -88,7 +90,7 @@ private:
|
||||
* this turns out to be too much, we can switch to a \c QHash based
|
||||
* solution.
|
||||
**/
|
||||
mutable CharMetrics metrics_cache_[65536];
|
||||
mutable CharMetrics metrics_cache_[MaxCharType];
|
||||
#endif // USE_LYX_FONTCACHE
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user