LCOV - code coverage report
Current view: directory - objdir/dist/include - nsBoundingMetrics.h (source / functions) Found Hit Coverage
Test: app.info Lines: 15 0 0.0 %
Date: 2012-06-02 Functions: 2 0 0.0 %

       1                 : /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 : /* ***** BEGIN LICENSE BLOCK *****
       3                 :  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
       4                 :  *
       5                 :  * The contents of this file are subject to the Mozilla Public License Version
       6                 :  * 1.1 (the "License"); you may not use this file except in compliance with
       7                 :  * the License. You may obtain a copy of the License at
       8                 :  * http://www.mozilla.org/MPL/
       9                 :  *
      10                 :  * Software distributed under the License is distributed on an "AS IS" basis,
      11                 :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      12                 :  * for the specific language governing rights and limitations under the
      13                 :  * License.
      14                 :  *
      15                 :  * The Original Code is mozilla.org code.
      16                 :  *
      17                 :  * The Initial Developer of the Original Code is
      18                 :  * Christopher Blizzard <blizzard@mozilla.org>.
      19                 :  * Portions created by the Initial Developer are Copyright (C) 2002
      20                 :  * the Initial Developer. All Rights Reserved.
      21                 :  *
      22                 :  * Contributor(s):
      23                 :  *
      24                 :  * Alternatively, the contents of this file may be used under the terms of
      25                 :  * either the GNU General Public License Version 2 or later (the "GPL"), or
      26                 :  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
      27                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
      28                 :  * of those above. If you wish to allow use of your version of this file only
      29                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
      30                 :  * use your version of this file under the terms of the MPL, indicate your
      31                 :  * decision by deleting the provisions above and replace them with the notice
      32                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
      33                 :  * the provisions above, a recipient may use your version of this file under
      34                 :  * the terms of any one of the MPL, the GPL or the LGPL.
      35                 :  *
      36                 :  * ***** END LICENSE BLOCK ***** */
      37                 : 
      38                 : #ifndef __nsBoundingMetrics_h
      39                 : #define __nsBoundingMetrics_h
      40                 : 
      41                 : #include "nsCoord.h"
      42                 : 
      43                 : /* Struct used for accurate measurements of a string, in order to
      44                 :  * allow precise positioning when processing MathML.  This is in its
      45                 :  * own header file because some very-widely-included headers need it
      46                 :  * but not the rest of nsFontMetrics, or vice versa.
      47                 :  */
      48                 : 
      49                 : struct nsBoundingMetrics {
      50                 : 
      51                 :     ///////////
      52                 :     // Metrics that _exactly_ enclose the text:
      53                 : 
      54                 :     // The character coordinate system is the one used on X Windows:
      55                 :     // 1. The origin is located at the intersection of the baseline
      56                 :     //    with the left of the character's cell.
      57                 :     // 2. All horizontal bearings are oriented from left to right.
      58                 :     // 2. All horizontal bearings are oriented from left to right.
      59                 :     // 3. The ascent is oriented from bottom to top (being 0 at the orgin).
      60                 :     // 4. The descent is oriented from top to bottom (being 0 at the origin).
      61                 : 
      62                 :     // Note that Win32/Mac/PostScript use a different convention for
      63                 :     // the descent (all vertical measurements are oriented from bottom
      64                 :     // to top on these palatforms). Make sure to flip the sign of the
      65                 :     // descent on these platforms for cross-platform compatibility.
      66                 : 
      67                 :     // Any of the following member variables listed here can have
      68                 :     // positive or negative value.
      69                 : 
      70                 :     nscoord leftBearing;
      71                 :     /* The horizontal distance from the origin of the drawing
      72                 :        operation to the left-most part of the drawn string. */
      73                 : 
      74                 :     nscoord rightBearing;
      75                 :     /* The horizontal distance from the origin of the drawing
      76                 :        operation to the right-most part of the drawn string.
      77                 :        The _exact_ width of the string is therefore:
      78                 :        rightBearing - leftBearing */
      79                 : 
      80                 :     nscoord ascent;
      81                 :     /* The vertical distance from the origin of the drawing
      82                 :        operation to the top-most part of the drawn string. */
      83                 : 
      84                 :     nscoord descent;
      85                 :     /* The vertical distance from the origin of the drawing
      86                 :        operation to the bottom-most part of the drawn string.
      87                 :        The _exact_ height of the string is therefore:
      88                 :        ascent + descent */
      89                 : 
      90                 :     nscoord width;
      91                 :     /* The horizontal distance from the origin of the drawing
      92                 :        operation to the correct origin for drawing another string
      93                 :        to follow the current one. Depending on the font, this
      94                 :        could be greater than or less than the right bearing. */
      95                 : 
      96               0 :     nsBoundingMetrics() : leftBearing(0), rightBearing(0),
      97               0 :                           ascent(0), descent(0), width(0)
      98               0 :     {}
      99                 : 
     100                 :     void
     101               0 :     operator += (const nsBoundingMetrics& bm) {
     102               0 :         if (ascent + descent == 0 && rightBearing - leftBearing == 0) {
     103               0 :             ascent = bm.ascent;
     104               0 :             descent = bm.descent;
     105               0 :             leftBearing = width + bm.leftBearing;
     106               0 :             rightBearing = width + bm.rightBearing;
     107                 :         }
     108                 :         else {
     109               0 :             if (ascent < bm.ascent) ascent = bm.ascent;
     110               0 :             if (descent < bm.descent) descent = bm.descent;
     111               0 :             leftBearing = NS_MIN(leftBearing, width + bm.leftBearing);
     112               0 :             rightBearing = NS_MAX(rightBearing, width + bm.rightBearing);
     113                 :         }
     114               0 :         width += bm.width;
     115               0 :     }
     116                 : };
     117                 : 
     118                 : #endif // __nsBoundingMetrics_h

Generated by: LCOV version 1.7