Back to index

lightning-sunbird  0.9+nobinonly
nsFont.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 nsFont_h___
00039 #define nsFont_h___
00040 
00041 #include "gfxCore.h"
00042 #include "nsCoord.h"
00043 #include "nsString.h"
00044 
00045 // XXX we need a method to enumerate all of the possible fonts on the
00046 // system across family, weight, style, size, etc. But not here!
00047 
00048 // Enumerator callback function. Return PR_FALSE to stop
00049 typedef PRBool (*nsFontFamilyEnumFunc)(const nsString& aFamily, PRBool aGeneric, void *aData);
00050 
00051 // IDs for generic fonts
00052 // NOTE: 0, 1 are reserved for the special IDs of the default variable
00053 // and fixed fonts in the presentation context, see nsPresContext.h
00054 const PRUint8 kGenericFont_NONE         = 0x00;
00055 // Special
00056 const PRUint8 kGenericFont_moz_variable = 0x00; // for the default variable width font
00057 const PRUint8 kGenericFont_moz_fixed    = 0x01; // our special "use the user's fixed font"
00058 // CSS
00059 const PRUint8 kGenericFont_serif        = 0x02;
00060 const PRUint8 kGenericFont_sans_serif   = 0x04;
00061 const PRUint8 kGenericFont_monospace    = 0x08;
00062 const PRUint8 kGenericFont_cursive      = 0x10;
00063 const PRUint8 kGenericFont_fantasy      = 0x20;
00064 
00065 // Font structure.
00066 struct NS_GFX nsFont {
00067   // The family name of the font
00068   nsString name;
00069 
00070   // The style of font (normal, italic, oblique)
00071   unsigned int style : 7;
00072 
00073   // Force this font to not be considered a 'generic' font, even if
00074   // the name is the same as a CSS generic font family.
00075   unsigned int systemFont : 1;
00076 
00077   // The variant of the font (normal, small-caps)
00078   PRUint8 variant : 7;
00079 
00080   // True if the character set quirks (for treatment of "Symbol",
00081   // "Wingdings", etc.) should be applied.
00082   PRPackedBool familyNameQuirks : 1;
00083 
00084   // The weight of the font (0-999)
00085   PRUint16 weight;
00086 
00087   // The decorations on the font (underline, overline,
00088   // line-through). The decorations can be binary or'd together.
00089   PRUint8 decorations;
00090 
00091   // The logical size of the font, in nscoord units
00092   nscoord size;
00093 
00094   // The aspect-value (ie., the ratio actualsize:actualxheight) that any
00095   // actual physical font created from this font structure must have when
00096   // rendering or measuring a string. A value of 0 means no adjustment
00097   // needs to be done.
00098   float sizeAdjust;
00099 
00100   // Initialize the font struct with an iso-latin1 name
00101   nsFont(const char* aName, PRUint8 aStyle, PRUint8 aVariant,
00102          PRUint16 aWeight, PRUint8 aDecoration, nscoord aSize,
00103          float aSizeAdjust=0.0f);
00104 
00105   // Initialize the font struct with a (potentially) unicode name
00106   nsFont(const nsString& aName, PRUint8 aStyle, PRUint8 aVariant,
00107          PRUint16 aWeight, PRUint8 aDecoration, nscoord aSize,
00108          float aSizeAdjust=0.0f);
00109 
00110   // Make a copy of the given font
00111   nsFont(const nsFont& aFont);
00112 
00113   nsFont();
00114   ~nsFont();
00115 
00116   PRBool operator==(const nsFont& aOther) const {
00117     return Equals(aOther);
00118   }
00119 
00120   PRBool Equals(const nsFont& aOther) const ;
00121 
00122   nsFont& operator=(const nsFont& aOther);
00123 
00124   // Utility method to interpret name string
00125   // enumerates all families specified by this font only
00126   // returns PR_TRUE if completed, PR_FALSE if stopped
00127   // enclosing quotes will be removed, and whitespace compressed (as needed)
00128   PRBool EnumerateFamilies(nsFontFamilyEnumFunc aFunc, void* aData) const;
00129   void GetFirstFamily(nsString& aFamily) const;
00130 
00131   // Utility method to return the ID of a generic font
00132   static void GetGenericID(const nsString& aGeneric, PRUint8* aID);
00133 };
00134 
00135 #define NS_FONT_STYLE_NORMAL              0
00136 #define NS_FONT_STYLE_ITALIC              1
00137 #define NS_FONT_STYLE_OBLIQUE             2
00138 
00139 #define NS_FONT_VARIANT_NORMAL            0
00140 #define NS_FONT_VARIANT_SMALL_CAPS        1
00141 
00142 #define NS_FONT_DECORATION_NONE           0x0
00143 #define NS_FONT_DECORATION_UNDERLINE      0x1
00144 #define NS_FONT_DECORATION_OVERLINE       0x2
00145 #define NS_FONT_DECORATION_LINE_THROUGH   0x4
00146 
00147 #define NS_FONT_WEIGHT_NORMAL             400
00148 #define NS_FONT_WEIGHT_BOLD               700
00149 
00150 #endif /* nsFont_h___ */