Bug #126919. Xft support. r=rbs, sr=dbaron a=roc,shaver,others

This commit is contained in:
blizzard%redhat.com 2002-10-12 02:03:34 +00:00
Родитель 78963a5459
Коммит 7163120165
16 изменённых файлов: 4002 добавлений и 1230 удалений

Просмотреть файл

@ -69,13 +69,10 @@ X11SHARED_LCPPSRCS = \
$(NULL)
CPPSRCS = \
$(X11SHARED_LCPPSRCS) \
nsDeviceContextGTK.cpp \
nsDeviceContextSpecFactoryG.cpp \
nsDeviceContextSpecG.cpp \
nsDrawingSurfaceGTK.cpp \
nsFontMetricsGTK.cpp \
nsGdkUtils.cpp \
nsGfxFactoryGTK.cpp \
nsGraphicsStateGTK.cpp \
nsImageGTK.cpp \
@ -84,8 +81,21 @@ CPPSRCS = \
nsScreenGtk.cpp \
nsScreenManagerGtk.cpp \
nsPrintOptionsGTK.cpp \
nsFontMetricsUtils.cpp \
$(NULL)
ifdef MOZ_ENABLE_COREXFONTS
CPPSRCS += \
$(X11SHARED_LCPPSRCS) \
nsFontMetricsGTK.cpp \
nsGdkUtils.cpp
endif
ifdef MOZ_ENABLE_XFT
CPPSRCS += \
nsFontMetricsXft.cpp
endif
ifdef MOZ_ENABLE_GTK
CPPSRCS += \
nsRegionGTK.cpp \
@ -142,9 +152,9 @@ EXTRA_DSO_LDOPTS += $(MOZ_COMPONENT_LIBS) \
$(NULL)
endif
EXTRA_DSO_LDOPTS += $(MOZ_GTK_LDFLAGS) $(MOZ_GTK2_LIBS)
CXXFLAGS += $(MOZ_GTK_CFLAGS) $(MOZ_GTK2_CFLAGS)
CFLAGS += $(MOZ_GTK_CFLAGS) $(MOZ_GTK2_CFLAGS)
EXTRA_DSO_LDOPTS += $(MOZ_GTK_LDFLAGS) $(MOZ_XFT_LIBS) $(MOZ_GTK2_LIBS)
CXXFLAGS += $(MOZ_XFT_CFLAGS) $(MOZ_GTK_CFLAGS) $(MOZ_GTK2_CFLAGS)
CFLAGS += $(MOZ_XFT_CFLAGS) $(MOZ_GTK_CFLAGS) $(MOZ_GTK2_CFLAGS)
ifdef MOZ_ENABLE_XINERAMA
GFX_XINERAMA_LIBS += $(MOZ_XINERAMA_LIBS)

Просмотреть файл

@ -46,7 +46,6 @@
#include "nsCRT.h"
#include "nsDeviceContextGTK.h"
#include "nsFontMetricsGTK.h"
#include "nsGfxCIID.h"
#ifdef USE_POSTSCRIPT
@ -58,6 +57,8 @@
#include "nsIDeviceContextXPrint.h"
#endif /* USE_XPRINT */
#include "nsFontMetricsUtils.h"
#include <gdk/gdk.h>
#include <gdk/gdkx.h>
@ -69,11 +70,6 @@
#include "nsDeviceContextSpecG.h"
#define NS_TO_GDK_RGB(ns) (ns & 0xff) << 16 | (ns & 0xff00) | ((ns >> 16) & 0xff)
#define GDK_COLOR_TO_NS_RGB(c) \
((nscolor) NS_RGB(c.red, c.green, c.blue))
static NS_DEFINE_CID(kPrefCID, NS_PREF_CID);
#define GDK_DEFAULT_FONT1 "-*-helvetica-medium-r-*--*-120-*-*-*-*-iso8859-1"
@ -445,7 +441,7 @@ NS_IMETHODIMP nsDeviceContextGTK::ConvertPixel(nscolor aColor,
NS_IMETHODIMP nsDeviceContextGTK::CheckFontExistence(const nsString& aFontName)
{
return nsFontMetricsGTK::FamilyExists(this, aFontName);
return NS_FontMetricsFamilyExists(this, aFontName);
}
NS_IMETHODIMP nsDeviceContextGTK::GetDeviceSurfaceDimensions(PRInt32 &aWidth, PRInt32 &aHeight)

Просмотреть файл

@ -119,5 +119,13 @@ private:
nsresult GetSystemFontInfo(GdkFont* iFont, nsSystemFontID anID, nsFont* aFont) const;
};
// used by several files
#define NS_TO_GDK_RGB(ns) \
((ns & 0xff) << 16 | (ns & 0xff00) | ((ns >> 16) & 0xff))
#define GDK_COLOR_TO_NS_RGB(c) \
((nscolor) NS_RGB(c.red, c.green, c.blue))
#endif /* nsDeviceContextGTK_h___ */

