Back to index

lightning-sunbird  0.9+nobinonly
nsAFMObject.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) 1999
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 
00039 #ifndef nsAFMObject_h__
00040 #define nsAFMObject_h__ 
00041 
00042 
00043 #include "nsIFontMetrics.h"
00044 #include "nsFont.h"
00045 #include "nsString.h"
00046 #include "nsUnitConversion.h"
00047 #include "nsIDeviceContext.h"
00048 #include "nsCRT.h"
00049 
00050 class nsDeviceContextPS;
00051 
00052 
00053 // AFM Key Words
00054 typedef enum
00055 {
00056   kComment,
00057 
00058   // File structure.
00059   kStartFontMetrics,
00060   kEndFontMetrics,
00061   kStartCompFontMetrics,
00062   kEndCompFontMetrics,
00063   kStartDescendent,
00064   kEndDescendent,
00065   kStartMasterFontMetrics,
00066   kEndMasterFontMetrics,
00067 
00068   // Control information.
00069   kMetricsSets,
00070   kDescendents,
00071   kMasters,
00072   kAxes,
00073 
00074   // Global font information. 
00075   kFontName,
00076   kFullName,
00077   kFamilyName,
00078   kWeight,
00079   kFontBBox,
00080   kVersion,
00081   kNotice,
00082   kEncodingScheme,
00083   kMappingScheme,
00084   kEscChar,
00085   kCharacterSet,
00086   kCharacters,
00087   kIsBaseFont,
00088   kVVector,
00089   kIsFixedV,
00090   kCapHeight,
00091   kXHeight,
00092   kAscender,
00093   kDescender,
00094   kWeightVector,
00095   kBlendDesignPositions,
00096   kBlendDesignMap,
00097   kBlendAxisTypes,
00098 
00099 
00100   // Writing direction information. 
00101   kStartDirection,
00102   kEndDirection,
00103   kUnderlinePosition,
00104   kUnderlineThickness,
00105   kItalicAngle,
00106   kCharWidth,
00107   kIsFixedPitch,
00108 
00109   // Individual character metrics. 
00110   kStartCharMetrics,
00111   kEndCharMetrics,
00112   kC,
00113   kCH,
00114   kWX,
00115   kW0X,
00116   kW1X,
00117   kWY,
00118   kW0Y,
00119   kW1Y,
00120   kW,
00121   kW0,
00122   kW1,
00123   kVV,
00124   kN,
00125   kB,
00126   kL,
00127 
00128   // Kerning data.
00129   kStartKernData,
00130   kEndKernData,
00131   kStartTrackKern,
00132   kEndTrackKern,
00133   kTrackKern,
00134   kStartKernPairs,
00135   kEndKernPairs,
00136   kKP,
00137   kKPH,
00138   kKPX,
00139   kKPY,
00140 
00141   // Composite character data.
00142   kStartComposites,
00143   kEndComposites,
00144   kCC,
00145   kPCC,
00146 
00147   // Axis information.
00148   kStartAxis,
00149   kEndAxis,
00150   kAxisType,
00151   kAxisLabel,
00152 
00153 
00154   // Master Design Information 
00155   kStartMaster,
00156   kEndMaster
00157 
00158 } AFMKey;
00159 
00160 
00161 
00162 // Single character infor for AFM character. 
00163 struct AFM_Single_Char_Metrics
00164 {
00165 
00166   PRInt32   mCharacter_Code;      // default charcode (-1 if not encoded) 
00167   float     mW0x;                 // character width x in writing direction 0, 
00168   float     mW0y;                 // character width y in writing direction 0
00169   float     mW1x;                 // character width x in writing direction 1
00170   float     mW1y;                 // character width y in writing direction 1
00171   //char      *mName;             // character name ,  not using currently
00172   //double    mVv_x;              // local VVector x ,  not using currently
00173   //double    mVv_y;              // local VVector y ,  not using currently
00174 
00175   // character bounding box. 
00176   float     mLlx;
00177   float     mLly;
00178   float     mUrx;
00179   float     mUry;
00180 
00181   //double num_ligatures;      
00182 
00183   //AFMLigature *ligatures;
00184 };
00185 
00186 
00187 typedef struct AFM_Single_Char_Metrics  AFMscm;
00188 
00189 
00190 // Font information which we get from AFM files, this is needed for the PS output
00191 struct fontInformation
00192 {
00193   double      mFontVersion;
00194   const char *mFontName;
00195   const char *mFullName;
00196   const char *mFamilyName;
00197   const char *mWeight;
00198   float       mFontBBox_llx;
00199   float       mFontBBox_lly;
00200   float       mFontBBox_urx;
00201   float       mFontBBox_ury;
00202   const char *mVersion;
00203   char       *mNotice;         // DO NOT MAKE "const" (125341)
00204   const char *mEncodingScheme;
00205   PRInt32     mMappingScheme;
00206   PRInt32     mEscChar;
00207   const char *mCharacterSet;
00208   PRInt32     mCharacters;
00209   PRBool      mIsBaseFont;
00210   float       mVVector_0;
00211   float       mVVector_1;
00212   PRBool      mIsFixedV;
00213   float       mCapHeight;
00214   float       mXHeight;
00215   float       mAscender;
00216   float       mDescender;
00217   float       mUnderlinePosition;
00218   float       mUnderlineThickness;
00219 
00220   PRInt32     mNumCharacters;
00221   AFMscm     *mAFMCharMetrics;
00222 };
00223 
00224 
00225 typedef struct fontInformation AFMFontInformation;
00226 
00227 
00228 class nsAFMObject 
00229 {
00230 public:
00231 
00236   nsAFMObject();
00237 
00242  virtual ~nsAFMObject();
00243 
00250   void    Init(nscoord  aFontHeight);
00251 
00252 
00259   PRBool AFM_ReadFile(const nsFont &aFontName);
00260 
00268   PRInt16 CheckBasicFonts(const nsFont &aFont,PRBool aPrimaryOnly=PR_FALSE);
00269 
00276   PRInt16 CreateSubstituteFont(const nsFont &aFont);
00277 
00284   void    SetFontSize(nscoord  aFontHeight) { mFontHeight = aFontHeight; }
00285 
00286 
00295   void    GetStringWidth(const PRUnichar *aString,nscoord& aWidth,nscoord aLength);
00296 
00304   void    GetStringWidth(const char *aString,nscoord& aWidth,nscoord aLength);
00305 
00313   void    WriteFontHeaderInformation(FILE *aOutFile);
00314 
00322   void    WriteFontCharInformation(FILE *aOutFile);
00323 protected:
00324 
00330   void    GetKey(AFMKey *aTheKey);
00331 
00337   PRInt32 GetToken(void);
00338 
00344   PRInt32 MatchKey(char *aKey);
00345 
00351   PRInt32 GetLine(void);
00352 
00358   char*   GetAFMString (void);
00359 
00365   char*   GetAFMName (void); 
00366 
00372   void    GetAFMInt (PRInt32 *aInt) {GetToken();*aInt = atoi (mToken);}
00373 
00379   void    GetAFMNumber (double *aFloat){GetToken();*aFloat = atof (mToken);}
00380   void    GetAFMNumber (float  *aFloat){GetToken();*aFloat = atof (mToken);}
00381 
00387   void    GetAFMBool (PRBool *aBool);
00388 
00395   void    ReadCharMetrics (AFMFontInformation *aFontInfo,PRInt32 aNumCharacters);
00396 
00397 
00398 public:
00399   AFMFontInformation  *mPSFontInfo;
00400 
00401 
00402 protected:
00403   FILE                *mAFMFile;          // this is the AFM file we are parsing.
00404   char                mToken[256];        // Temporary storage for reading and parsing the file
00405   nscoord             mFontHeight;        // font height in twips that we are supporting.
00406                                           // XXX  This should be passed into the GetStringWidth
00407                                           // so we can have one font family support many sizes
00408 
00409 };
00410 
00411 #define NUM_KEYS (sizeof (keynames) / sizeof (struct keyname_st) - 1)
00412 
00421 struct AFM_SubstituteFonts
00422 {
00423   const char*         mPSName;
00424   const char*         mFamily;
00425   PRUint16            mWeight;
00426   PRUint8             mStyle;
00427   const AFMFontInformation* mFontInfo;
00428   const AFMscm*             mCharInfo;
00429   PRInt32             mIndex;
00430 };
00431 
00432 typedef struct AFM_SubstituteFonts  DefFonts;
00433 
00434 extern DefFonts gSubstituteFonts[];
00435 
00436 // number of supported default fonts
00437 #define NUM_AFM_FONTS 13
00438 
00439 #endif /* !nsAFMObject_h__ */
00440