/work/obj-fuzz/dist/include/nsBoundingMetrics.h
Line | Count | Source (jump to first uncovered line) |
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/. */ |
5 | | |
6 | | #ifndef __nsBoundingMetrics_h |
7 | | #define __nsBoundingMetrics_h |
8 | | |
9 | | #include "nsCoord.h" |
10 | | #include <algorithm> |
11 | | |
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. |
16 | | */ |
17 | | |
18 | | struct nsBoundingMetrics { |
19 | | |
20 | | /////////// |
21 | | // Metrics that _exactly_ enclose the text: |
22 | | |
23 | | // The character coordinate system is the one used on X Windows: |
24 | | // 1. The origin is located at the intersection of the baseline |
25 | | // with the left of the character's cell. |
26 | | // 2. All horizontal bearings are oriented from left to right. |
27 | | // 2. All horizontal bearings are oriented from left to right. |
28 | | // 3. The ascent is oriented from bottom to top (being 0 at the orgin). |
29 | | // 4. The descent is oriented from top to bottom (being 0 at the origin). |
30 | | |
31 | | // Note that Win32/Mac/PostScript use a different convention for |
32 | | // the descent (all vertical measurements are oriented from bottom |
33 | | // to top on these palatforms). Make sure to flip the sign of the |
34 | | // descent on these platforms for cross-platform compatibility. |
35 | | |
36 | | // Any of the following member variables listed here can have |
37 | | // positive or negative value. |
38 | | |
39 | | nscoord leftBearing; |
40 | | /* The horizontal distance from the origin of the drawing |
41 | | operation to the left-most part of the drawn string. */ |
42 | | |
43 | | nscoord rightBearing; |
44 | | /* The horizontal distance from the origin of the drawing |
45 | | operation to the right-most part of the drawn string. |
46 | | The _exact_ width of the string is therefore: |
47 | | rightBearing - leftBearing */ |
48 | | |
49 | | nscoord ascent; |
50 | | /* The vertical distance from the origin of the drawing |
51 | | operation to the top-most part of the drawn string. */ |
52 | | |
53 | | nscoord descent; |
54 | | /* The vertical distance from the origin of the drawing |
55 | | operation to the bottom-most part of the drawn string. |
56 | | The _exact_ height of the string is therefore: |
57 | | ascent + descent */ |
58 | | |
59 | | nscoord width; |
60 | | /* The horizontal distance from the origin of the drawing |
61 | | operation to the correct origin for drawing another string |
62 | | to follow the current one. Depending on the font, this |
63 | | could be greater than or less than the right bearing. */ |
64 | | |
65 | | nsBoundingMetrics() : leftBearing(0), rightBearing(0), |
66 | | ascent(0), descent(0), width(0) |
67 | | {} |
68 | | |
69 | | void |
70 | 0 | operator += (const nsBoundingMetrics& bm) { |
71 | 0 | if (ascent + descent == 0 && rightBearing - leftBearing == 0) { |
72 | 0 | ascent = bm.ascent; |
73 | 0 | descent = bm.descent; |
74 | 0 | leftBearing = width + bm.leftBearing; |
75 | 0 | rightBearing = width + bm.rightBearing; |
76 | 0 | } |
77 | 0 | else { |
78 | 0 | if (ascent < bm.ascent) ascent = bm.ascent; |
79 | 0 | if (descent < bm.descent) descent = bm.descent; |
80 | 0 | leftBearing = std::min(leftBearing, width + bm.leftBearing); |
81 | 0 | rightBearing = std::max(rightBearing, width + bm.rightBearing); |
82 | 0 | } |
83 | 0 | width += bm.width; |
84 | 0 | } |
85 | | }; |
86 | | |
87 | | #endif // __nsBoundingMetrics_h |