michael@0: /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef __nsBoundingMetrics_h michael@0: #define __nsBoundingMetrics_h michael@0: michael@0: #include "nsCoord.h" michael@0: #include michael@0: michael@0: /* Struct used for accurate measurements of a string, in order to michael@0: * allow precise positioning when processing MathML. This is in its michael@0: * own header file because some very-widely-included headers need it michael@0: * but not the rest of nsFontMetrics, or vice versa. michael@0: */ michael@0: michael@0: struct nsBoundingMetrics { michael@0: michael@0: /////////// michael@0: // Metrics that _exactly_ enclose the text: michael@0: michael@0: // The character coordinate system is the one used on X Windows: michael@0: // 1. The origin is located at the intersection of the baseline michael@0: // with the left of the character's cell. michael@0: // 2. All horizontal bearings are oriented from left to right. michael@0: // 2. All horizontal bearings are oriented from left to right. michael@0: // 3. The ascent is oriented from bottom to top (being 0 at the orgin). michael@0: // 4. The descent is oriented from top to bottom (being 0 at the origin). michael@0: michael@0: // Note that Win32/Mac/PostScript use a different convention for michael@0: // the descent (all vertical measurements are oriented from bottom michael@0: // to top on these palatforms). Make sure to flip the sign of the michael@0: // descent on these platforms for cross-platform compatibility. michael@0: michael@0: // Any of the following member variables listed here can have michael@0: // positive or negative value. michael@0: michael@0: nscoord leftBearing; michael@0: /* The horizontal distance from the origin of the drawing michael@0: operation to the left-most part of the drawn string. */ michael@0: michael@0: nscoord rightBearing; michael@0: /* The horizontal distance from the origin of the drawing michael@0: operation to the right-most part of the drawn string. michael@0: The _exact_ width of the string is therefore: michael@0: rightBearing - leftBearing */ michael@0: michael@0: nscoord ascent; michael@0: /* The vertical distance from the origin of the drawing michael@0: operation to the top-most part of the drawn string. */ michael@0: michael@0: nscoord descent; michael@0: /* The vertical distance from the origin of the drawing michael@0: operation to the bottom-most part of the drawn string. michael@0: The _exact_ height of the string is therefore: michael@0: ascent + descent */ michael@0: michael@0: nscoord width; michael@0: /* The horizontal distance from the origin of the drawing michael@0: operation to the correct origin for drawing another string michael@0: to follow the current one. Depending on the font, this michael@0: could be greater than or less than the right bearing. */ michael@0: michael@0: nsBoundingMetrics() : leftBearing(0), rightBearing(0), michael@0: ascent(0), descent(0), width(0) michael@0: {} michael@0: michael@0: void michael@0: operator += (const nsBoundingMetrics& bm) { michael@0: if (ascent + descent == 0 && rightBearing - leftBearing == 0) { michael@0: ascent = bm.ascent; michael@0: descent = bm.descent; michael@0: leftBearing = width + bm.leftBearing; michael@0: rightBearing = width + bm.rightBearing; michael@0: } michael@0: else { michael@0: if (ascent < bm.ascent) ascent = bm.ascent; michael@0: if (descent < bm.descent) descent = bm.descent; michael@0: leftBearing = std::min(leftBearing, width + bm.leftBearing); michael@0: rightBearing = std::max(rightBearing, width + bm.rightBearing); michael@0: } michael@0: width += bm.width; michael@0: } michael@0: }; michael@0: michael@0: #endif // __nsBoundingMetrics_h