1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef __nsBoundingMetrics_h
7 #define __nsBoundingMetrics_h
11 /* Struct used for accurate measurements of a string, in order to
12 * allow precise positioning when processing MathML. This is in its
13 * own header file because some very-widely-included headers need it
14 * but not the rest of nsFontMetrics, or vice versa.
17 struct nsBoundingMetrics
{
20 // Metrics that _exactly_ enclose the text:
22 // The character coordinate system is the one used on X Windows:
23 // 1. The origin is located at the intersection of the baseline
24 // with the left of the character's cell.
25 // 2. All horizontal bearings are oriented from left to right.
26 // 2. All horizontal bearings are oriented from left to right.
27 // 3. The ascent is oriented from bottom to top (being 0 at the orgin).
28 // 4. The descent is oriented from top to bottom (being 0 at the origin).
30 // Note that Win32/Mac/PostScript use a different convention for
31 // the descent (all vertical measurements are oriented from bottom
32 // to top on these palatforms). Make sure to flip the sign of the
33 // descent on these platforms for cross-platform compatibility.
35 // Any of the following member variables listed here can have
36 // positive or negative value.
39 /* The horizontal distance from the origin of the drawing
40 operation to the left-most part of the drawn string. */
43 /* The horizontal distance from the origin of the drawing
44 operation to the right-most part of the drawn string.
45 The _exact_ width of the string is therefore:
46 rightBearing - leftBearing */
49 /* The vertical distance from the origin of the drawing
50 operation to the top-most part of the drawn string. */
53 /* The vertical distance from the origin of the drawing
54 operation to the bottom-most part of the drawn string.
55 The _exact_ height of the string is therefore:
59 /* The horizontal distance from the origin of the drawing
60 operation to the correct origin for drawing another string
61 to follow the current one. Depending on the font, this
62 could be greater than or less than the right bearing. */
64 nsBoundingMetrics() : leftBearing(0), rightBearing(0),
65 ascent(0), descent(0), width(0)
69 operator += (const nsBoundingMetrics
& bm
) {
70 if (ascent
+ descent
== 0 && rightBearing
- leftBearing
== 0) {
73 leftBearing
= width
+ bm
.leftBearing
;
74 rightBearing
= width
+ bm
.rightBearing
;
77 if (ascent
< bm
.ascent
) ascent
= bm
.ascent
;
78 if (descent
< bm
.descent
) descent
= bm
.descent
;
79 leftBearing
= NS_MIN(leftBearing
, width
+ bm
.leftBearing
);
80 rightBearing
= NS_MAX(rightBearing
, width
+ bm
.rightBearing
);
86 #endif // __nsBoundingMetrics_h