2002-06-11 21:44:00 +00:00
|
|
|
// -*- C++ -*-
|
|
|
|
/**
|
|
|
|
* \file font_metrics.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
|
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
|
|
|
|
|
|
|
class LyXFont;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A namespace holding helper functions for determining
|
|
|
|
* 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
|
|
|
*/
|
|
|
|
namespace font_metrics {
|
|
|
|
/// return the maximum ascent of the font
|
|
|
|
int maxAscent(LyXFont const & f);
|
|
|
|
/// return the maximum descent of the font
|
|
|
|
int maxDescent(LyXFont const & f);
|
2003-10-28 11:18:40 +00:00
|
|
|
/// return the maximum descent of the font
|
|
|
|
inline int maxHeight(LyXFont const & f) {
|
|
|
|
return maxAscent(f) + maxDescent(f);
|
|
|
|
}
|
2002-06-11 21:44:00 +00:00
|
|
|
/// return the ascent of the char in the font
|
2006-04-09 02:30:40 +00:00
|
|
|
int ascent(lyx::char_type c, LyXFont const & f);
|
2002-06-11 21:44:00 +00:00
|
|
|
/// return the descent of the char in the font
|
2006-04-09 02:30:40 +00:00
|
|
|
int descent(lyx::char_type c, LyXFont const & f);
|
2003-10-28 11:18:40 +00:00
|
|
|
/// return the descent of the char in the font
|
2006-08-13 22:54:59 +00:00
|
|
|
inline int height(lyx::char_type c, LyXFont const & f)
|
|
|
|
{
|
2003-10-28 11:18:40 +00:00
|
|
|
return ascent(c, f) + descent(c, f);
|
|
|
|
}
|
2002-06-11 21:44:00 +00:00
|
|
|
/// return the left bearing of the char in the font
|
2006-04-09 02:30:40 +00:00
|
|
|
int lbearing(lyx::char_type c, LyXFont const & f);
|
2002-06-11 21:44:00 +00:00
|
|
|
/// return the right bearing of the char in the font
|
2006-04-09 02:30:40 +00:00
|
|
|
int rbearing(lyx::char_type c, LyXFont const & f);
|
2003-10-28 11:18:40 +00:00
|
|
|
/// return the inner width of the char in the font
|
2006-04-09 02:30:40 +00:00
|
|
|
inline int center(lyx::char_type c, LyXFont const & f) {
|
2003-10-28 11:18:40 +00:00
|
|
|
return (rbearing(c, f) - lbearing(c, f)) / 2;
|
|
|
|
}
|
2002-06-11 21:44:00 +00:00
|
|
|
/// return the width of the string in the font
|
2006-08-13 22:54:59 +00:00
|
|
|
int width(lyx::char_type const * s, size_t n, LyXFont const & f);
|
2002-06-11 21:44:00 +00:00
|
|
|
/// return the width of the char in the font
|
2006-08-13 22:54:59 +00:00
|
|
|
inline int width(lyx::char_type c, LyXFont const & f)
|
|
|
|
{
|
|
|
|
lyx::char_type tmp[2] = { c, L'\0'};
|
|
|
|
return width(tmp, 1, f);
|
2002-06-11 21:44:00 +00:00
|
|
|
}
|
|
|
|
/// return the width of the string in the font
|
2006-08-13 22:54:59 +00:00
|
|
|
inline int width(lyx::docstring const & s, LyXFont const & f)
|
|
|
|
{
|
|
|
|
return s.empty() ? 0 : width(s.data(), s.length(), f);
|
2002-06-11 21:44:00 +00:00
|
|
|
}
|
|
|
|
/// FIXME ??
|
2006-08-13 22:54:59 +00:00
|
|
|
int signedWidth(lyx::docstring const & s, LyXFont const & f);
|
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-08-13 22:54:59 +00:00
|
|
|
void rectText(lyx::docstring const & str, LyXFont const & font,
|
2002-12-01 22:59:25 +00:00
|
|
|
int & width,
|
|
|
|
int & ascent,
|
2002-06-11 21:44:00 +00:00
|
|
|
int & descent);
|
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-08-13 22:54:59 +00:00
|
|
|
void buttonText(lyx::docstring const & str, LyXFont const & font,
|
2002-12-01 22:59:25 +00:00
|
|
|
int & width,
|
|
|
|
int & ascent,
|
2002-06-11 21:44:00 +00:00
|
|
|
int & descent);
|
2002-06-12 09:16:03 +00:00
|
|
|
}
|
2002-06-11 21:44:00 +00:00
|
|
|
|
|
|
|
#endif // FONT_METRICS_H
|