Просмотреть файл

@ -49,6 +49,10 @@ NS_IMPL_ISUPPORTS1(nsDrawingSurfaceGTK, nsIDrawingSurface)
static PRTime mLockTime, mUnlockTime;
#endif
#ifdef MOZ_ENABLE_XFT
#include <X11/Xft/Xft.h>
#endif
nsDrawingSurfaceGTK :: nsDrawingSurfaceGTK()
{
NS_INIT_ISUPPORTS();
@ -89,6 +93,10 @@ nsDrawingSurfaceGTK :: nsDrawingSurfaceGTK()
mPixFormat.mAlphaShift = 0;
mDepth = v->depth;
#ifdef MOZ_ENABLE_XFT
mXftDraw = nsnull;
#endif
}
nsDrawingSurfaceGTK :: ~nsDrawingSurfaceGTK()
@ -101,6 +109,11 @@ nsDrawingSurfaceGTK :: ~nsDrawingSurfaceGTK()
if (mGC)
gdk_gc_unref(mGC);
#ifdef MOZ_ENABLE_XFT
if (mXftDraw)
XftDrawDestroy(mXftDraw);
#endif
}
/**
@ -310,6 +323,31 @@ nsresult nsDrawingSurfaceGTK :: Init(GdkGC *aGC, PRUint32 aWidth,
return mPixmap ? NS_OK : NS_ERROR_FAILURE;
}
#ifdef MOZ_ENABLE_XFT
XftDraw *nsDrawingSurfaceGTK :: GetXftDraw(void)
{
if (!mXftDraw) {
mXftDraw = XftDrawCreate(GDK_DISPLAY(), GDK_WINDOW_XWINDOW(mPixmap),
GDK_VISUAL_XVISUAL(::gdk_rgb_get_visual()),
GDK_COLORMAP_XCOLORMAP(::gdk_rgb_get_cmap()));
}
return mXftDraw;
}
void nsDrawingSurfaceGTK :: GetLastXftClip(nsIRegion **aLastRegion)
{
*aLastRegion = mLastXftClip.get();
NS_IF_ADDREF(*aLastRegion);
}
void nsDrawingSurfaceGTK :: SetLastXftClip(nsIRegion *aLastRegion)
{
mLastXftClip = aLastRegion;
}
#endif /* MOZ_ENABLE_XFT */
/* inline */
PRUint8
nsDrawingSurfaceGTK::ConvertMaskToCount(unsigned long val)

Просмотреть файл

