2002-06-11 21:44:00 +00:00
|
|
|
// -*- C++ -*-
|
|
|
|
/**
|
2006-10-07 16:15:06 +00:00
|
|
|
* \file FontMetrics.h
|
2002-09-05 15:14:23 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
2002-06-11 21:44:00 +00:00
|
|
|
*
|
|
|
|
* \author unknown
|
2002-12-01 22:59:25 +00:00
|
|
|
* \author John Levon
|
2006-10-07 16:15:06 +00:00
|
|
|
* \author Abdelrazak Younes
|
2002-09-05 14:10:50 +00:00
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
* Full author contact details are available in file CREDITS.
|
2002-06-11 21:44:00 +00:00
|
|
|
*/
|
2002-05-24 14:34:32 +00:00
|
|
|
|
2002-06-11 21:44:00 +00:00
|
|
|
#ifndef FONT_METRICS_H
|
|
|
|
#define FONT_METRICS_H
|
|
|
|
|
2006-09-13 21:13:49 +00:00
|
|
|
#include "support/docstring.h"
|
2003-10-06 15:43:21 +00:00
|
|
|
|
2002-06-11 21:44:00 +00:00
|
|
|
/**
|
2006-10-07 16:15:06 +00:00
|
|
|
* A class holding helper functions for determining
|
2002-06-11 21:44:00 +00:00
|
|
|
* the screen dimensions of fonts.
|
|
|
|
*
|
|
|
|
* The geometry is the standard typographical geometry,
|
|
|
|
* as follows :
|
2002-12-01 22:59:25 +00:00
|
|
|
*
|
2002-06-11 21:44:00 +00:00
|
|
|
* --------------+------------------<maxAscent
|
|
|
|
* | |
|
|
|
|
* <-------> (right bearing)
|
|
|
|
* <-> (left bearing)
|
|
|
|
* char ascent>___ |
|
2002-12-01 22:59:25 +00:00
|
|
|
* ^ oooo | oooo
|
|
|
|
* origin>____ | oo oo | oo oo
|
|
|
|
* \| oo oo | oo oo
|
|
|
|
* --------------+---ooooo--|--oooo-<baseline
|
|
|
|
* | oo |
|
|
|
|
* char | oo oo |
|
|
|
|
* descent>______| oooo |
|
2002-06-11 21:44:00 +00:00
|
|
|
* <- width ->
|
|
|
|
* --------------+----------+-------<maxDescent
|
2002-12-01 22:59:25 +00:00
|
|
|
*
|
2002-06-11 21:44:00 +00:00
|
|
|
*/
|
2006-10-07 16:15:06 +00:00
|
|
|
|
|
|
|
namespace lyx {
|
2006-10-21 00:16:43 +00:00
|
|
|
|
2006-10-07 16:15:06 +00:00
|
|
|
namespace frontend {
|
|
|
|
|
|
|
|
class FontMetrics
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual ~FontMetrics() {}
|
|
|
|
|
2002-06-11 21:44:00 +00:00
|
|
|
/// return the maximum ascent of the font
|
2006-10-07 16:15:06 +00:00
|
|
|
virtual int maxAscent() const = 0;
|
2002-06-11 21:44:00 +00:00
|
|
|
/// return the maximum descent of the font
|
2006-10-07 16:15:06 +00:00
|
|
|
virtual int maxDescent() const = 0;
|
2002-06-11 21:44:00 +00:00
|
|
|
/// return the ascent of the char in the font
|
2006-10-21 00:16:43 +00:00
|
|
|
virtual int ascent(char_type c) const = 0;
|
2003-10-28 11:18:40 +00:00
|
|
|
/// return the descent of the char in the font
|
2006-10-21 00:16:43 +00:00
|
|
|
virtual int descent(char_type c) const = 0;
|
2002-06-11 21:44:00 +00:00
|
|
|
/// return the left bearing of the char in the font
|
2006-10-21 00:16:43 +00:00
|
|
|
virtual int lbearing(char_type c) const = 0;
|
2002-06-11 21:44:00 +00:00
|
|
|
/// return the right bearing of the char in the font
|
2006-10-21 00:16:43 +00:00
|
|
|
virtual int rbearing(char_type c) const = 0;
|
2002-06-11 21:44:00 +00:00
|
|
|
/// return the width of the string in the font
|
2006-10-21 00:16:43 +00:00
|
|
|
virtual int width(char_type const * s, size_t n) const = 0;
|
2002-06-11 21:44:00 +00:00
|
|
|
/// FIXME ??
|
2006-10-21 00:16:43 +00:00
|
|
|
virtual int signedWidth(docstring const & s) const = 0;
|
2002-12-01 22:59:25 +00:00
|
|
|
/**
|
2002-06-11 21:44:00 +00:00
|
|
|
* fill in width,ascent,descent with the values for the
|
|
|
|
* given string in the font.
|
|
|
|
*/
|
2006-10-21 00:16:43 +00:00
|
|
|
virtual void rectText(docstring const & str,
|
2002-12-01 22:59:25 +00:00
|
|
|
int & width,
|
|
|
|
int & ascent,
|
2006-10-07 16:15:06 +00:00
|
|
|
int & descent) const = 0;
|
2002-12-01 22:59:25 +00:00
|
|
|
/**
|
2002-06-11 21:44:00 +00:00
|
|
|
* fill in width,ascent,descent with the values for the
|
|
|
|
* given string in the font for a button.
|
|
|
|
*/
|
2006-10-21 00:16:43 +00:00
|
|
|
virtual void buttonText(docstring const & str,
|
2002-12-01 22:59:25 +00:00
|
|
|
int & width,
|
|
|
|
int & ascent,
|
2006-10-07 16:15:06 +00:00
|
|
|
int & descent) const = 0;
|
|
|
|
|
|
|
|
/// return the maximum descent of the font
|
|
|
|
inline int maxHeight() const {
|
|
|
|
return maxAscent() + maxDescent();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// return the descent of the char in the font
|
2006-10-21 00:16:43 +00:00
|
|
|
inline int height(char_type c) const
|
2006-10-07 16:15:06 +00:00
|
|
|
{
|
|
|
|
return ascent(c) + descent(c);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// return the inner width of the char in the font
|
2006-10-21 00:16:43 +00:00
|
|
|
inline int center(char_type c) const {
|
2006-10-07 16:15:06 +00:00
|
|
|
return (rbearing(c) - lbearing(c)) / 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// return the width of the char in the font
|
2006-10-21 00:16:43 +00:00
|
|
|
inline int width(char_type c) const
|
2006-10-07 16:15:06 +00:00
|
|
|
{
|
2006-10-21 00:16:43 +00:00
|
|
|
char_type tmp[2] = { c, L'\0'};
|
2006-10-07 16:15:06 +00:00
|
|
|
return width(tmp, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// return the width of the string in the font
|
2006-10-21 00:16:43 +00:00
|
|
|
inline int width(docstring const & s) const
|
2006-10-07 16:15:06 +00:00
|
|
|
{
|
|
|
|
return s.empty() ? 0 : width(s.data(), s.length());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
2006-10-07 16:15:06 +00:00
|
|
|
} // namespace frontend
|
2002-06-11 21:44:00 +00:00
|
|
|
|
2006-10-11 17:24:46 +00:00
|
|
|
class LyXFont;
|
|
|
|
|
2006-10-14 19:58:42 +00:00
|
|
|
/// Implementation is in Application.C
|
2006-10-21 00:16:43 +00:00
|
|
|
frontend::FontMetrics const & theFontMetrics(LyXFont const & f);
|
|
|
|
|
|
|
|
} // namespace lyx
|
2006-10-11 17:24:46 +00:00
|
|
|
|
2002-06-11 21:44:00 +00:00
|
|
|
#endif // FONT_METRICS_H
|