LCOV - code coverage report
Current view: directory - gfx/src - nsDeviceContext.h (source / functions) Found Hit Coverage
Test: app.info Lines: 5 0 0.0 %
Date: 2012-06-02 Functions: 5 0 0.0 %

       1                 : /* -*- Mode: C++; 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 thebes gfx
      16                 :  *
      17                 :  * The Initial Developer of the Original Code is
      18                 :  * mozilla.org.
      19                 :  * Portions created by the Initial Developer are Copyright (C) 2005
      20                 :  * the Initial Developer. All Rights Reserved.
      21                 :  *
      22                 :  * Contributor(s):
      23                 :  *   Vladimir Vukicevic <vladimir@pobox.com>
      24                 :  *   Stuart Parmenter <pavlov@pavlov.net>
      25                 :  *
      26                 :  * Alternatively, the contents of this file may be used under the terms of
      27                 :  * either the GNU General Public License Version 2 or later (the "GPL"), or
      28                 :  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
      29                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
      30                 :  * of those above. If you wish to allow use of your version of this file only
      31                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
      32                 :  * use your version of this file under the terms of the MPL, indicate your
      33                 :  * decision by deleting the provisions above and replace them with the notice
      34                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
      35                 :  * the provisions above, a recipient may use your version of this file under
      36                 :  * the terms of any one of the MPL, the GPL or the LGPL.
      37                 :  *
      38                 :  * ***** END LICENSE BLOCK ***** */
      39                 : 
      40                 : #ifndef _NS_DEVICECONTEXT_H_
      41                 : #define _NS_DEVICECONTEXT_H_
      42                 : 
      43                 : #include "nsCOMPtr.h"
      44                 : #include "nsIDeviceContextSpec.h"
      45                 : #include "nsIScreenManager.h"
      46                 : #include "nsIWidget.h"
      47                 : #include "nsCoord.h"
      48                 : #include "gfxContext.h"
      49                 : 
      50                 : class nsIAtom;
      51                 : class nsFontCache;
      52                 : class gfxUserFontSet;
      53                 : 
      54                 : class nsDeviceContext
      55                 : {
      56                 : public:
      57                 :     nsDeviceContext();
      58                 :     ~nsDeviceContext();
      59                 : 
      60               0 :     NS_INLINE_DECL_REFCOUNTING(nsDeviceContext)
      61                 : 
      62                 :     /**
      63                 :      * Initialize the device context from a widget
      64                 :      * @param aWidget a widget to initialize the device context from
      65                 :      * @return error status
      66                 :      */
      67                 :     nsresult Init(nsIWidget *aWidget);
      68                 : 
      69                 :     /**
      70                 :      * Initialize the device context from a device context spec
      71                 :      * @param aDevSpec the specification of the printing device
      72                 :      * @return error status
      73                 :      */
      74                 :     nsresult InitForPrinting(nsIDeviceContextSpec *aDevSpec);
      75                 : 
      76                 :     /**
      77                 :      * Create a rendering context and initialize it.  Only call this
      78                 :      * method on device contexts that were initialized for printing.
      79                 :      * @param aContext out parameter for new rendering context
      80                 :      * @return error status
      81                 :      */
      82                 :     nsresult CreateRenderingContext(nsRenderingContext *&aContext);
      83                 : 
      84                 :     /**
      85                 :      * Gets the number of app units in one CSS pixel; this number is global,
      86                 :      * not unique to each device context.
      87                 :      */
      88               0 :     static PRInt32 AppUnitsPerCSSPixel() { return 60; }
      89                 : 
      90                 :     /**
      91                 :      * Gets the number of app units in one device pixel; this number
      92                 :      * is usually a factor of AppUnitsPerCSSPixel(), although that is
      93                 :      * not guaranteed.
      94                 :      */
      95               0 :     PRUint32 AppUnitsPerDevPixel() const { return mAppUnitsPerDevPixel; }
      96                 : 
      97                 :     /**
      98                 :      * Convert device pixels which is used for gfx/thebes to nearest
      99                 :      * (rounded) app units
     100                 :      */
     101                 :     nscoord GfxUnitsToAppUnits(gfxFloat aGfxUnits) const
     102                 :     { return nscoord(NS_round(aGfxUnits * AppUnitsPerDevPixel())); }
     103                 : 
     104                 :     /**
     105                 :      * Convert app units to device pixels which is used for gfx/thebes.
     106                 :      */
     107                 :     gfxFloat AppUnitsToGfxUnits(nscoord aAppUnits) const
     108                 :     { return gfxFloat(aAppUnits) / AppUnitsPerDevPixel(); }
     109                 : 
     110                 :     /**
     111                 :      * Gets the number of app units in one physical inch; this is the
     112                 :      * device's DPI times AppUnitsPerDevPixel().
     113                 :      */
     114               0 :     PRInt32 AppUnitsPerPhysicalInch() const
     115               0 :     { return mAppUnitsPerPhysicalInch; }
     116                 : 
     117                 :     /**
     118                 :      * Gets the number of app units in one CSS inch; this is
     119                 :      * 96 times AppUnitsPerCSSPixel.
     120                 :      */
     121                 :     static PRInt32 AppUnitsPerCSSInch() { return 96 * AppUnitsPerCSSPixel(); }
     122                 : 
     123                 :     /**
     124                 :      * Get the unscaled ratio of app units to dev pixels; useful if something
     125                 :      * needs to be converted from to unscaled pixels
     126                 :      */
     127                 :     PRInt32 UnscaledAppUnitsPerDevPixel() const
     128                 :     { return mAppUnitsPerDevNotScaledPixel; }
     129                 : 
     130                 :     /**
     131                 :      * Get the nsFontMetrics that describe the properties of
     132                 :      * an nsFont.
     133                 :      * @param aFont font description to obtain metrics for
     134                 :      * @param aLanguage the language of the document
     135                 :      * @param aMetrics out parameter for font metrics
     136                 :      * @param aUserFontSet user font set
     137                 :      * @return error status
     138                 :      */
     139                 :     nsresult GetMetricsFor(const nsFont& aFont, nsIAtom* aLanguage,
     140                 :                            gfxUserFontSet* aUserFontSet,
     141                 :                            nsFontMetrics*& aMetrics);
     142                 : 
     143                 :     /**
     144                 :      * Notification when a font metrics instance created for this device is
     145                 :      * about to be deleted
     146                 :      */
     147                 :     nsresult FontMetricsDeleted(const nsFontMetrics* aFontMetrics);
     148                 : 
     149                 :     /**
     150                 :      * Attempt to free up resources by flushing out any fonts no longer
     151                 :      * referenced by anything other than the font cache itself.
     152                 :      * @return error status
     153                 :      */
     154                 :     nsresult FlushFontCache();
     155                 : 
     156                 :     /**
     157                 :      * Return the bit depth of the device.
     158                 :      */
     159                 :     nsresult GetDepth(PRUint32& aDepth);
     160                 : 
     161                 :     /**
     162                 :      * Get the size of the displayable area of the output device
     163                 :      * in app units.
     164                 :      * @param aWidth out parameter for width
     165                 :      * @param aHeight out parameter for height
     166                 :      * @return error status
     167                 :      */
     168                 :     nsresult GetDeviceSurfaceDimensions(nscoord& aWidth, nscoord& aHeight);
     169                 : 
     170                 :     /**
     171                 :      * Get the size of the content area of the output device in app
     172                 :      * units.  This corresponds on a screen device, for instance, to
     173                 :      * the entire screen.
     174                 :      * @param aRect out parameter for full rect. Position (x,y) will
     175                 :      *              be (0,0) or relative to the primary monitor if
     176                 :      *              this is not the primary.
     177                 :      * @return error status
     178                 :      */
     179                 :     nsresult GetRect(nsRect& aRect);
     180                 : 
     181                 :     /**
     182                 :      * Get the size of the content area of the output device in app
     183                 :      * units.  This corresponds on a screen device, for instance, to
     184                 :      * the area reported by GetDeviceSurfaceDimensions, minus the
     185                 :      * taskbar (Windows) or menubar (Macintosh).
     186                 :      * @param aRect out parameter for client rect. Position (x,y) will
     187                 :      *              be (0,0) adjusted for any upper/left non-client
     188                 :      *              space if present or relative to the primary
     189                 :      *              monitor if this is not the primary.
     190                 :      * @return error status
     191                 :      */
     192                 :     nsresult GetClientRect(nsRect& aRect);
     193                 : 
     194                 :     /**
     195                 :      * Inform the output device that output of a document is beginning
     196                 :      * Used for print related device contexts. Must be matched 1:1 with
     197                 :      * EndDocument() or AbortDocument().
     198                 :      *
     199                 :      * @param aTitle - title of Document
     200                 :      * @param aPrintToFileName - name of file to print to, if NULL
     201                 :      * then don't print to file
     202                 :      * @param aStartPage - starting page number (must be greater than zero)
     203                 :      * @param aEndPage - ending page number (must be less than or
     204                 :      * equal to number of pages)
     205                 :      *
     206                 :      * @return error status
     207                 :      */
     208                 :     nsresult BeginDocument(PRUnichar  *aTitle,
     209                 :                            PRUnichar  *aPrintToFileName,
     210                 :                            PRInt32     aStartPage,
     211                 :                            PRInt32     aEndPage);
     212                 : 
     213                 :     /**
     214                 :      * Inform the output device that output of a document is ending.
     215                 :      * Used for print related device contexts. Must be matched 1:1 with
     216                 :      * BeginDocument()
     217                 :      * @return error status
     218                 :      */
     219                 :     nsresult EndDocument();
     220                 : 
     221                 :     /**
     222                 :      * Inform the output device that output of a document is being aborted.
     223                 :      * Must be matched 1:1 with BeginDocument()
     224                 :      * @return error status
     225                 :      */
     226                 :     nsresult AbortDocument();
     227                 : 
     228                 :     /**
     229                 :      * Inform the output device that output of a page is beginning
     230                 :      * Used for print related device contexts. Must be matched 1:1 with
     231                 :      * EndPage() and within a BeginDocument()/EndDocument() pair.
     232                 :      * @return error status
     233                 :      */
     234                 :     nsresult BeginPage();
     235                 : 
     236                 :     /**
     237                 :      * Inform the output device that output of a page is ending
     238                 :      * Used for print related device contexts. Must be matched 1:1 with
     239                 :      * BeginPage() and within a BeginDocument()/EndDocument() pair.
     240                 :      * @return error status
     241                 :      */
     242                 :     nsresult EndPage();
     243                 : 
     244                 :     /**
     245                 :      * Check to see if the DPI has changed
     246                 :      * @return whether there was actually a change in the DPI (whether
     247                 :      *         AppUnitsPerDevPixel() or AppUnitsPerPhysicalInch()
     248                 :      *         changed)
     249                 :      */
     250                 :     bool CheckDPIChange();
     251                 : 
     252                 :     /**
     253                 :      * Set the pixel scaling factor: all lengths are multiplied by this factor
     254                 :      * when we convert them to device pixels. Returns whether the ratio of
     255                 :      * app units to dev pixels changed because of the scale factor.
     256                 :      */
     257                 :     bool SetPixelScale(float aScale);
     258                 : 
     259                 :     /**
     260                 :      * True if this device context was created for printing.
     261                 :      */
     262                 :     bool IsPrinterSurface();
     263                 : 
     264                 : protected:
     265                 :     void SetDPI();
     266                 :     void ComputeClientRectUsingScreen(nsRect *outRect);
     267                 :     void ComputeFullAreaUsingScreen(nsRect *outRect);
     268                 :     void FindScreen(nsIScreen **outScreen);
     269                 :     void CalcPrintingSize();
     270                 :     void UpdateScaledAppUnits();
     271                 : 
     272                 :     nscoord  mWidth;
     273                 :     nscoord  mHeight;
     274                 :     PRUint32 mDepth;
     275                 :     PRUint32  mAppUnitsPerDevPixel;
     276                 :     PRInt32  mAppUnitsPerDevNotScaledPixel;
     277                 :     PRInt32  mAppUnitsPerPhysicalInch;
     278                 :     float    mPixelScale;
     279                 :     float    mPrintingScale;
     280                 : 
     281                 :     nsFontCache*                   mFontCache;
     282                 :     nsCOMPtr<nsIWidget>            mWidget;
     283                 :     nsCOMPtr<nsIScreenManager>     mScreenManager;
     284                 :     nsCOMPtr<nsIDeviceContextSpec> mDeviceContextSpec;
     285                 :     nsRefPtr<gfxASurface>          mPrintingSurface;
     286                 : };
     287                 : 
     288                 : #endif /* _NS_DEVICECONTEXT_H_ */

Generated by: LCOV version 1.7