@ -42,9 +42,15 @@
#include "nsIDrawingSurface.h"
#include "nsTimer.h"
#include "nsIRegion.h"
#include "nsCOMPtr.h"
#include <gtk/gtk.h>
#ifdef MOZ_ENABLE_XFT
typedef struct _XftDraw XftDraw;
#endif
class nsDrawingSurfaceGTK : public nsIDrawingSurface
{
public:
@ -102,6 +108,12 @@ public:
PRInt32 GetDepth() { return mDepth; }
#ifdef MOZ_ENABLE_XFT
XftDraw *GetXftDraw (void);
void GetLastXftClip (nsIRegion **aLastRegion);
void SetLastXftClip (nsIRegion *aLastRegion);
#endif /* MOZ_ENABLE_XFT */
protected:
inline PRUint8 ConvertMaskToCount(unsigned long val);
@ -125,6 +137,11 @@ private:
PRUint32 mLockFlags;
PRBool mLocked;
#ifdef MOZ_ENABLE_XFT
XftDraw *mXftDraw;
nsCOMPtr<nsIRegion> mLastXftClip;
#endif
// MOZ_TIMER_DECLARE(mLockTime)
// MOZ_TIMER_DECLARE(mUnlockTime)
};

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -51,6 +51,7 @@
#include "nsRenderingContextGTK.h"
#include "nsICharRepresentable.h"
#include "nsCompressedCharMap.h"
#include "nsIFontMetricsGTK.h"
#include <gdk/gdk.h>
#include <gdk/gdkx.h>
@ -75,6 +76,7 @@ class nsXFont;
class nsFontGTKUserDefined;
class nsFontMetricsGTK;
class nsFreeTypeFace;
class nsFontGTK;
struct nsFontStretch
{
@ -218,7 +220,7 @@ typedef PRBool (*PR_CALLBACK nsFontSwitchCallbackGTK)
PRUint32 aSubstringLength,
void *aData);
class nsFontMetricsGTK : public nsIFontMetrics
class nsFontMetricsGTK : public nsIFontMetricsGTK
{
public:
nsFontMetricsGTK();
@ -282,7 +284,65 @@ public:
PRUnichar aChar,
const char *aName);
// nsIFontMetricsGTK (calls from the font rendering layer)
virtual nsresult GetWidth(const char* aString, PRUint32 aLength,
nscoord& aWidth,
nsRenderingContextGTK *aContext);
virtual nsresult GetWidth(const PRUnichar* aString, PRUint32 aLength,
nscoord& aWidth, PRInt32 *aFontID,
nsRenderingContextGTK *aContext);
virtual nsresult GetTextDimensions(const PRUnichar* aString,
PRUint32 aLength,
nsTextDimensions& aDimensions,
PRInt32* aFontID,
nsRenderingContextGTK *aContext);
virtual nsresult GetTextDimensions(const char* aString,
PRInt32 aLength,
PRInt32 aAvailWidth,
PRInt32* aBreaks,
PRInt32 aNumBreaks,
nsTextDimensions& aDimensions,
PRInt32& aNumCharsFit,
nsTextDimensions& aLastWordDimensions,
PRInt32* aFontID,
nsRenderingContextGTK *aContext);
virtual nsresult GetTextDimensions(const PRUnichar* aString,
PRInt32 aLength,
PRInt32 aAvailWidth,
PRInt32* aBreaks,
PRInt32 aNumBreaks,
nsTextDimensions& aDimensions,
PRInt32& aNumCharsFit,
nsTextDimensions& aLastWordDimensions,
PRInt32* aFontID,
nsRenderingContextGTK *aContext);
virtual nsresult DrawString(const char *aString, PRUint32 aLength,
nscoord aX, nscoord aY,
const nscoord* aSpacing,
nsRenderingContextGTK *aContext,
nsDrawingSurfaceGTK *aSurface);
virtual nsresult DrawString(const PRUnichar* aString, PRUint32 aLength,
nscoord aX, nscoord aY,
PRInt32 aFontID,
const nscoord* aSpacing,
nsRenderingContextGTK *aContext,
nsDrawingSurfaceGTK *aSurface);
virtual nsresult GetBoundingMetrics(const char *aString, PRUint32 aLength,
nsBoundingMetrics &aBoundingMetrics,
nsRenderingContextGTK *aContext);
virtual nsresult GetBoundingMetrics(const PRUnichar *aString,
PRUint32 aLength,
nsBoundingMetrics &aBoundingMetrics,
PRInt32 *aFontID,
nsRenderingContextGTK *aContext);
virtual GdkFont* GetCurrentGDKFont(void);
static nsresult FamilyExists(nsIDeviceContext *aDevice, const nsString& aName);
static PRUint32 GetHints(void);
//friend struct nsFontGTK;
@ -311,6 +371,7 @@ protected:
nsIDeviceContext *mDeviceContext;
nsFont *mFont;
nsFontGTK *mWesternFont;
nsFontGTK *mCurrentFont;
nscoord mLeading;
nscoord mEmHeight;

Просмотреть файл

@ -0,0 +1,123 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* vim:expandtab:shiftwidth=4:tabstop=4:
*/
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code Christopher Blizzard
* <blizzard@mozilla.org>. Portions created by the Initial Developer
* are Copyright (C) 2002 the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
// welcome to the dumping ground for font metrics stuff that has to
// know about both the xft and core fonts code.
#ifdef MOZ_ENABLE_XFT
#include "nsFontMetricsXft.h"
#include "nsIPref.h"
#include "nsIServiceManagerUtils.h"
#include "prenv.h"
#endif /* MOZ_ENABLE_XFT */
#ifdef MOZ_ENABLE_COREXFONTS
#include "nsFontMetricsGTK.h"
#endif
#include "nsFontMetricsUtils.h"
PRUint32
NS_FontMetricsGetHints(void)
{
#ifdef MOZ_ENABLE_XFT
if (NS_IsXftEnabled()) {
return nsFontMetricsXft::GetHints();
}
#endif
#ifdef MOZ_ENABLE_COREXFONTS
return nsFontMetricsGTK::GetHints();
#endif
}
nsresult
NS_FontMetricsFamilyExists(nsIDeviceContext *aDevice, const nsString &aName)
{
#ifdef MOZ_ENABLE_XFT
// try to fall through to the core fonts if xft fails
if (NS_IsXftEnabled()) {
return nsFontMetricsXft::FamilyExists(aDevice, aName);
}
#endif
#ifdef MOZ_ENABLE_COREXFONTS
return nsFontMetricsGTK::FamilyExists(aDevice, aName);
#endif
}
#ifdef MOZ_ENABLE_XFT
PRBool
NS_IsXftEnabled(void)
{
static PRBool been_here = PR_FALSE;
static PRBool cachedXftSetting = PR_TRUE;
if (!been_here) {
been_here = PR_TRUE;
nsCOMPtr<nsIPref> prefService;
prefService = do_GetService(NS_PREF_CONTRACTID);
if (!prefService)
return PR_TRUE;
nsresult rv;
rv = prefService->GetBoolPref("fonts.xft.enabled", &cachedXftSetting);
// Yes, this makes sense. If xft is compiled in and there's no
// pref, it's automatically enabled. If there's no pref, check
// the environment.
if (NS_FAILED(rv)) {
char *val = PR_GetEnv("GDK_USE_XFT");
if (val && val[0] == '0') {
cachedXftSetting = PR_FALSE;
goto end;
}
cachedXftSetting = PR_TRUE;
}
}
end:
return cachedXftSetting;
}
#endif /* MOZ_ENABLE_XFT */

