Back to index

lightning-sunbird  0.9+nobinonly
nsFontMetricsQt.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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  *   Lars Knoll <knoll@kde.org>
00024  *   Zack Rusin <zack@kde.org>
00025  *   John C. Griggs <jcgriggs@sympatico.ca>
00026  *   Jean Claude Batista <jcb@macadamian.com>
00027  *
00028  * Alternatively, the contents of this file may be used under the terms of
00029  * either the GNU General Public License Version 2 or later (the "GPL"), or
00030  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00031  * in which case the provisions of the GPL or the LGPL are applicable instead
00032  * of those above. If you wish to allow use of your version of this file only
00033  * under the terms of either the GPL or the LGPL, and not to allow others to
00034  * use your version of this file under the terms of the MPL, indicate your
00035  * decision by deleting the provisions above and replace them with the notice
00036  * and other provisions required by the GPL or the LGPL. If you do not delete
00037  * the provisions above, a recipient may use your version of this file under
00038  * the terms of any one of the MPL, the GPL or the LGPL.
00039  *
00040  * ***** END LICENSE BLOCK ***** */
00041 
00042 #ifndef nsFontMetricsQt_h__
00043 #define nsFontMetricsQt_h__
00044 
00045 #include "nsIFontMetrics.h"
00046 #include "nsIFontEnumerator.h"
00047 #include "nsIDeviceContext.h"
00048 #include "nsCRT.h"
00049 #include "nsCOMPtr.h"
00050 #include "nsICharRepresentable.h"
00051 #include "nsICharsetConverterManager.h"
00052 #include "nsVoidArray.h"
00053 #include "nsFont.h"
00054 
00055 #include <qfont.h>
00056 #include <qfontmetrics.h>
00057 
00058 class nsFont;
00059 class nsString;
00060 class nsRenderingContextQt;
00061 class nsDrawingSurfaceQt;
00062 class nsFontMetricsQt;
00063 class nsFontQtUserDefined;
00064 class QString;
00065 class QFontInfo;
00066 class QFontDatabase;
00067 
00068 #undef FONT_HAS_GLYPH
00069 #define FONT_HAS_GLYPH(map,char) IS_REPRESENTABLE(map,char)
00070 
00071 typedef struct nsFontCharSetInfo nsFontCharSetInfo;
00072 
00073 class nsFontQt
00074 {
00075 public:
00076     nsFontQt(const nsFont &afont, nsIAtom *aLangGroup, nsIDeviceContext *acontext);
00077     ~nsFontQt() {}
00078     NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW
00079 
00080     bool SupportsChar(PRUnichar c) { return QFontMetrics(font).inFont(QChar(c)); }
00081 
00082     QFont font;
00083 
00084     nsIDeviceContext *mDeviceContext;
00085     nsCOMPtr<nsIAtom> mLangGroup;
00086 
00087     nscoord          mLeading;
00088     nscoord          mEmHeight;
00089     nscoord          mEmAscent;
00090     nscoord          mEmDescent;
00091     nscoord          mMaxHeight;
00092     nscoord          mMaxAscent;
00093     nscoord          mMaxDescent;
00094     nscoord          mMaxAdvance;
00095     nscoord          mAveCharWidth;
00096     nscoord          mXHeight;
00097     nscoord          mSuperscriptOffset;
00098     nscoord          mSubscriptOffset;
00099     nscoord          mStrikeoutSize;
00100     nscoord          mStrikeoutOffset;
00101     nscoord          mUnderlineSize;
00102     nscoord          mUnderlineOffset;
00103     nscoord          mSpaceWidth;
00104 
00105     PRUint16         mPixelSize;
00106     PRUint16         mWeight;
00107 
00108     void RealizeFont();
00109 };
00110 
00111 class nsFontMetricsQt : public nsIFontMetrics
00112 {
00113 public:
00114     nsFontMetricsQt();
00115     virtual ~nsFontMetricsQt();
00116 
00117     NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW
00118 
00119     NS_DECL_ISUPPORTS
00120 
00121     NS_IMETHOD  Init(const nsFont& aFont, nsIAtom* aLangGroup,
00122                      nsIDeviceContext* aContext);
00123     NS_IMETHOD  Destroy();
00124 
00125     NS_IMETHOD  GetXHeight(nscoord& aResult);
00126     NS_IMETHOD  GetSuperscriptOffset(nscoord& aResult);
00127     NS_IMETHOD  GetSubscriptOffset(nscoord& aResult);
00128     NS_IMETHOD  GetStrikeout(nscoord& aOffset, nscoord& aSize);
00129     NS_IMETHOD  GetUnderline(nscoord& aOffset, nscoord& aSize);
00130 
00131     NS_IMETHOD  GetHeight(nscoord &aHeight);
00132     NS_IMETHOD  GetNormalLineHeight(nscoord &aHeight);
00133     NS_IMETHOD  GetLeading(nscoord &aLeading);
00134     NS_IMETHOD  GetEmHeight(nscoord &aHeight);
00135     NS_IMETHOD  GetEmAscent(nscoord &aAscent);
00136     NS_IMETHOD  GetEmDescent(nscoord &aDescent);
00137     NS_IMETHOD  GetMaxHeight(nscoord &aHeight);
00138     NS_IMETHOD  GetMaxAscent(nscoord &aAscent);
00139     NS_IMETHOD  GetMaxDescent(nscoord &aDescent);
00140     NS_IMETHOD  GetMaxAdvance(nscoord &aAdvance);
00141     NS_IMETHOD  GetAveCharWidth(nscoord &aAveCharWidth);
00142     NS_IMETHOD  GetLangGroup(nsIAtom** aLangGroup);
00143     NS_IMETHOD  GetFontHandle(nsFontHandle &aHandle);
00144 
00145     NS_IMETHOD  GetSpaceWidth(nscoord &aSpaceWidth);
00146     // No known string length limits on Qt
00147     virtual PRInt32 GetMaxStringLength() { return PR_INT32_MAX; }
00148 
00149     nsFontQt    *qFont;
00150 
00151 #if 0
00152     nsFontQt*  FindFont(PRUnichar aChar);
00153     nsFontQt*  FindUserDefinedFont(PRUnichar aChar);
00154     nsFontQt*  FindLangGroupPrefFont(nsIAtom *aLangGroup,PRUnichar aChar);
00155     nsFontQt*  FindLocalFont(PRUnichar aChar);
00156     nsFontQt*  FindGenericFont(PRUnichar aChar);
00157     nsFontQt*  FindGlobalFont(PRUnichar aChar);
00158     nsFontQt*  FindSubstituteFont(PRUnichar aChar);
00159 
00160     nsFontQt*  LookUpFontPref(nsCAutoString &aName,PRUnichar aChar);
00161     nsFontQt*  LoadFont(QString &aName,PRUnichar aChar);
00162     nsFontQt*  LoadFont(QString &aName,const QString &aCharSet,
00163                         PRUnichar aChar);
00164     QFont*     LoadQFont(QString &aName);
00165 
00166     static nsresult FamilyExists(const nsString& aFontName);
00167 
00168     PRUint16    mLoadedFontsAlloc;
00169     PRUint16    mLoadedFontsCount;
00170 
00171     nsFontQt               *mSubstituteFont;
00172     nsFontQtUserDefined    *mUserDefinedFont;
00173 
00174     nsCOMPtr<nsIAtom> mLangGroup;
00175     nsCStringArray    mFonts;
00176     PRInt32           mFontsIndex;
00177     nsVoidArray       mFontIsGeneric;
00178     nsCAutoString     mDefaultFont;
00179     nsCString         *mGeneric;
00180     nsCAutoString     mUserDefined;
00181 
00182     PRUint8 mTriedAllGenerics;
00183     PRUint8 mIsUserDefined;
00184 
00185     static QFontDatabase *GetQFontDB();
00186 
00187 protected:
00188     void RealizeFont();
00189 
00190     nsIDeviceContext *mDeviceContext;
00191     nsFont           *mFont;
00192     nsFontQt         *mWesternFont;
00193 
00194     QString          *mQStyle;
00195 
00196     QIntDict<char>   mCharSubst;
00197 
00198 
00199     static QFontDatabase    *mQFontDB;
00200 #endif
00201 };
00202 
00203 class nsFontEnumeratorQt : public nsIFontEnumerator
00204 {
00205 public:
00206   nsFontEnumeratorQt();
00207   NS_DECL_ISUPPORTS
00208   NS_DECL_NSIFONTENUMERATOR
00209 };
00210 
00211 #endif