bug 362682. relanding linux text goodness. patch by myself and Behdad Esfahbod <mozilla@behdad.org>. r=vlad

This commit is contained in:
pavlov@pavlov.net 2007-09-27 15:15:51 -07:00
parent 869b1280bb
commit e914cf6bf2
7 changed files with 220 additions and 894 deletions

View File

@ -213,6 +213,7 @@ Gdiplus.h
gdk/gdkevents.h gdk/gdkevents.h
gdk/gdk.h gdk/gdk.h
gdk/gdkkeysyms.h gdk/gdkkeysyms.h
gdk/gdkpango.h
gdk/gdkprivate.h gdk/gdkprivate.h
gdk/gdkregion.h gdk/gdkregion.h
gdk/gdkwindow.h gdk/gdkwindow.h
@ -505,6 +506,7 @@ PALM_CMN.H
pango-engine.h pango-engine.h
pango-glyph.h pango-glyph.h
pango-modules.h pango-modules.h
pango/pangocairo.h
pango/pangofc-decoder.h pango/pangofc-decoder.h
pango/pangofc-font.h pango/pangofc-font.h
pango/pangofc-fontmap.h pango/pangofc-fontmap.h
@ -513,6 +515,7 @@ pango/pango-fontmap.h
pango/pango.h pango/pango.h
pango/pangoxft.h pango/pangoxft.h
pango/pangox.h pango/pangox.h
pango/pango-utils.h
pango-types.h pango-types.h
pascal.h pascal.h
Patches.h Patches.h

View File

