LCOV - code coverage report
Current view: directory - gfx/thebes - gfxMatrix.cpp (source / functions) Found Hit Coverage
Test: app.info Lines: 68 0 0.0 %
Date: 2012-06-02 Functions: 13 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 Oracle Corporation code.
      16                 :  *
      17                 :  * The Initial Developer of the Original Code is Oracle Corporation.
      18                 :  * Portions created by the Initial Developer are Copyright (C) 2005
      19                 :  * the Initial Developer. All Rights Reserved.
      20                 :  *
      21                 :  * Contributor(s):
      22                 :  *   Stuart Parmenter <pavlov@pavlov.net>
      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                 : #include "gfxMatrix.h"
      39                 : #include "cairo.h"
      40                 : 
      41                 : #define CAIRO_MATRIX(x) reinterpret_cast<cairo_matrix_t*>((x))
      42                 : #define CONST_CAIRO_MATRIX(x) reinterpret_cast<const cairo_matrix_t*>((x))
      43                 : 
      44                 : const gfxMatrix&
      45               0 : gfxMatrix::Reset()
      46                 : {
      47               0 :     cairo_matrix_init_identity(CAIRO_MATRIX(this));
      48               0 :     return *this;
      49                 : }
      50                 : 
      51                 : const gfxMatrix&
      52               0 : gfxMatrix::Invert()
      53                 : {
      54               0 :     cairo_matrix_invert(CAIRO_MATRIX(this));
      55               0 :     return *this;
      56                 : }
      57                 : 
      58                 : const gfxMatrix&
      59               0 : gfxMatrix::Scale(gfxFloat x, gfxFloat y)
      60                 : {
      61               0 :     cairo_matrix_scale(CAIRO_MATRIX(this), x, y);
      62               0 :     return *this;
      63                 : }
      64                 : 
      65                 : const gfxMatrix&
      66               0 : gfxMatrix::Translate(const gfxPoint& pt)
      67                 : {
      68               0 :     cairo_matrix_translate(CAIRO_MATRIX(this), pt.x, pt.y);
      69               0 :     return *this;
      70                 : }
      71                 : 
      72                 : const gfxMatrix&
      73               0 : gfxMatrix::Rotate(gfxFloat radians)
      74                 : {
      75               0 :     cairo_matrix_rotate(CAIRO_MATRIX(this), radians);
      76               0 :     return *this;
      77                 : }
      78                 : 
      79                 : const gfxMatrix&
      80               0 : gfxMatrix::Multiply(const gfxMatrix& m)
      81                 : {
      82               0 :     cairo_matrix_multiply(CAIRO_MATRIX(this), CAIRO_MATRIX(this), CONST_CAIRO_MATRIX(&m));
      83               0 :     return *this;
      84                 : }
      85                 : 
      86                 : const gfxMatrix&
      87               0 : gfxMatrix::PreMultiply(const gfxMatrix& m)
      88                 : {
      89               0 :     cairo_matrix_multiply(CAIRO_MATRIX(this), CONST_CAIRO_MATRIX(&m), CAIRO_MATRIX(this));
      90               0 :     return *this;
      91                 : }
      92                 : 
      93                 : gfxPoint
      94               0 : gfxMatrix::Transform(const gfxPoint& point) const
      95                 : {
      96               0 :     gfxPoint ret = point;
      97               0 :     cairo_matrix_transform_point(CONST_CAIRO_MATRIX(this), &ret.x, &ret.y);
      98                 :     return ret;
      99                 : }
     100                 : 
     101                 : gfxSize
     102               0 : gfxMatrix::Transform(const gfxSize& size) const
     103                 : {
     104               0 :     gfxSize ret = size;
     105               0 :     cairo_matrix_transform_distance(CONST_CAIRO_MATRIX(this), &ret.width, &ret.height);
     106                 :     return ret;
     107                 : }
     108                 : 
     109                 : gfxRect
     110               0 : gfxMatrix::Transform(const gfxRect& rect) const
     111                 : {
     112               0 :     return gfxRect(Transform(rect.TopLeft()), Transform(rect.Size()));
     113                 : }
     114                 : 
     115                 : gfxRect
     116               0 : gfxMatrix::TransformBounds(const gfxRect& rect) const
     117                 : {
     118                 :     /* Code taken from cairo-matrix.c, _cairo_matrix_transform_bounding_box isn't public */
     119                 :     int i;
     120                 :     double quad_x[4], quad_y[4];
     121                 :     double min_x, max_x;
     122                 :     double min_y, max_y;
     123                 : 
     124               0 :     quad_x[0] = rect.X();
     125               0 :     quad_y[0] = rect.Y();
     126               0 :     cairo_matrix_transform_point (CONST_CAIRO_MATRIX(this), &quad_x[0], &quad_y[0]);
     127                 : 
     128               0 :     quad_x[1] = rect.XMost();
     129               0 :     quad_y[1] = rect.Y();
     130               0 :     cairo_matrix_transform_point (CONST_CAIRO_MATRIX(this), &quad_x[1], &quad_y[1]);
     131                 : 
     132               0 :     quad_x[2] = rect.X();
     133               0 :     quad_y[2] = rect.YMost();
     134               0 :     cairo_matrix_transform_point (CONST_CAIRO_MATRIX(this), &quad_x[2], &quad_y[2]);
     135                 : 
     136               0 :     quad_x[3] = rect.XMost();
     137               0 :     quad_y[3] = rect.YMost();
     138               0 :     cairo_matrix_transform_point (CONST_CAIRO_MATRIX(this), &quad_x[3], &quad_y[3]);
     139                 : 
     140               0 :     min_x = max_x = quad_x[0];
     141               0 :     min_y = max_y = quad_y[0];
     142                 : 
     143               0 :     for (i = 1; i < 4; i++) {
     144               0 :         if (quad_x[i] < min_x)
     145               0 :             min_x = quad_x[i];
     146               0 :         if (quad_x[i] > max_x)
     147               0 :             max_x = quad_x[i];
     148                 : 
     149               0 :         if (quad_y[i] < min_y)
     150               0 :             min_y = quad_y[i];
     151               0 :         if (quad_y[i] > max_y)
     152               0 :             max_y = quad_y[i];
     153                 :     }
     154                 : 
     155               0 :     return gfxRect(min_x, min_y, max_x - min_x, max_y - min_y);
     156                 : }
     157                 : 
     158                 : 
     159               0 : static void NudgeToInteger(double *aVal)
     160                 : {
     161               0 :     float f = float(*aVal);
     162               0 :     float r = NS_roundf(f);
     163               0 :     if (f == r) {
     164               0 :         *aVal = r;
     165                 :     }
     166               0 : }
     167                 : 
     168                 : void
     169               0 : gfxMatrix::NudgeToIntegers(void)
     170                 : {
     171               0 :     NudgeToInteger(&xx);
     172               0 :     NudgeToInteger(&xy);
     173               0 :     NudgeToInteger(&yx);
     174               0 :     NudgeToInteger(&yy);
     175               0 :     NudgeToInteger(&x0);
     176               0 :     NudgeToInteger(&y0);
     177               0 : }

Generated by: LCOV version 1.7