Просмотреть файл

@ -0,0 +1,50 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* vim:expandtab:shiftwidth=4:tabstop=4:
*/
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code Christopher Blizzard
* <blizzard@mozilla.org>. Portions created by the Initial Developer
* are Copyright (C) 2002 the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef __nsFontMetricsUtils_h
#define __nsFontMetricsUtils_h
extern PRUint32 NS_FontMetricsGetHints (void);
extern nsresult NS_FontMetricsFamilyExists(nsIDeviceContext *aDevice,
const nsString &aName);
#ifdef MOZ_ENABLE_XFT
extern PRBool NS_IsXftEnabled(void);
#endif
#endif /* __nsFontMetricsUtils_h */

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -0,0 +1,282 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* vim:expandtab:shiftwidth=4:tabstop=4:
*/
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code Christopher Blizzard
* <blizzard@mozilla.org>. Portions created by the Initial Developer
* are Copyright (C) 2002 the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsIFontMetrics.h"
#include "nsIFontEnumerator.h"
#include "nsCRT.h"
#include "nsIAtom.h"
#include "nsString.h"
#include "nsVoidArray.h"
#include "nsIFontMetricsGTK.h"
#include <X11/Xlib.h>
#include <X11/Xdefs.h>
#include <X11/Xft/Xft.h>
class nsFontXft;
class nsFontMetricsXft : public nsIFontMetricsGTK
{
public:
nsFontMetricsXft();
virtual ~nsFontMetricsXft();
NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW
// nsISupports
NS_DECL_ISUPPORTS
// nsIFontMetrics
NS_IMETHOD Init (const nsFont& aFont, nsIAtom* aLangGroup,
nsIDeviceContext *aContext);
NS_IMETHOD Destroy();
NS_IMETHOD GetFont (const nsFont *&aFont);
NS_IMETHOD GetLangGroup (nsIAtom** aLangGroup);
NS_IMETHOD GetFontHandle (nsFontHandle &aHandle);
NS_IMETHOD GetXHeight (nscoord& aResult)
{ aResult = mXHeight; return NS_OK; };
NS_IMETHOD GetSuperscriptOffset (nscoord& aResult)
{ aResult = mSuperscriptOffset;
return NS_OK; };
NS_IMETHOD GetSubscriptOffset (nscoord& aResult)
{ aResult = mSubscriptOffset;
return NS_OK; };
NS_IMETHOD GetStrikeout (nscoord& aOffset, nscoord& aSize)
{ aOffset = mStrikeoutOffset;
aSize = mStrikeoutSize;
return NS_OK; };
NS_IMETHOD GetUnderline (nscoord& aOffset, nscoord& aSize)
{ aOffset = mUnderlineOffset;
aSize = mUnderlineSize;
return NS_OK; };
NS_IMETHOD GetHeight (nscoord &aHeight)
{ aHeight = mMaxHeight;
return NS_OK; };
NS_IMETHOD GetNormalLineHeight (nscoord &aHeight)
{ aHeight = mEmHeight + mLeading;
return NS_OK; };
NS_IMETHOD GetLeading (nscoord &aLeading)
{ aLeading = mLeading;
return NS_OK; };
NS_IMETHOD GetEmHeight (nscoord &aHeight)
{ aHeight = mEmHeight;
return NS_OK; };
NS_IMETHOD GetEmAscent (nscoord &aAscent)
{ aAscent = mEmAscent;
return NS_OK; };
NS_IMETHOD GetEmDescent (nscoord &aDescent)
{ aDescent = mEmDescent;
return NS_OK; };
NS_IMETHOD GetMaxHeight (nscoord &aHeight)
{ aHeight = mMaxHeight;
return NS_OK; };
NS_IMETHOD GetMaxAscent (nscoord &aAscent)
{ aAscent = mMaxAscent;
return NS_OK; };
NS_IMETHOD GetMaxDescent (nscoord &aDescent)
{ aDescent = mMaxDescent;
return NS_OK; };
NS_IMETHOD GetMaxAdvance (nscoord &aAdvance)
{ aAdvance = mMaxAdvance;
return NS_OK; };
NS_IMETHOD GetSpaceWidth (nscoord &aSpaceCharWidth)
{ aSpaceCharWidth = mSpaceWidth;
return NS_OK; };
NS_IMETHOD GetAveCharWidth (nscoord &aAveCharWidth)
{ aAveCharWidth = mAveCharWidth;
return NS_OK; };
// nsIFontMetricsGTK (calls from the font rendering layer)
virtual nsresult GetWidth(const char* aString, PRUint32 aLength,
nscoord& aWidth,
nsRenderingContextGTK *aContext);
virtual nsresult GetWidth(const PRUnichar* aString, PRUint32 aLength,
nscoord& aWidth, PRInt32 *aFontID,
nsRenderingContextGTK *aContext);
virtual nsresult GetTextDimensions(const PRUnichar* aString,
PRUint32 aLength,
nsTextDimensions& aDimensions,
PRInt32* aFontID,
nsRenderingContextGTK *aContext);
virtual nsresult GetTextDimensions(const char* aString,
PRInt32 aLength,
PRInt32 aAvailWidth,
PRInt32* aBreaks,
PRInt32 aNumBreaks,
nsTextDimensions& aDimensions,
PRInt32& aNumCharsFit,
nsTextDimensions& aLastWordDimensions,
PRInt32* aFontID,
nsRenderingContextGTK *aContext);
virtual nsresult GetTextDimensions(const PRUnichar* aString,
PRInt32 aLength,
PRInt32 aAvailWidth,
PRInt32* aBreaks,
PRInt32 aNumBreaks,
nsTextDimensions& aDimensions,
PRInt32& aNumCharsFit,
nsTextDimensions& aLastWordDimensions,
PRInt32* aFontID,
nsRenderingContextGTK *aContext);
virtual nsresult DrawString(const char *aString, PRUint32 aLength,
nscoord aX, nscoord aY,
const nscoord* aSpacing,
nsRenderingContextGTK *aContext,
nsDrawingSurfaceGTK *aSurface);
virtual nsresult DrawString(const PRUnichar* aString, PRUint32 aLength,
nscoord aX, nscoord aY,
PRInt32 aFontID,
const nscoord* aSpacing,
nsRenderingContextGTK *aContext,
nsDrawingSurfaceGTK *aSurface);
virtual nsresult GetBoundingMetrics(const char *aString, PRUint32 aLength,
nsBoundingMetrics &aBoundingMetrics,
nsRenderingContextGTK *aContext);
virtual nsresult GetBoundingMetrics(const PRUnichar *aString,
PRUint32 aLength,
nsBoundingMetrics &aBoundingMetrics,
PRInt32 *aFontID,
nsRenderingContextGTK *aContext);
virtual GdkFont* GetCurrentGDKFont(void);
// get hints for the font
static PRUint32 GetHints (void);
// drawing surface methods
static nsresult FamilyExists (nsIDeviceContext *aDevice,
const nsString &aName);
private:
// local methods
nsresult RealizeFont (void);
nsresult CacheFontMetrics (void);
nsFontXft *FindFont (PRUnichar);
void SetupFCPattern (void);
void DoMatch (void);
gint RawGetWidth (const PRUnichar* aString,
PRUint32 aLength);
nsresult SetupMiniFont (void);
nsresult DrawUnknownGlyph (PRUnichar aChar,
nscoord aX,
nscoord aY,
XftColor *aColor,
XftDraw *aDraw);
void PrepareToDraw (nsRenderingContextGTK *aContext,
nsDrawingSurfaceGTK *aSurface,
XftDraw **aDraw, XftColor &aColor);
// called when enumerating font families
static PRBool EnumFontCallback (const nsString &aFamily,
PRBool aIsGeneric, void *aData);
// generic font metrics class bits
nsCStringArray mFontList;
nsAutoVoidArray mFontIsGeneric;
nsIDeviceContext *mDeviceContext;
nsCOMPtr<nsIAtom> mLangGroup;
nsCString *mGenericFont;
nsFont *mFont;
PRUint16 mPixelSize;
nsCAutoString mDefaultFont;
nsVoidArray mLoadedFonts;
// Xft-related items
nsFontXft *mWesternFont;
FcPattern *mPattern;
PRBool mMatched;
// for rendering unknown fonts
XftFont *mMiniFont;
nscoord mMiniFontWidth;
nscoord mMiniFontHeight;
nscoord mMiniFontPadding;
nscoord mMiniFontYOffset;
// Cached font metrics
nscoord mXHeight;
nscoord mSuperscriptOffset;
nscoord mSubscriptOffset;
nscoord mStrikeoutOffset;
nscoord mStrikeoutSize;
nscoord mUnderlineOffset;
nscoord mUnderlineSize;
nscoord mMaxHeight;
nscoord mLeading;
nscoord mEmHeight;
nscoord mEmAscent;
nscoord mEmDescent;
nscoord mMaxAscent;
nscoord mMaxDescent;
nscoord mMaxAdvance;
nscoord mSpaceWidth;
nscoord mAveCharWidth;
};
class nsFontEnumeratorXft : public nsIFontEnumerator
{
public:
nsFontEnumeratorXft();
NS_DECL_ISUPPORTS
NS_DECL_NSIFONTENUMERATOR
};

