Back to index

lightning-sunbird  0.9+nobinonly
nsXFontNormal.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ex: set tabstop=8 softtabstop=2 shiftwidth=2 expandtab: */
00003 /* ***** BEGIN LICENSE BLOCK *****
00004  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00005  *
00006  * The contents of this file are subject to the Mozilla Public License Version
00007  * 1.1 (the "License"); you may not use this file except in compliance with
00008  * the License. You may obtain a copy of the License at
00009  * http://www.mozilla.org/MPL/
00010  *
00011  * Software distributed under the License is distributed on an "AS IS" basis,
00012  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00013  * for the specific language governing rights and limitations under the
00014  * License.
00015  *
00016  * The Original Code is mozilla.org code.
00017  *
00018  * The Initial Developer of the Original Code is
00019  * Netscape Communications Corporation.
00020  * Portions created by the Initial Developer are Copyright (C) 2001
00021  * the Initial Developer. All Rights Reserved.
00022  *
00023  * Contributor(s):
00024  *   Brian Stell <bstell@netscape.com>
00025  *
00026  * Alternatively, the contents of this file may be used under the terms of
00027  * either of the GNU General Public License Version 2 or later (the "GPL"),
00028  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00029  * in which case the provisions of the GPL or the LGPL are applicable instead
00030  * of those above. If you wish to allow use of your version of this file only
00031  * under the terms of either the GPL or the LGPL, and not to allow others to
00032  * use your version of this file under the terms of the MPL, indicate your
00033  * decision by deleting the provisions above and replace them with the notice
00034  * and other provisions required by the GPL or the LGPL. If you do not delete
00035  * the provisions above, a recipient may use your version of this file under
00036  * the terms of any one of the MPL, the GPL or the LGPL.
00037  *
00038  * ***** END LICENSE BLOCK ***** */
00039 
00040 #include "gfx-config.h"
00041 #include "nscore.h"
00042 #include "nsXFontNormal.h"
00043 #include "nsRenderingContextGTK.h"
00044 #include "nsGdkUtils.h"
00045 
00046 void
00047 nsXFontNormal::DrawText8(GdkDrawable *aDrawable, GdkGC *aGC,
00048                          PRInt32 aX, PRInt32 aY,
00049                         const char *aString, PRUint32 aLength)
00050 {
00051   my_gdk_draw_text(aDrawable, mGdkFont, aGC, aX, aY, aString, aLength);
00052 }
00053 
00054 void
00055 nsXFontNormal::DrawText16(GdkDrawable *aDrawable, GdkGC *aGC,
00056                          PRInt32 aX, PRInt32 aY,
00057                         const XChar2b *aString, PRUint32 aLength)
00058 {
00059   my_gdk_draw_text(aDrawable, mGdkFont, aGC, aX, aY,
00060                    (const char *)aString, aLength*2);
00061 }
00062 
00063 PRBool
00064 nsXFontNormal::GetXFontProperty(Atom aAtom, unsigned long *aValue)
00065 {
00066   NS_ASSERTION(mGdkFont, "GetXFontProperty called before font loaded");
00067   if (mGdkFont==nsnull)
00068     return PR_FALSE;
00069 
00070   XFontStruct *fontInfo = (XFontStruct *)GDK_FONT_XFONT(mGdkFont);
00071 
00072   return ::XGetFontProperty(fontInfo, aAtom, aValue);
00073 }
00074 
00075 XFontStruct *
00076 nsXFontNormal::GetXFontStruct()
00077 {
00078   NS_ASSERTION(mGdkFont, "GetXFontStruct called before font loaded");
00079   if (mGdkFont==nsnull)
00080     return nsnull;
00081 
00082   return (XFontStruct *)GDK_FONT_XFONT(mGdkFont);
00083 }
00084 
00085 PRBool
00086 nsXFontNormal::LoadFont()
00087 {
00088   if (!mGdkFont)
00089     return PR_FALSE;
00090   XFontStruct *fontInfo = (XFontStruct *)GDK_FONT_XFONT(mGdkFont);
00091   mIsSingleByte = (fontInfo->min_byte1 == 0) && (fontInfo->max_byte1 == 0);
00092   return PR_TRUE;
00093 }
00094 
00095 nsXFontNormal::nsXFontNormal(GdkFont *aGdkFont)
00096 {
00097   mGdkFont = ::gdk_font_ref(aGdkFont);
00098 }
00099 
00100 void
00101 nsXFontNormal::TextExtents8(const char *aString, PRUint32 aLength,
00102                             PRInt32* aLBearing, PRInt32* aRBearing,
00103                             PRInt32* aWidth, PRInt32* aAscent,
00104                             PRInt32* aDescent)
00105 {
00106   gdk_text_extents(mGdkFont, aString, aLength,
00107                     aLBearing, aRBearing, aWidth, aAscent, aDescent);
00108 }
00109 
00110 void
00111 nsXFontNormal::TextExtents16(const XChar2b *aString, PRUint32 aLength,
00112                             PRInt32* aLBearing, PRInt32* aRBearing,
00113                             PRInt32* aWidth, PRInt32* aAscent,
00114                             PRInt32* aDescent)
00115 {
00116   gdk_text_extents(mGdkFont, (const char *)aString, aLength*2,
00117                     aLBearing, aRBearing, aWidth, aAscent, aDescent);
00118 }
00119 
00120 PRInt32
00121 nsXFontNormal::TextWidth8(const char *aString, PRUint32 aLength)
00122 {
00123   NS_ASSERTION(mGdkFont, "TextWidth8 called before font loaded");
00124   if (mGdkFont==nsnull)
00125     return 0;
00126   PRInt32 width = gdk_text_width(mGdkFont, aString, aLength);
00127   return width;
00128 }
00129 
00130 PRInt32
00131 nsXFontNormal::TextWidth16(const XChar2b *aString, PRUint32 aLength)
00132 {
00133   NS_ASSERTION(mGdkFont, "TextWidth16 called before font loaded");
00134   if (mGdkFont==nsnull)
00135     return 0;
00136   PRInt32 width = gdk_text_width(mGdkFont, (const char *)aString, aLength*2);
00137   return width;
00138 }
00139 
00140 void
00141 nsXFontNormal::UnloadFont()
00142 {
00143   delete this;
00144 }
00145 
00146 nsXFontNormal::~nsXFontNormal()
00147 {
00148   if (mGdkFont) {
00149     ::gdk_font_unref(mGdkFont);
00150   }
00151 }
00152