@ -116,7 +116,8 @@ PERL_VERSION=5.006
LIBART_VERSION=2.3.4 LIBART_VERSION=2.3.4
CAIRO_VERSION=1.4.2 CAIRO_VERSION=1.4.2
GLITZ_VERSION=0.4.0 GLITZ_VERSION=0.4.0
GTK2_VERSION=1.3.7 PANGO_VERSION=1.10.0
GTK2_VERSION=1.8.0
MAKE_VERSION=3.78 MAKE_VERSION=3.78
WINDRES_VERSION=2.14.90 WINDRES_VERSION=2.14.90
W32API_VERSION=3.8 W32API_VERSION=3.8
@ -4567,7 +4568,7 @@ fi
if test "$COMPILE_ENVIRONMENT"; then if test "$COMPILE_ENVIRONMENT"; then
if test "$MOZ_ENABLE_GTK2" if test "$MOZ_ENABLE_GTK2"
then then
PKG_CHECK_MODULES(MOZ_GTK2, gtk+-2.0 >= 1.3.7 gdk-x11-2.0 glib-2.0 gobject-2.0) PKG_CHECK_MODULES(MOZ_GTK2, gtk+-2.0 >= $GTK2_VERSION gdk-x11-2.0 glib-2.0 gobject-2.0)
fi fi
fi # COMPILE_ENVIRONMENT fi # COMPILE_ENVIRONMENT
@ -4782,7 +4783,7 @@ if test "$MOZ_ENABLE_XFT"
then then
AC_DEFINE(MOZ_ENABLE_XFT) AC_DEFINE(MOZ_ENABLE_XFT)
PKG_CHECK_MODULES(MOZ_XFT, xft) PKG_CHECK_MODULES(MOZ_XFT, xft)
PKG_CHECK_MODULES(_PANGOCHK, pango >= 1.1.0) PKG_CHECK_MODULES(_PANGOCHK, pango >= $PANGO_VERSION)
fi fi
AC_SUBST(MOZ_ENABLE_XFT) AC_SUBST(MOZ_ENABLE_XFT)
@ -4799,12 +4800,7 @@ MOZ_ARG_ENABLE_BOOL(pango,
if test "$MOZ_ENABLE_PANGO" && test -z "$MOZ_ENABLE_CAIRO_GFX" if test "$MOZ_ENABLE_PANGO" && test -z "$MOZ_ENABLE_CAIRO_GFX"
then then
AC_DEFINE(MOZ_ENABLE_PANGO) AC_MSG_ERROR([Cairo gfx is required for Pango font rendering])
PKG_CHECK_MODULES(MOZ_PANGO, pangoxft >= 1.6.0)
AC_SUBST(MOZ_ENABLE_PANGO)
AC_SUBST(MOZ_PANGO_CFLAGS)
AC_SUBST(MOZ_PANGO_LIBS)
fi fi
if test "$MOZ_ENABLE_GTK2" && test "$MOZ_ENABLE_CAIRO_GFX" if test "$MOZ_ENABLE_GTK2" && test "$MOZ_ENABLE_CAIRO_GFX"
@ -4820,13 +4816,7 @@ fi
if test "$MOZ_ENABLE_PANGO" && test "$MOZ_ENABLE_CAIRO_GFX" if test "$MOZ_ENABLE_PANGO" && test "$MOZ_ENABLE_CAIRO_GFX"
then then
AC_DEFINE(MOZ_ENABLE_PANGO) AC_DEFINE(MOZ_ENABLE_PANGO)
dnl PKG_CHECK_MODULES(MOZ_PANGO, pango >= 1.10.0 pangocairo >= 1.10.0) PKG_CHECK_MODULES(MOZ_PANGO, pango >= $PANGO_VERSION pangocairo >= $PANGO_VERSION pangoft2 >= $PANGO_VERSION)
if test "$MOZ_X11"; then
PKG_CHECK_MODULES(MOZ_PANGO, pango >= 1.6.0 pangoft2 >= 1.6.0 pangoxft >= 1.6.0)
else
PKG_CHECK_MODULES(MOZ_PANGO, pango >= 1.6.0 pangoft2 >= 1.6.0)
fi
AC_SUBST(MOZ_ENABLE_PANGO) AC_SUBST(MOZ_ENABLE_PANGO)
AC_SUBST(MOZ_PANGO_CFLAGS) AC_SUBST(MOZ_PANGO_CFLAGS)
AC_SUBST(MOZ_PANGO_LIBS) AC_SUBST(MOZ_PANGO_LIBS)

View File

@ -44,14 +44,15 @@
#include "gfxFont.h" #include "gfxFont.h"
#include <pango/pango.h> #include <pango/pango.h>
#include <X11/Xft/Xft.h>
// Control when we use Xft directly, bypassing Pango // Control when we bypass Pango
// Enable this to use Xft to glyph-convert 8bit-only textruns, but use Pango // Enable this to use FreeType to glyph-convert 8bit-only textruns, but use Pango
// to shape any textruns with non-8bit characters // to shape any textruns with non-8bit characters
#define ENABLE_XFT_FAST_PATH_8BIT // XXX
// Enable this to use Xft to glyph-convert all textruns #define ENABLE_FAST_PATH_8BIT
// #define ENABLE_XFT_FAST_PATH_ALWAYS // Enable this to bypass Pango shaping for all textruns. Don't expect
// anything other than simple Latin work though!
//#define ENABLE_FAST_PATH_ALWAYS
#include "nsDataHashtable.h" #include "nsDataHashtable.h"
#include "nsClassHashtable.h" #include "nsClassHashtable.h"
@ -70,17 +71,15 @@ public:
virtual const gfxFont::Metrics& GetMetrics(); virtual const gfxFont::Metrics& GetMetrics();
PangoFontDescription *GetPangoFontDescription() { RealizeFont(); return mPangoFontDesc; } PangoFontDescription *GetPangoFontDescription() { if (!mPangoFontDesc) RealizeFont(); return mPangoFontDesc; }
PangoContext *GetPangoContext() { RealizeFont(); return mPangoCtx; } PangoContext *GetPangoContext() { if (!mPangoFontDesc) RealizeFont(); return mPangoCtx; }
void GetMozLang(nsACString &aMozLang); void GetMozLang(nsACString &aMozLang);
void GetActualFontFamily(nsACString &aFamily); void GetActualFontFamily(nsACString &aFamily);
XftFont *GetXftFont () { RealizeXftFont (); return mXftFont; } PangoFont *GetPangoFont() { if (!mPangoFont) RealizePangoFont(); return mPangoFont; }
PangoFont *GetPangoFont() { RealizePangoFont(); return mPangoFont; } gfxFloat GetAdjustedSize() { if (!mPangoFontDesc) RealizeFont(); return mAdjustedSize; }
gfxFloat GetAdjustedSize() { RealizeFont(); return mAdjustedSize; }
PRBool HasGlyph(const PRUint32 aChar);
PRUint32 GetGlyph(const PRUint32 aChar); PRUint32 GetGlyph(const PRUint32 aChar);
virtual nsString GetUniqueName(); virtual nsString GetUniqueName();
@ -95,9 +94,7 @@ protected:
PangoFontDescription *mPangoFontDesc; PangoFontDescription *mPangoFontDesc;
PangoContext *mPangoCtx; PangoContext *mPangoCtx;
XftFont *mXftFont;
PangoFont *mPangoFont; PangoFont *mPangoFont;
PangoFont *mGlyphTestingFont;
cairo_scaled_font_t *mCairoFont; cairo_scaled_font_t *mCairoFont;
PRBool mHasMetrics; PRBool mHasMetrics;
@ -106,7 +103,6 @@ protected:
gfxFloat mAdjustedSize; gfxFloat mAdjustedSize;
void RealizeFont(PRBool force = PR_FALSE); void RealizeFont(PRBool force = PR_FALSE);
void RealizeXftFont(PRBool force = PR_FALSE);
void RealizePangoFont(PRBool aForce = PR_FALSE); void RealizePangoFont(PRBool aForce = PR_FALSE);
void GetCharSize(const char aChar, gfxSize& aInkSize, gfxSize& aLogSize, void GetCharSize(const char aChar, gfxSize& aInkSize, gfxSize& aLogSize,
PRUint32 *aGlyphID = nsnull); PRUint32 *aGlyphID = nsnull);
@ -124,7 +120,7 @@ public:
virtual gfxFontGroup *Copy(const gfxFontStyle *aStyle); virtual gfxFontGroup *Copy(const gfxFontStyle *aStyle);
// Create and initialize a textrun using Pango (or Xft) // Create and initialize a textrun using Pango
virtual gfxTextRun *MakeTextRun(const PRUnichar *aString, PRUint32 aLength, virtual gfxTextRun *MakeTextRun(const PRUnichar *aString, PRUint32 aLength,
const Parameters *aParams, PRUint32 aFlags); const Parameters *aParams, PRUint32 aFlags);
virtual gfxTextRun *MakeTextRun(const PRUint8 *aString, PRUint32 aLength, virtual gfxTextRun *MakeTextRun(const PRUint8 *aString, PRUint32 aLength,
@ -146,8 +142,8 @@ protected:
* but stored in UTF16 format) * but stored in UTF16 format)
*/ */
void InitTextRun(gfxTextRun *aTextRun, const gchar *aUTF8Text, void InitTextRun(gfxTextRun *aTextRun, const gchar *aUTF8Text,
PRUint32 aUTF8Length, PRUint32 aUTF8HeaderLength, PRUint32 aUTF8Length, PRBool aTake8BitPath);
PRBool aTake8BitPath);
// Returns NS_ERROR_FAILURE if there's a missing glyph // Returns NS_ERROR_FAILURE if there's a missing glyph
nsresult SetGlyphs(gfxTextRun *aTextRun, gfxPangoFont *aFont, nsresult SetGlyphs(gfxTextRun *aTextRun, gfxPangoFont *aFont,
const gchar *aUTF8, PRUint32 aUTF8Length, const gchar *aUTF8, PRUint32 aUTF8Length,
@ -158,10 +154,10 @@ protected:
const gchar *aUTF8, PRUint32 aUTF8Length, const gchar *aUTF8, PRUint32 aUTF8Length,
PRUint32 *aUTF16Offset); PRUint32 *aUTF16Offset);
void CreateGlyphRunsItemizing(gfxTextRun *aTextRun, void CreateGlyphRunsItemizing(gfxTextRun *aTextRun,
const gchar *aUTF8, PRUint32 aUTF8Length, const gchar *aUTF8, PRUint32 aUTF8Length);
PRUint32 aUTF8HeaderLength); #if defined(ENABLE_FAST_PATH_8BIT) || defined(ENABLE_FAST_PATH_ALWAYS)
#if defined(ENABLE_XFT_FAST_PATH_8BIT) || defined(ENABLE_XFT_FAST_PATH_ALWAYS) PRBool CanTakeFastPath(PRUint32 aFlags);
void CreateGlyphRunsXft(gfxTextRun *aTextRun, void CreateGlyphRunsFast(gfxTextRun *aTextRun,
const gchar *aUTF8, PRUint32 aUTF8Length); const gchar *aUTF8, PRUint32 aUTF8Length);
#endif #endif
@ -212,30 +208,4 @@ private:
nsClassHashtable<nsUint32HashKey, gfxPangoFontWrapper> mPangoFonts; nsClassHashtable<nsUint32HashKey, gfxPangoFontWrapper> mPangoFonts;
}; };
// XXX we should remove this class, because this class is used only in |HasGlyph| of gfxPangoFont.
// But it can use fontconfig directly after bug 366664.
class gfxPangoFontNameMap
{
public:
gfxPangoFontNameMap();
~gfxPangoFontNameMap();
static gfxPangoFontNameMap* GetPangoFontNameMap() {
if (!sPangoFontNameMap)
sPangoFontNameMap = new gfxPangoFontNameMap();
return sPangoFontNameMap;
}
static void Shutdown() {
if (sPangoFontNameMap)
delete sPangoFontNameMap;
sPangoFontNameMap = nsnull;
}
void Put(const nsACString &aName, PangoFont *aPangoFont);
PangoFont* Get(const nsACString &aName);
private:
static gfxPangoFontNameMap *sPangoFontNameMap;
nsClassHashtable<nsCStringHashKey, gfxPangoFontWrapper> mPangoFonts;
};
#endif /* GFX_PANGOFONTS_H */ #endif /* GFX_PANGOFONTS_H */