Просмотреть файл

@ -44,7 +44,6 @@
#include "nsGfxCIID.h"
#include "nsBlender.h"
#include "nsFontMetricsGTK.h"
#include "nsRenderingContextGTK.h"
#include "nsDeviceContextGTK.h"
// aka nsDeviceContextSpecGTK.h
@ -62,12 +61,18 @@
#ifdef NATIVE_THEME_SUPPORT
#include "nsNativeThemeGTK.h"
#endif
#ifdef MOZ_ENABLE_XFT
#include "nsFontMetricsXft.h"
#endif
#ifdef MOZ_ENABLE_COREXFONTS
#include "nsFontMetricsGTK.h"
#endif
#include "nsFontMetricsUtils.h"
#include "nsPrintSession.h"
#include "gfxImageFrame.h"
// objects that just require generic constructors
NS_GENERIC_FACTORY_CONSTRUCTOR(nsFontMetricsGTK)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsDeviceContextGTK)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsRenderingContextGTK)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsImageGTK)
@ -75,7 +80,6 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsBlender)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsRegionGTK)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsDeviceContextSpecGTK)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsDeviceContextSpecFactoryGTK)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsFontEnumeratorGTK)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsFontList);
NS_GENERIC_FACTORY_CONSTRUCTOR(nsScreenManagerGtk)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsPrintOptionsGTK)
@ -85,8 +89,81 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsNativeThemeGTK)
#endif
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsPrintSession, Init)
NS_GENERIC_FACTORY_CONSTRUCTOR(gfxImageFrame)
// our custom constructors
static nsresult
nsFontMetricsConstructor(nsISupports *aOuter, REFNSIID aIID, void **aResult)
{
nsIFontMetrics *result;
if (!aResult)
return NS_ERROR_NULL_POINTER;
*aResult = nsnull;
if (aOuter)
return NS_ERROR_NO_AGGREGATION;
#ifdef MOZ_ENABLE_XFT
if (NS_IsXftEnabled()) {
result = new nsFontMetricsXft();
if (!result)
return NS_ERROR_OUT_OF_MEMORY;
} else {
#endif
#ifdef MOZ_ENABLE_COREXFONTS
result = new nsFontMetricsGTK();
if (!result)
return NS_ERROR_OUT_OF_MEMORY;
#endif
#ifdef MOZ_ENABLE_XFT
}
#endif
NS_ADDREF(result);
nsresult rv = result->QueryInterface(aIID, aResult);
NS_RELEASE(result);
return rv;
}
static nsresult
nsFontEnumeratorConstructor(nsISupports *aOuter, REFNSIID aIID, void **aResult)
{
nsIFontEnumerator *result;
if (!aResult)
return NS_ERROR_NULL_POINTER;
*aResult = nsnull;
if (aOuter)
return NS_ERROR_NO_AGGREGATION;
#ifdef MOZ_ENABLE_XFT
if (NS_IsXftEnabled()) {
result = new nsFontEnumeratorXft();
if (!result)
return NS_ERROR_OUT_OF_MEMORY;
} else {
#endif
#ifdef MOZ_ENABLE_COREXFONTS
result = new nsFontEnumeratorGTK();
if (!result)
return NS_ERROR_OUT_OF_MEMORY;
#endif
#ifdef MOZ_ENABLE_XFT
}
#endif
NS_ADDREF(result);
nsresult rv = result->QueryInterface(aIID, aResult);
NS_RELEASE(result);
return rv;
}
static NS_IMETHODIMP nsScriptableRegionConstructor(nsISupports *aOuter, REFNSIID aIID, void **aResult)
{
nsresult rv;
@ -134,7 +211,7 @@ static const nsModuleComponentInfo components[] =
NS_FONT_METRICS_CID,
// "@mozilla.org/gfx/font_metrics/gtk;1",
"@mozilla.org/gfx/fontmetrics;1",
nsFontMetricsGTKConstructor },
nsFontMetricsConstructor },
{ "Gtk Device Context",
NS_DEVICE_CONTEXT_CID,
// "@mozilla.org/gfx/device_context/gtk;1",
@ -183,7 +260,7 @@ static const nsModuleComponentInfo components[] =
NS_FONT_ENUMERATOR_CID,
// "@mozilla.org/gfx/font_enumerator/gtk;1",
"@mozilla.org/gfx/fontenumerator;1",
nsFontEnumeratorGTKConstructor },
nsFontEnumeratorConstructor },
{ "Font List",
NS_FONTLIST_CID,
// "@mozilla.org/gfx/fontlist;1"

Просмотреть файл

@ -0,0 +1,124 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* vim:expandtab:shiftwidth=4:tabstop=4:
*/
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code Christopher Blizzard
* <blizzard@mozilla.org>. Portions created by the Initial Developer
* are Copyright (C) 2002 the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef __nsIFontMetricsGTK_h
#define __nsIFontMetricsGTK_h
#include "nsIFontMetrics.h"
#include "nsIRenderingContext.h"
#include "nsDrawingSurfaceGTK.h"
class nsRenderingContextGTK;
class nsIFontMetricsGTK : public nsIFontMetrics {
public:
// Get the width for this string. aWidth will be updated with the
// width in points, not twips. Callers must convert it if they
// want it in another format.
virtual nsresult GetWidth(const char* aString, PRUint32 aLength,
nscoord& aWidth,
nsRenderingContextGTK *aContext) = 0;
// aCachedOffset will be updated with a new offset.
virtual nsresult GetWidth(const PRUnichar* aString, PRUint32 aLength,
nscoord& aWidth, PRInt32 *aFontID,
nsRenderingContextGTK *aContext) = 0;
// Get the text dimensions for this string
virtual nsresult GetTextDimensions(const PRUnichar* aString,
PRUint32 aLength,
nsTextDimensions& aDimensions,
PRInt32* aFontID,
nsRenderingContextGTK *aContext) = 0;
virtual nsresult GetTextDimensions(const char* aString,
PRInt32 aLength,
PRInt32 aAvailWidth,
PRInt32* aBreaks,
PRInt32 aNumBreaks,
nsTextDimensions& aDimensions,
PRInt32& aNumCharsFit,
nsTextDimensions& aLastWordDimensions,
PRInt32* aFontID,
nsRenderingContextGTK *aContext)=0;
virtual nsresult GetTextDimensions(const PRUnichar* aString,
PRInt32 aLength,
PRInt32 aAvailWidth,
PRInt32* aBreaks,
PRInt32 aNumBreaks,
nsTextDimensions& aDimensions,
PRInt32& aNumCharsFit,
nsTextDimensions& aLastWordDimensions,
PRInt32* aFontID,
nsRenderingContextGTK *aContext)=0;
// Draw a string using this font handle on the surface passed in.
virtual nsresult DrawString(const char *aString, PRUint32 aLength,
nscoord aX, nscoord aY,
const nscoord* aSpacing,
nsRenderingContextGTK *aContext,
nsDrawingSurfaceGTK *aSurface) = 0;
// aCachedOffset will be updated with a new offset.
virtual nsresult DrawString(const PRUnichar* aString, PRUint32 aLength,
nscoord aX, nscoord aY,
PRInt32 aFontID,
const nscoord* aSpacing,
nsRenderingContextGTK *aContext,
nsDrawingSurfaceGTK *aSurface) = 0;
// These two functions get the bounding metrics for this handle,
// updating the aBoundingMetrics in Points. This means that the
// caller will have to update them to twips before passing it
// back.
virtual nsresult GetBoundingMetrics(const char *aString, PRUint32 aLength,
nsBoundingMetrics &aBoundingMetrics,
nsRenderingContextGTK *aContext) = 0;
// aCachedOffset will be updated with a new offset.
virtual nsresult GetBoundingMetrics(const PRUnichar *aString,
PRUint32 aLength,
nsBoundingMetrics &aBoundingMetrics,
PRInt32 *aFontID,
nsRenderingContextGTK *aContext) = 0;
// Get a GdkFont for this handle, if there is one. This can
// return 0, which means there is no GdkFont associated with this
// particular handle.
virtual GdkFont* GetCurrentGDKFont(void) = 0;
};
#endif /* __nsIFontMetricsGTK_h */

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -42,7 +42,6 @@
#include "nsRenderingContextImpl.h"
#include "nsUnitConversion.h"
#include "nsFont.h"
#include "nsIFontMetrics.h"
#include "nsPoint.h"
#include "nsString.h"
#include "nsCRT.h"
@ -55,12 +54,10 @@
#include "nsGfxCIID.h"
#include "nsDrawingSurfaceGTK.h"
#include "nsRegionGTK.h"
#include "nsIFontMetricsGTK.h"
#include <gtk/gtk.h>
class nsFontGTK;
class nsXFont;
class nsRenderingContextGTK : public nsRenderingContextImpl
{
public:
@ -174,7 +171,7 @@ public:
NS_IMETHOD GetTextDimensions(const char* aString, PRUint32 aLength,
nsTextDimensions& aDimensions);
NS_IMETHOD GetTextDimensions(const PRUnichar *aString, PRUint32 aLength,
nsTextDimensions& aDimensions, PRInt32 *aFontID);
nsTextDimensions& aDimensions,PRInt32 *aFontID);
NS_IMETHOD GetTextDimensions(const char* aString,
PRInt32 aLength,
PRInt32 aAvailWidth,
@ -183,7 +180,7 @@ public:
nsTextDimensions& aDimensions,
PRInt32& aNumCharsFit,
nsTextDimensions& aLastWordDimensions,
PRInt32* aFontID = nsnull);
PRInt32* aFontID);
NS_IMETHOD GetTextDimensions(const PRUnichar* aString,
PRInt32 aLength,
PRInt32 aAvailWidth,
@ -192,7 +189,7 @@ public:
nsTextDimensions& aDimensions,
PRInt32& aNumCharsFit,
nsTextDimensions& aLastWordDimensions,
PRInt32* aFontID = nsnull);
PRInt32* aFontID);
NS_IMETHOD DrawImage(nsIImage *aImage, nscoord aX, nscoord aY);
NS_IMETHOD DrawImage(nsIImage *aImage, nscoord aX, nscoord aY,
@ -251,20 +248,19 @@ public:
return gdk_gc_ref(mGC);
}
// handle drawing 8 bit data with a 16 bit font
static void Widen8To16AndDraw(GdkDrawable *drawable,
nsXFont *font,
GdkGC *gc,
gint x,
gint y,
const gchar *text,
gint text_length);
// cause the GC to be updated
void UpdateGC();
// Get a pointer to the trans matrix
nsTransform2D *GetTranMatrix() {
return mTranMatrix;
}
private:
nsDrawingSurfaceGTK *mOffscreenSurface;
nsDrawingSurfaceGTK *mSurface;
nsIDeviceContext *mContext;
nsIFontMetrics *mFontMetrics;
nsIFontMetricsGTK *mFontMetrics;
nsCOMPtr<nsIRegion> mClipRegion;
float mP2T;
GdkWChar* mDrawStringBuf;
@ -279,10 +275,8 @@ private:
char mDashList[2];
int mDashes;
nscolor mCurrentColor;
nsFontGTK *mCurrentFont;
nsLineStyle mCurrentLineStyle;
void UpdateGC();
// ConditionRect is used to fix coordinate overflow problems for
// rectangles after they are transformed to screen coordinates
void ConditionRect(nscoord &x, nscoord &y, nscoord &w, nscoord &h) {

Просмотреть файл

@ -718,35 +718,7 @@ nsIFontMetrics *nsWidget::GetFont(void)
//-------------------------------------------------------------------------
NS_IMETHODIMP nsWidget::SetFont(const nsFont &aFont)
{
nsCOMPtr<nsIFontMetrics> fontMetrics;
mContext->GetMetricsFor(aFont, *getter_AddRefs(fontMetrics));
if (!fontMetrics)
return NS_ERROR_FAILURE;
nsFontHandle fontHandle;
fontMetrics->GetFontHandle(fontHandle);
nsFontGTK *gtkfontHandle = (nsFontGTK *)fontHandle;
GdkFont *gdk_font = nsnull;
if (fontHandle) {
gdk_font = gtkfontHandle->GetGDKFont();
}
if (gdk_font) {
// FIXME avoid fontset problems....
if (gdk_font->type == GDK_FONT_FONTSET) {
#ifdef DEBUG
g_print("nsWidget:SetFont - got a FontSet.. ignoring\n");
#endif
return NS_ERROR_FAILURE;
}
if (mWidget)
SetFontNative(gdk_font);
}
return NS_OK;
return NS_ERROR_NOT_IMPLEMENTED;
}
//-------------------------------------------------------------------------