Bug 1927094 - optimize lineScrollAmount so it doesn't iterate over all tabs, r=mconley
[gecko.git] / gfx / src / nsBoundingMetrics.h
blobe937dc18704d6770393931efa447456b01550d94
1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
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
9 #include "nsCoord.h"
10 #include <algorithm>
12 /* Struct used for accurate measurements of a string, in order to
13 * allow precise positioning when processing MathML. This is in its
14 * own header file because some very-widely-included headers need it
15 * but not the rest of nsFontMetrics, or vice versa.
18 struct nsBoundingMetrics {
19 ///////////
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.
38 nscoord leftBearing;
39 /* The horizontal distance from the origin of the drawing
40 operation to the left-most part of the drawn string. */
42 nscoord rightBearing;
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 */
48 nscoord ascent;
49 /* The vertical distance from the origin of the drawing
50 operation to the top-most part of the drawn string. */
52 nscoord descent;
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:
56 ascent + descent */
58 nscoord width;
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()
65 : leftBearing(0), rightBearing(0), ascent(0), descent(0), width(0) {}
67 void operator+=(const nsBoundingMetrics& bm) {
68 if (ascent + descent == 0 && rightBearing - leftBearing == 0) {
69 ascent = bm.ascent;
70 descent = bm.descent;
71 leftBearing = width + bm.leftBearing;
72 rightBearing = width + bm.rightBearing;
73 } else {
74 if (ascent < bm.ascent) ascent = bm.ascent;
75 if (descent < bm.descent) descent = bm.descent;
76 leftBearing = std::min(leftBearing, width + bm.leftBearing);
77 rightBearing = std::max(rightBearing, width + bm.rightBearing);
79 width += bm.width;
83 #endif // __nsBoundingMetrics_h