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
|
|
|
|
|
2003-10-06 15:43:21 +00:00
|
|
|
#include <string>
|
|
|
|
|
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);
|
|
|
|
/// return the ascent of the char in the font
|
|
|
|
int ascent(char c, LyXFont const & f);
|
|
|
|
/// return the descent of the char in the font
|
|
|
|
int descent(char c, LyXFont const & f);
|
|
|
|
/// return the left bearing of the char in the font
|
|
|
|
int lbearing(char c, LyXFont const & f);
|
|
|
|
/// return the right bearing of the char in the font
|
|
|
|
int rbearing(char c, LyXFont const & f);
|
|
|
|
/// return the width of the string in the font
|
|
|
|
int width(char const * s, size_t n, LyXFont const & f);
|
|
|
|
/// return the width of the char in the font
|
|
|
|
inline int width(char c, LyXFont const & f) {
|
|
|
|
return width(&c, 1, f);
|
|
|
|
}
|
|
|
|
/// return the width of the string in the font
|
2003-10-06 15:43:21 +00:00
|
|
|
inline int width(std::string const & s, LyXFont const & f) {
|
2002-06-11 21:44:00 +00:00
|
|
|
if (s.empty()) return 0;
|
|
|
|
return width(s.data(), s.length(), f);
|
|
|
|
}
|
|
|
|
/// FIXME ??
|
2003-10-06 15:43:21 +00:00
|
|
|
int signedWidth(std::string 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.
|
|
|
|
*/
|
2003-10-06 15:43:21 +00:00
|
|
|
void rectText(std::string 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.
|
|
|
|
*/
|
2003-10-06 15:43:21 +00:00
|
|
|
void buttonText(std::string 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
|