1 // This may look like C code, but it's really -*- C++ -*-
2 /*
3  * Copyright (C) 2008 Emweb bv, Herent, Belgium.
4  *
5  * See the LICENSE file for terms of use.
6  */
7 #ifndef WFONTMETRICS_H_
8 #define WFONTMETRICS_H_
9 
10 #include <Wt/WFont.h>
11 
12 namespace Wt {
13 
14 /*! \class WFontMetrics Wt/WFontMetrics.h Wt/WFontMetrics.h
15  *  \brief A value class that describes font metrics for a font.
16  *
17  * This class provides font metrics for a given font. It is returned
18  * by an implementation of WPaintDevice::fontMetrics(), and may differ
19  * between devices.
20  *
21  * All methods return pixel dimensions.
22  *
23  * \sa WPaintDevice
24  */
25 class WT_API WFontMetrics
26 {
27 public:
28   /*! \brief Creates a font metrics information object.
29    */
30   WFontMetrics(const WFont& font, double leading, double ascent,
31 	       double descent);
32 
33   /*! \brief Returns the font for which these font metrics were computed.
34    */
font()35   const WFont& font() const { return font_; }
36 
37   /*! \brief Returns the font size.
38    *
39    * This is the same as:
40    * \code
41    * font().size().sizeLength()
42    * \endcode
43    *
44    * e.g.~for a font with size set to 16px, this returns 16.
45    */
46   double size() const;
47 
48   /*! \brief Returns the font height.
49    *
50    * The font height is the total height of a text line. It is usually
51    * a bit bigger than the font size to have natural line spacing.
52    */
height()53   double height() const { return leading_ + ascent_ + descent_; }
54 
55   /*! \brief Returns the font leading length.
56    *
57    * This is vertical space provided on top of the ascent (empty space
58    * which serves as natural line spacing).
59    */
leading()60   double leading() const { return leading_; }
61 
62   /*! \brief Returns the font ascent length.
63    *
64    * This is vertical space which corresponds to the maximum height of a
65    * character over the baseline (although many fonts violate this for
66    * some glyphs).
67    */
ascent()68   double ascent() const { return ascent_; }
69 
70   /*! \brief Returns the font descent length.
71    *
72    * This is vertical space which corresponds to the maximum height of a
73    * character under the baseline (although many fonts violate this for
74    * some glyphs).
75    */
descent()76   double descent() const { return descent_; }
77 
78 private:
79   WFont font_;
80   double leading_, ascent_, descent_;
81 };
82 
83 }
84 
85 #endif // WFONT_METRICS_H_
86