зеркало из https://github.com/mozilla/pjs.git
Initial check-in of new X/GTK font code. Improved font-weight "bolder"
and "lighter", more accurate font-size (max ascent and max descent), better speed. However, ifdeffed for now to try on various platforms.
This commit is contained in:
Родитель
68d3052d06
Коммит
6b3ee2d93d
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -30,6 +30,39 @@
|
|||
#include <gdk/gdk.h>
|
||||
#include <gdk/gdkx.h>
|
||||
|
||||
#undef FONT_SWITCHING
|
||||
#ifdef FONT_SWITCHING
|
||||
|
||||
#ifdef ADD_GLYPH
|
||||
#undef ADD_GLYPH
|
||||
#endif
|
||||
#define ADD_GLYPH(map, g) (map)[(g) >> 3] |= (1 << ((g) & 7))
|
||||
|
||||
#ifdef FONT_HAS_GLYPH
|
||||
#undef FONT_HAS_GLYPH
|
||||
#endif
|
||||
#define FONT_HAS_GLYPH(map, g) (((map)[(g) >> 3] >> ((g) & 7)) & 1)
|
||||
|
||||
typedef struct nsFontCharSetInfo nsFontCharSetInfo;
|
||||
|
||||
typedef gint (*nsFontCharSetConverter)(nsFontCharSetInfo* aSelf,
|
||||
const PRUnichar* aSrcBuf, PRUint32 aSrcLen, PRUint8* aDestBuf,
|
||||
PRUint32 aDestLen);
|
||||
|
||||
typedef struct nsFontGTK
|
||||
{
|
||||
GdkFont* mFont;
|
||||
PRUint8* mMap;
|
||||
nsFontCharSetInfo* mCharSetInfo;
|
||||
char* mName;
|
||||
} nsFontGTK;
|
||||
|
||||
struct nsFontCharSet;
|
||||
struct nsFontFamily;
|
||||
typedef struct nsFontSearch nsFontSearch;
|
||||
|
||||
#endif /* FONT_SWITCHING */
|
||||
|
||||
class nsFontMetricsGTK : public nsIFontMetrics
|
||||
{
|
||||
public:
|
||||
|
@ -57,6 +90,27 @@ public:
|
|||
NS_IMETHOD GetFont(const nsFont *&aFont);
|
||||
NS_IMETHOD GetFontHandle(nsFontHandle &aHandle);
|
||||
|
||||
#ifdef FONT_SWITCHING
|
||||
|
||||
nsFontGTK* FindFont(PRUnichar aChar);
|
||||
static gint GetWidth(GdkFont* aFont, nsFontCharSetInfo* aInfo,
|
||||
const PRUnichar* aString, PRUint32 aLength);
|
||||
static void InitFonts(void);
|
||||
|
||||
friend void TryCharSet(nsFontSearch* aSearch, nsFontCharSet* aCharSet);
|
||||
friend void TryFamily(nsFontSearch* aSearch, nsFontFamily* aFamily);
|
||||
|
||||
nsFontGTK *mLoadedFonts;
|
||||
PRUint16 mLoadedFontsAlloc;
|
||||
PRUint16 mLoadedFontsCount;
|
||||
|
||||
nsString *mFonts;
|
||||
PRUint16 mFontsAlloc;
|
||||
PRUint16 mFontsCount;
|
||||
PRUint16 mFontsIndex;
|
||||
|
||||
#endif /* FONT_SWITCHING */
|
||||
|
||||
protected:
|
||||
char *PickAppropriateSize(char **names, XFontStruct *fonts, int cnt, nscoord desired);
|
||||
void RealizeFont();
|
||||
|
@ -79,6 +133,14 @@ protected:
|
|||
nscoord mStrikeoutOffset;
|
||||
nscoord mUnderlineSize;
|
||||
nscoord mUnderlineOffset;
|
||||
|
||||
#ifdef FONT_SWITCHING
|
||||
|
||||
PRUint16 mPixelSize;
|
||||
PRUint8 mStretchIndex;
|
||||
PRUint8 mStyleIndex;
|
||||
|
||||
#endif /* FONT_SWITCHING */
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
*/
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
#include "nsFontMetricsGTK.h"
|
||||
#include "nsRenderingContextGTK.h"
|
||||
#include "nsRegionGTK.h"
|
||||
#include "nsGfxCIID.h"
|
||||
|
@ -829,6 +830,23 @@ NS_IMETHODIMP nsRenderingContextGTK::FillArc(nscoord aX, nscoord aY,
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
#ifdef FONT_SWITCHING
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsRenderingContextGTK::GetWidth(char aC, nscoord &aWidth)
|
||||
{
|
||||
return GetWidth(&aC, 1, aWidth);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsRenderingContextGTK::GetWidth(PRUnichar aC, nscoord& aWidth,
|
||||
PRInt32* aFontID)
|
||||
{
|
||||
return GetWidth(&aC, 1, aWidth, aFontID);
|
||||
}
|
||||
|
||||
#else /* FONT_SWITCHING */
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsRenderingContextGTK::GetWidth(char aC, nscoord &aWidth)
|
||||
{
|
||||
|
@ -848,6 +866,8 @@ nsRenderingContextGTK::GetWidth(PRUnichar aC, nscoord& aWidth,
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
#endif /* FONT_SWITCHING */
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsRenderingContextGTK::GetWidth(const nsString& aString,
|
||||
nscoord& aWidth, PRInt32* aFontID)
|
||||
|
@ -861,6 +881,89 @@ nsRenderingContextGTK::GetWidth(const char* aString, nscoord& aWidth)
|
|||
return GetWidth(aString, strlen(aString), aWidth);
|
||||
}
|
||||
|
||||
#ifdef FONT_SWITCHING
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsRenderingContextGTK::GetWidth(const char* aString, PRUint32 aLength,
|
||||
nscoord& aWidth)
|
||||
{
|
||||
if (0 == aLength) {
|
||||
aWidth = 0;
|
||||
}
|
||||
else {
|
||||
g_return_val_if_fail(aString != NULL, NS_ERROR_FAILURE);
|
||||
gint rawWidth = gdk_text_width (mCurrentFont, aString, aLength);
|
||||
aWidth = NSToCoordRound(rawWidth * mP2T);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsRenderingContextGTK::GetWidth(const PRUnichar* aString, PRUint32 aLength,
|
||||
nscoord& aWidth, PRInt32* aFontID)
|
||||
{
|
||||
if (0 == aLength) {
|
||||
aWidth = 0;
|
||||
}
|
||||
else {
|
||||
g_return_val_if_fail(aString != NULL, NS_ERROR_FAILURE);
|
||||
|
||||
nsFontMetricsGTK* metrics = (nsFontMetricsGTK*) mFontMetrics;
|
||||
GdkFont* prevFont = nsnull;
|
||||
nsFontCharSetInfo* prevCharSetInfo = nsnull;
|
||||
gint rawWidth = 0;
|
||||
PRUint32 start = 0;
|
||||
PRUint32 i;
|
||||
for (i = 0; i < aLength; i++) {
|
||||
PRUnichar c = aString[i];
|
||||
GdkFont* currFont = nsnull;
|
||||
nsFontCharSetInfo* currCharSetInfo = nsnull;
|
||||
nsFontGTK* font = metrics->mLoadedFonts;
|
||||
nsFontGTK* end = &metrics->mLoadedFonts[metrics->mLoadedFontsCount];
|
||||
while (font < end) {
|
||||
if (FONT_HAS_GLYPH(font->mMap, c)) {
|
||||
currFont = font->mFont;
|
||||
currCharSetInfo = font->mCharSetInfo;
|
||||
goto FoundFont; // for speed -- avoid "if" statement
|
||||
}
|
||||
font++;
|
||||
}
|
||||
font = metrics->FindFont(c);
|
||||
currFont = font->mFont;
|
||||
currCharSetInfo = font->mCharSetInfo;
|
||||
FoundFont:
|
||||
// XXX avoid this test by duplicating code -- erik
|
||||
if (prevFont) {
|
||||
if (currFont != prevFont) {
|
||||
rawWidth += nsFontMetricsGTK::GetWidth(prevFont, prevCharSetInfo,
|
||||
&aString[start], i - start);
|
||||
prevFont = currFont;
|
||||
prevCharSetInfo = currCharSetInfo;
|
||||
start = i;
|
||||
}
|
||||
}
|
||||
else {
|
||||
prevFont = currFont;
|
||||
prevCharSetInfo = currCharSetInfo;
|
||||
start = i;
|
||||
}
|
||||
}
|
||||
|
||||
if (prevFont) {
|
||||
rawWidth += nsFontMetricsGTK::GetWidth(prevFont, prevCharSetInfo,
|
||||
&aString[start], i - start);
|
||||
}
|
||||
|
||||
aWidth = NSToCoordRound(rawWidth * mP2T);
|
||||
}
|
||||
if (nsnull != aFontID)
|
||||
*aFontID = 0;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
#else /* FONT_SWITCHING */
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsRenderingContextGTK::GetWidth(const char* aString, PRUint32 aLength,
|
||||
nscoord& aWidth)
|
||||
|
@ -915,6 +1018,8 @@ nsRenderingContextGTK::GetWidth(const PRUnichar* aString, PRUint32 aLength,
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
#endif /* FONT_SWITCHING */
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsRenderingContextGTK::DrawString(const char *aString, PRUint32 aLength,
|
||||
nscoord aX, nscoord aY,
|
||||
|
|
Загрузка…
Ссылка в новой задаче