View File

@ -79,7 +79,7 @@ public:
if (sDPI == -1) { if (sDPI == -1) {
InitDPI(); InitDPI();
} }
NS_ASSERTION(sDPI != 0, "Something is wrong"); NS_ASSERTION(sDPI > 0, "Something is wrong");
return sDPI; return sDPI;
} }

View File

@ -40,6 +40,7 @@
#include "cairo-xlib.h" #include "cairo-xlib.h"
#include <stdlib.h> #include <stdlib.h>
#include <stdint.h>
#if HAVE_STDINT_H #if HAVE_STDINT_H
#include <stdint.h> #include <stdint.h>
#elif HAVE_INTTYPES_H #elif HAVE_INTTYPES_H

File diff suppressed because it is too large Load Diff

View File

@ -60,12 +60,6 @@
#include <fontconfig/fontconfig.h> #include <fontconfig/fontconfig.h>
#ifndef THEBES_USE_PANGO_CAIRO
#include <pango/pangoxft.h>
#endif // THEBES_USE_PANGO_CAIRO
#include <pango/pango-font.h>
#include "nsMathUtils.h" #include "nsMathUtils.h"
#include "lcms.h" #include "lcms.h"
@ -89,6 +83,8 @@ gfxPlatformGtk::gfxPlatformGtk()
#endif #endif
if (!sFontconfigUtils) if (!sFontconfigUtils)
sFontconfigUtils = gfxFontconfigUtils::GetFontconfigUtils(); sFontconfigUtils = gfxFontconfigUtils::GetFontconfigUtils();
InitDPI();
} }
gfxPlatformGtk::~gfxPlatformGtk() gfxPlatformGtk::~gfxPlatformGtk()
@ -98,10 +94,6 @@ gfxPlatformGtk::~gfxPlatformGtk()
gfxPangoFont::Shutdown(); gfxPangoFont::Shutdown();
#ifndef THEBES_USE_PANGO_CAIRO
pango_xft_shutdown_display(GDK_DISPLAY(), 0);
#endif
#if 0 #if 0
// It would be nice to do this (although it might need to be after // It would be nice to do this (although it might need to be after
// the cairo shutdown that happens in ~gfxPlatform). It even looks // the cairo shutdown that happens in ~gfxPlatform). It even looks
@ -278,95 +270,19 @@ gfxPlatformGtk::CreateFontGroup(const nsAString &aFamilies,
return new gfxPangoFontGroup(aFamilies, aStyle); return new gfxPangoFontGroup(aFamilies, aStyle);
} }
static PRInt32
GetXftDPI()
{
char *val = XGetDefault(GDK_DISPLAY(), "Xft", "dpi");
if (val) {
char *e;
double d = strtod(val, &e);
if (e != val)
return NS_lround(d);
}
return -1;
}
static PRInt32
GetDPIFromPangoFont()
{
#ifndef THEBES_USE_PANGO_CAIRO
PangoContext* ctx = pango_xft_get_context(GDK_DISPLAY(), 0);
gdk_pango_context_set_colormap(ctx, gdk_rgb_get_cmap());
#else
PangoContext* ctx =
pango_cairo_font_map_create_context(
PANGO_CAIRO_FONT_MAP(pango_cairo_font_map_get_default()));
#endif
if (!ctx) {
return 0;
}
double dblDPI = 0.0f;
GList *items = nsnull;
PangoItem *item = nsnull;
PangoFcFont *fcfont = nsnull;
PangoAttrList *al = pango_attr_list_new();
if (!al) {
goto cleanup;
}
// Just using the string "a" because we need _some_ text.
items = pango_itemize(ctx, "a", 0, 1, al, NULL);
if (!items) {
goto cleanup;
}
item = (PangoItem*)items->data;
if (!item) {
goto cleanup;
}
fcfont = PANGO_FC_FONT(item->analysis.font);
if (!fcfont) {
goto cleanup;
}
FcPatternGetDouble(fcfont->font_pattern, FC_DPI, 0, &dblDPI);
cleanup:
if (al)
pango_attr_list_unref(al);
if (item)
pango_item_free(item);
if (items)
g_list_free(items);
if (ctx)
g_object_unref(ctx);
return NS_lround(dblDPI);
}
/* static */ /* static */
void void
gfxPlatformGtk::InitDPI() gfxPlatformGtk::InitDPI()
{ {
sDPI = GetXftDPI(); PangoContext *context = gdk_pango_context_get ();
if (sDPI <= 0) { sDPI = pango_cairo_context_get_resolution (context);
sDPI = GetDPIFromPangoFont(); g_object_unref (context);
if (sDPI <= 0) { if (sDPI <= 0) {
// Fall back to something sane // Fall back to something sane
sDPI = 96; sDPI = 96;
} }
} }
}
cmsHPROFILE cmsHPROFILE
gfxPlatformGtk::GetPlatformCMSOutputProfile() gfxPlatformGtk::GetPlatformCMSOutputProfile()