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
|
|
|
|
|
2007-11-13 23:00:36 +00:00
|
|
|
#include "support/strfwd.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
|
|
|
*
|
2006-11-07 20:46:38 +00:00
|
|
|
* Caution: All char_type and docstring arguments of any method of this class
|
|
|
|
* are no UCS4 chars or strings if the font is a symbol font. They simply
|
|
|
|
* denote the code points of the font instead. You have to keep this in mind
|
|
|
|
* when you implement the methods in a frontend. You must not pass these
|
|
|
|
* parameters to a unicode conversion function in particular.
|
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-12-04 10:09:22 +00:00
|
|
|
class Dimension;
|
|
|
|
|
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;
|
2006-12-04 10:09:22 +00:00
|
|
|
/// return default dimension of the font.
|
|
|
|
/// \warning \c width is set to zero.
|
|
|
|
virtual Dimension const defaultDimension() const = 0;
|
2015-03-26 15:55:19 +00:00
|
|
|
/// return the em size
|
|
|
|
virtual int em() const = 0;
|
|
|
|
|
2006-12-01 16:12:24 +00:00
|
|
|
/// return the width of the char in the font
|
|
|
|
virtual int width(char_type c) 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
|
2007-02-26 15:13:08 +00:00
|
|
|
virtual int width(docstring const & s) 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;
|
2014-05-14 15:46:43 +00:00
|
|
|
/**
|
|
|
|
* return the x offset of a position in the string. The
|
|
|
|
* direction of the string is forced, and the returned value
|
|
|
|
* is from the left edge of the word, not from the start of the string.
|
|
|
|
*/
|
|
|
|
virtual int pos2x(docstring const & s, int pos, bool rtl) const = 0;
|
|
|
|
/**
|
|
|
|
* return the position in the string for a given x offset. The
|
|
|
|
* direction of the string is forced, and the returned value
|
|
|
|
* is from the left edge of the word, not from the start of the string.
|
|
|
|
* the offset x is updated to match the closest position in the string.
|
|
|
|
*/
|
|
|
|
virtual int x2pos(docstring const & s, int & x, bool rtl) const = 0;
|
2015-07-18 23:22:10 +00:00
|
|
|
/**
|
|
|
|
* Break string at width at most x.
|
|
|
|
* \return true if successful
|
|
|
|
* \param rtl is true for right-to-left layout
|
|
|
|
* \param force is false for breaking at word separator, true for
|
|
|
|
* arbitrary position.
|
|
|
|
*/
|
|
|
|
virtual bool breakAt(docstring & s, int & x, bool rtl, bool force) const = 0;
|
2006-12-04 10:09:22 +00:00
|
|
|
/// return char dimension for the font.
|
|
|
|
virtual Dimension const dimension(char_type c) 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
|
2007-11-13 23:00:36 +00:00
|
|
|
inline int maxHeight() const { return maxAscent() + maxDescent(); }
|
2006-10-07 16:15:06 +00:00
|
|
|
|
|
|
|
/// return the descent of the char in the font
|
2007-11-13 23:00:36 +00:00
|
|
|
inline int height(char_type c) const { return ascent(c) + descent(c); }
|
2006-10-07 16:15:06 +00:00
|
|
|
|
|
|
|
/// 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;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
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
|
|
|
|
2007-04-29 18:17:15 +00:00
|
|
|
class Font;
|
2007-10-28 18:51:54 +00:00
|
|
|
class FontInfo;
|
2006-10-11 17:24:46 +00:00
|
|
|
|
2007-04-26 04:02:55 +00:00
|
|
|
/// Implementation is in Application.cpp
|
2007-04-29 18:17:15 +00:00
|
|
|
frontend::FontMetrics const & theFontMetrics(Font const & f);
|
2007-10-28 18:51:54 +00:00
|
|
|
frontend::FontMetrics const & theFontMetrics(FontInfo const & fi);
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
} // namespace lyx
|
2006-10-11 17:24:46 +00:00
|
|
|
|
2002-06-11 21:44:00 +00:00
|
|
|
#endif // FONT_METRICS_H
|