Back to index

lightning-sunbird  0.9+nobinonly
nsFontMetricsPh.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  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either of the GNU General Public License Version 2 or later (the "GPL"),
00026  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 #ifndef nsFontMetricsPh_h__
00039 #define nsFontMetricsPh_h__
00040 
00041 #include <Pt.h>
00042 
00043 #include "nsIFontMetrics.h"
00044 #include "nsIFontEnumerator.h"
00045 #include "nsFont.h"
00046 #include "nsString.h"
00047 #include "nsUnitConversion.h"
00048 #include "nsIDeviceContext.h"
00049 #include "nsCRT.h"
00050 #include "nsDeviceContextPh.h"
00051 #include "nsCOMPtr.h"
00052 
00053 class nsFontMetricsPh : public nsIFontMetrics
00054 {
00055 public:
00056   nsFontMetricsPh();
00057   virtual ~nsFontMetricsPh();
00058 
00059    NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW
00060 
00061   NS_DECL_ISUPPORTS
00062 
00063   NS_IMETHOD  Init(const nsFont& aFont, nsIAtom* aLangGroup,
00064                    nsIDeviceContext* aContext);
00065 
00066        inline
00067   NS_IMETHODIMP GetLangGroup(nsIAtom** aLangGroup)
00068               {
00069               if( !aLangGroup ) return NS_ERROR_NULL_POINTER;
00070               *aLangGroup = mLangGroup;
00071               NS_IF_ADDREF(*aLangGroup);
00072               return NS_OK;
00073               }
00074 
00075   NS_IMETHODIMP  Destroy()
00076               {
00077               mDeviceContext = nsnull;
00078               return NS_OK;
00079               }
00080 
00081   inline NS_IMETHODIMP  GetXHeight(nscoord& aResult)
00082               {
00083               aResult = mXHeight;
00084               return NS_OK;
00085               }
00086   inline NS_IMETHODIMP  GetSuperscriptOffset(nscoord& aResult)
00087               {
00088               aResult = mSuperscriptOffset;
00089               return NS_OK;
00090               }
00091   inline NS_IMETHOD  GetSubscriptOffset(nscoord& aResult)
00092               {
00093               aResult = mSubscriptOffset;
00094               return NS_OK;
00095               }
00096   inline NS_IMETHOD  GetStrikeout(nscoord& aOffset, nscoord& aSize)
00097               {
00098               aOffset = mStrikeoutOffset;
00099               aSize = mStrikeoutSize;
00100               return NS_OK;
00101               }
00102   inline NS_IMETHOD  GetUnderline(nscoord& aOffset, nscoord& aSize)
00103               {
00104               aOffset = mUnderlineOffset;
00105               aSize = mUnderlineSize;
00106               return NS_OK;
00107               }
00108 
00109   inline NS_IMETHODIMP  GetHeight(nscoord &aHeight)
00110               {
00111               aHeight = mHeight;
00112               return NS_OK;
00113               }
00114   inline NS_IMETHODIMP  GetNormalLineHeight(nscoord &aHeight)
00115               {
00116               aHeight = mEmHeight + mLeading;
00117               return NS_OK;
00118               }
00119   inline NS_IMETHODIMP  GetLeading(nscoord &aLeading)
00120               {
00121               aLeading = mLeading;
00122               return NS_OK;
00123               }
00124   inline NS_IMETHODIMP  GetEmHeight(nscoord &aHeight)
00125               {
00126               aHeight = mEmHeight;
00127               return NS_OK;
00128               }
00129   inline NS_IMETHODIMP  GetEmAscent(nscoord &aAscent)
00130               {
00131               aAscent = mEmAscent;
00132               return NS_OK;
00133               }
00134   inline NS_IMETHODIMP  GetEmDescent(nscoord &aDescent)
00135               {
00136               aDescent = mEmDescent;
00137               return NS_OK;
00138               }
00139   inline NS_IMETHODIMP  GetMaxHeight(nscoord &aHeight)
00140               {
00141               aHeight = mMaxHeight;
00142               return NS_OK;
00143               }
00144   inline NS_IMETHODIMP  GetMaxAscent(nscoord &aAscent)
00145               {
00146               aAscent = mMaxAscent;
00147               return NS_OK;
00148               }
00149   inline NS_IMETHODIMP  GetMaxDescent(nscoord &aDescent)
00150               {
00151               aDescent = mMaxDescent;
00152               return NS_OK;
00153               }
00154   inline NS_IMETHODIMP  GetMaxAdvance(nscoord &aAdvance)
00155               {
00156               aAdvance = mMaxAdvance;
00157               return NS_OK;
00158               }
00159        inline NS_IMETHODIMP  GetAveCharWidth(nscoord &aAveCharWidth)
00160               {
00161               aAveCharWidth = mAveCharWidth;
00162               return NS_OK;
00163               }
00164   inline NS_IMETHODIMP  GetFontHandle(nsFontHandle &aHandle)
00165               {
00166               aHandle = (nsFontHandle) mFontHandle;
00167               return NS_OK;
00168               }
00169   inline NS_IMETHODIMP  GetSpaceWidth(nscoord &aSpaceWidth)
00170               {
00171               aSpaceWidth = mSpaceWidth;
00172               return NS_OK;
00173               }
00174   // No known string length limits on Photon
00175   virtual PRInt32 GetMaxStringLength() { return PR_INT32_MAX; }
00176   
00177 protected:
00178   void RealizeFont();
00179 
00180   nsIDeviceContext    *mDeviceContext;
00181   char                *mFontHandle;              /* Photon Fonts are just a string */
00182   nscoord             mHeight;
00183   nscoord             mAscent;
00184   nscoord             mDescent;
00185   nscoord             mLeading;
00186   nscoord             mEmHeight;
00187   nscoord             mEmAscent;
00188   nscoord             mEmDescent;
00189   nscoord             mMaxHeight;
00190   nscoord             mMaxAscent;
00191   nscoord             mMaxDescent;
00192   nscoord             mMaxAdvance;
00193   nscoord             mXHeight;
00194   nscoord             mSuperscriptOffset;
00195   nscoord             mSubscriptOffset;
00196   nscoord             mStrikeoutSize;
00197   nscoord             mStrikeoutOffset;
00198   nscoord             mUnderlineSize;
00199   nscoord             mUnderlineOffset;
00200   nscoord             mSpaceWidth;
00201   nscoord                   mAveCharWidth;
00202   
00203   nsCOMPtr<nsIAtom>   mLangGroup;
00204 };
00205 
00206 class nsFontEnumeratorPh : public nsIFontEnumerator
00207 {
00208 public:
00209   nsFontEnumeratorPh();
00210   NS_DECL_ISUPPORTS
00211 //  NS_DECL_NSIFONTENUMERATOR
00212 
00213        inline NS_IMETHODIMP HaveFontFor(const char* aLangGroup, PRBool* aResult)
00214               {
00215                 NS_ENSURE_ARG_POINTER(aResult);
00216                 *aResult = PR_TRUE; // always return true for now.
00217                 return NS_OK;
00218               }
00219 
00220 
00221        inline NS_IMETHODIMP GetDefaultFont(const char *aLangGroup, const char *aGeneric, PRUnichar **aResult)
00222               {
00223                 // aLangGroup=null or ""  means any (i.e., don't care)
00224                 // aGeneric=null or ""  means any (i.e, don't care)
00225                 NS_ENSURE_ARG_POINTER(aResult);
00226                 *aResult = nsnull;
00227                 return NS_OK;
00228               }
00229 
00230        inline NS_IMETHODIMP UpdateFontList(PRBool *updateFontList)
00231               {
00232                 *updateFontList = PR_FALSE; // always return false for now
00233                 return NS_OK;
00234               }
00235 
00236        inline NS_IMETHODIMP EnumerateAllFonts(PRUint32* aCount, PRUnichar*** aResult)
00237               {
00238                 return EnumerateFonts( nsnull, nsnull, aCount, aResult );
00239               }
00240 
00241        NS_IMETHOD EnumerateFonts( const char* aLangGroup, const char* aGeneric,
00242                                                         PRUint32* aCount, PRUnichar*** aResult );
00243 
00244 };
00245 
00246 #endif