gfx/src/nsBoundingMetrics.h

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

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

mercurial