Back to index

lightning-sunbird  0.9+nobinonly
nsDeviceContext.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *   Roland Mainz <Roland.Mainz@informatik.med.uni-giessen.de>
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either of the GNU General Public License Version 2 or later (the "GPL"),
00027  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00028  * in which case the provisions of the GPL or the LGPL are applicable instead
00029  * of those above. If you wish to allow use of your version of this file only
00030  * under the terms of either the GPL or the LGPL, and not to allow others to
00031  * use your version of this file under the terms of the MPL, indicate your
00032  * decision by deleting the provisions above and replace them with the notice
00033  * and other provisions required by the GPL or the LGPL. If you do not delete
00034  * the provisions above, a recipient may use your version of this file under
00035  * the terms of any one of the MPL, the GPL or the LGPL.
00036  *
00037  * ***** END LICENSE BLOCK ***** */
00038 
00039 #ifndef nsDeviceContext_h___
00040 #define nsDeviceContext_h___
00041 
00042 #include "nsIDeviceContext.h"
00043 #include "nsIDeviceContextSpec.h"
00044 #include "nsCOMPtr.h"
00045 #include "nsIAtom.h"
00046 #include "nsVoidArray.h"
00047 #include "nsIObserver.h"
00048 #include "nsIObserverService.h"
00049 #include "nsWeakReference.h"
00050 #include "gfxCore.h"
00051 
00052 class nsIImageRequest;
00053 class nsHashtable;
00054 
00055 class NS_GFX nsFontCache
00056 {
00057 public:
00058   nsFontCache();
00059   virtual ~nsFontCache();
00060 
00061   virtual nsresult Init(nsIDeviceContext* aContext);
00062   virtual nsresult GetDeviceContext(nsIDeviceContext *&aContext) const;
00063   virtual nsresult GetMetricsFor(const nsFont& aFont, nsIAtom* aLangGroup,
00064                                  nsIFontMetrics *&aMetrics);
00065 
00066   nsresult   FontMetricsDeleted(const nsIFontMetrics* aFontMetrics);
00067   nsresult   Compact();
00068   nsresult   Flush();
00069   /* printer device context classes may create their own
00070    * subclasses of nsFontCache (and override this method) and override 
00071    * DeviceContextImpl::CreateFontCache (see bug 81311).
00072    */
00073   virtual nsresult CreateFontMetricsInstance(nsIFontMetrics** fm);
00074   
00075 protected:
00076   nsVoidArray      mFontMetrics;
00077   nsIDeviceContext *mContext; // we do not addref this since
00078                               // ownership is implied. MMP.
00079 };
00080 
00081 #undef  IMETHOD_VISIBILITY
00082 #define IMETHOD_VISIBILITY NS_VISIBILITY_DEFAULT
00083 
00084 class NS_GFX DeviceContextImpl : public nsIDeviceContext,
00085                                  public nsIObserver,
00086                                  public nsSupportsWeakReference
00087 {
00088 public:
00089   DeviceContextImpl();
00090 
00091   NS_DECL_ISUPPORTS
00092   NS_DECL_NSIOBSERVER
00093 
00094   NS_IMETHOD  Init(nsNativeWidget aWidget);
00095 
00096   NS_IMETHOD  CreateRenderingContext(nsIView *aView, nsIRenderingContext *&aContext);
00097   NS_IMETHOD  CreateRenderingContext(nsIWidget *aWidget, nsIRenderingContext *&aContext);
00098   NS_IMETHOD  CreateRenderingContext(nsIRenderingContext *&aContext){return NS_ERROR_NOT_IMPLEMENTED;}
00099   NS_IMETHOD  CreateRenderingContext(nsIDrawingSurface* aSurface, nsIRenderingContext *&aContext);
00100   NS_IMETHOD  CreateRenderingContextInstance(nsIRenderingContext *&aContext);
00101 
00102   NS_IMETHOD  GetCanonicalPixelScale(float &aScale) const;
00103   NS_IMETHOD  SetCanonicalPixelScale(float aScale);
00104 
00105   NS_IMETHOD  GetMetricsFor(const nsFont& aFont, nsIAtom* aLangGroup,
00106                             nsIFontMetrics*& aMetrics);
00107   NS_IMETHOD  GetMetricsFor(const nsFont& aFont, nsIFontMetrics*& aMetrics);
00108 
00109   NS_IMETHOD  SetZoom(float aZoom);
00110   NS_IMETHOD  GetZoom(float &aZoom) const;
00111 
00112   NS_IMETHOD FirstExistingFont(const nsFont& aFont, nsString& aFaceName);
00113 
00114   NS_IMETHOD GetLocalFontName(const nsString& aFaceName, nsString& aLocalName,
00115                               PRBool& aAliased);
00116 
00117   NS_IMETHOD CreateFontCache();
00118   NS_IMETHOD FontMetricsDeleted(const nsIFontMetrics* aFontMetrics);
00119   NS_IMETHOD FlushFontCache(void);
00120 
00121   NS_IMETHOD GetDepth(PRUint32& aDepth);
00122 
00123   NS_IMETHOD GetPaletteInfo(nsPaletteInfo& aPaletteInfo);
00124 
00125   NS_IMETHOD PrepareDocument(PRUnichar * aTitle, 
00126                              PRUnichar*  aPrintToFileName) { return NS_OK; }
00127   NS_IMETHOD AbortDocument(void) { return NS_OK; }
00128 
00129 #ifdef NS_PRINT_PREVIEW
00130   NS_IMETHOD SetAltDevice(nsIDeviceContext* aAltDC);
00131   NS_IMETHOD GetAltDevice(nsIDeviceContext** aAltDC) { *aAltDC = mAltDC.get(); NS_IF_ADDREF(*aAltDC); return NS_OK;}
00132   NS_IMETHOD SetUseAltDC(PRUint8 aValue, PRBool aOn);
00133 #endif
00134 
00135 private:
00136   /* Helper methods for |CreateRenderingContext|&co. */
00137   nsresult InitRenderingContext(nsIRenderingContext *aContext, nsIWidget *aWindow);
00138   nsresult InitRenderingContext(nsIRenderingContext *aContext, nsIDrawingSurface* aSurface);
00139 
00140 protected:
00141   virtual ~DeviceContextImpl();
00142 
00143   void CommonInit(void);
00144   nsresult CreateIconILGroupContext();
00145   virtual nsresult CreateFontAliasTable();
00146   nsresult AliasFont(const nsString& aFont, 
00147                      const nsString& aAlias, const nsString& aAltAlias,
00148                      PRBool aForceAlias);
00149   void GetLocaleLangGroup(void);
00150 
00151   nsFontCache       *mFontCache;
00152   nsCOMPtr<nsIAtom> mLocaleLangGroup; // XXX temp fix for performance bug - erik
00153   float             mZoom;
00154   nsHashtable*      mFontAliasTable;
00155   float             mCPixelScale;
00156 
00157 #ifdef NS_PRINT_PREVIEW
00158   nsCOMPtr<nsIDeviceContext> mAltDC;
00159   PRUint8           mUseAltDC;
00160 #endif
00161 
00162 public:
00163   nsNativeWidget    mWidget;
00164 #ifdef NS_DEBUG
00165   PRBool            mInitialized;
00166 #endif
00167 };
00168 
00169 #undef  IMETHOD_VISIBILITY
00170 #define IMETHOD_VISIBILITY NS_VISIBILITY_HIDDEN
00171 
00172 #endif /* nsDeviceContext_h___ */