зеркало из https://github.com/mozilla/pjs.git
a little cleanup (removed the commented-out unix code etc...)
This commit is contained in:
Родитель
b40b568a08
Коммит
1f928b00d9
|
@ -19,18 +19,13 @@
|
|||
#include "nsFontMetricsMac.h"
|
||||
#include "nsDeviceContextMac.h"
|
||||
|
||||
#include "nspr.h"
|
||||
#include "nsCRT.h"
|
||||
|
||||
static NS_DEFINE_IID(kIFontMetricsIID, NS_IFONT_METRICS_IID);
|
||||
|
||||
//#define NOISY_FONTS
|
||||
|
||||
nsFontMetricsMac :: nsFontMetricsMac()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
mFont = nsnull;//¥¥¥
|
||||
//mFontHandle = nsnull;
|
||||
mFont = nsnull;
|
||||
}
|
||||
|
||||
nsFontMetricsMac :: ~nsFontMetricsMac()
|
||||
|
@ -42,127 +37,16 @@ nsFontMetricsMac :: ~nsFontMetricsMac()
|
|||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsFontMetricsMac, kIFontMetricsIID)
|
||||
|
||||
NS_IMETHODIMP nsFontMetricsMac :: Init(const nsFont& aFont, nsIDeviceContext* aCX)
|
||||
{
|
||||
NS_ASSERTION(!(nsnull == aCX), "attempt to init fontmetrics with null device context");
|
||||
|
||||
/*
|
||||
char **fnames = nsnull;
|
||||
PRInt32 namelen = aFont.name.Length() + 1;
|
||||
char *wildstring = (char *)PR_Malloc((namelen << 1) + 200);
|
||||
int numnames = 0;
|
||||
char altitalicization = 0;
|
||||
XFontStruct *fonts;
|
||||
PRInt32 dpi = NSToIntRound(aCX->GetTwipsToDevUnits() * 1440);
|
||||
Display *dpy = XtDisplay((Widget)aCX->GetNativeWidget());
|
||||
|
||||
if (nsnull == wildstring)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
mFont = new nsFont(aFont);
|
||||
mContext = aCX;
|
||||
mFontHandle = nsnull;
|
||||
|
||||
aFont.name.ToCString(wildstring, namelen);
|
||||
|
||||
if (abs(dpi - 75) < abs(dpi - 100))
|
||||
dpi = 75;
|
||||
else
|
||||
dpi = 100;
|
||||
|
||||
#ifdef NOISY_FONTS
|
||||
fprintf(stderr, "looking for font %s (%d)", wildstring, aFont.size / 20);
|
||||
#endif
|
||||
|
||||
//font properties we care about:
|
||||
//name
|
||||
//weight (bold, medium)
|
||||
//slant (r = normal, i = italic, o = oblique)
|
||||
//size in nscoords >> 1
|
||||
|
||||
PR_snprintf(&wildstring[namelen + 1], namelen + 200,
|
||||
"*-%s-%s-%c-normal--*-*-%d-%d-*-*-*",
|
||||
wildstring,
|
||||
(aFont.weight <= NS_FONT_WEIGHT_NORMAL) ? "medium" : "bold",
|
||||
(aFont.style == NS_FONT_STYLE_NORMAL) ? 'r' :
|
||||
((aFont.style == NS_FONT_STYLE_ITALIC) ? 'i' : 'o'), dpi, dpi);
|
||||
|
||||
fnames = XListFontsWithInfo(dpy, &wildstring[namelen + 1], 200, &numnames, &fonts);
|
||||
|
||||
if (aFont.style == NS_FONT_STYLE_ITALIC)
|
||||
altitalicization = 'o';
|
||||
else if (aFont.style == NS_FONT_STYLE_OBLIQUE)
|
||||
altitalicization = 'i';
|
||||
|
||||
if ((numnames <= 0) && altitalicization)
|
||||
{
|
||||
PR_snprintf(&wildstring[namelen + 1], namelen + 200,
|
||||
"*-%s-%s-%c-normal--*-*-%d-%d-*-*-*",
|
||||
wildstring,
|
||||
(aFont.weight <= NS_FONT_WEIGHT_NORMAL) ? "medium" : "bold",
|
||||
altitalicization, dpi, dpi);
|
||||
|
||||
fnames = XListFontsWithInfo(dpy, &wildstring[namelen + 1], 200, &numnames, &fonts);
|
||||
}
|
||||
|
||||
if (numnames <= 0)
|
||||
{
|
||||
//we were not able to match the font name at all...
|
||||
|
||||
const char *newname = MapFamilyToFont(aFont.name);
|
||||
|
||||
PR_snprintf(&wildstring[namelen + 1], namelen + 200,
|
||||
"*-%s-%s-%c-normal--*-*-%d-%d-*-*-*",
|
||||
newname,
|
||||
(aFont.weight <= NS_FONT_WEIGHT_NORMAL) ? "medium" : "bold",
|
||||
(aFont.style == NS_FONT_STYLE_NORMAL) ? 'r' :
|
||||
((aFont.style == NS_FONT_STYLE_ITALIC) ? 'i' : 'o'), dpi, dpi);
|
||||
|
||||
fnames = XListFontsWithInfo(dpy, &wildstring[namelen + 1], 200, &numnames, &fonts);
|
||||
|
||||
if ((numnames <= 0) && altitalicization)
|
||||
{
|
||||
PR_snprintf(&wildstring[namelen + 1], namelen + 200,
|
||||
"*-%s-%s-%c-normal--*-*-%d-%d-*-*-*",
|
||||
newname,
|
||||
(aFont.weight <= NS_FONT_WEIGHT_NORMAL) ? "medium" : "bold",
|
||||
altitalicization, dpi, dpi);
|
||||
|
||||
fnames = XListFontsWithInfo(dpy, &wildstring[namelen + 1], 200, &numnames, &fonts);
|
||||
}
|
||||
}
|
||||
|
||||
if (numnames > 0)
|
||||
{
|
||||
char *nametouse = PickAppropriateSize(fnames, fonts, numnames, aFont.size);
|
||||
|
||||
mFontHandle = ::XLoadFont(dpy, nametouse);
|
||||
|
||||
#ifdef NOISY_FONTS
|
||||
fprintf(stderr, " is: %s\n", nametouse);
|
||||
#endif
|
||||
|
||||
XFreeFontInfo(fnames, fonts, numnames);
|
||||
}
|
||||
else
|
||||
{
|
||||
//ack. we're in real trouble, go for fixed...
|
||||
|
||||
#ifdef NOISY_FONTS
|
||||
fprintf(stderr, " is: %s\n", "fixed (final fallback)");
|
||||
#endif
|
||||
|
||||
mFontHandle = ::XLoadFont(dpy, "fixed");
|
||||
}
|
||||
|
||||
RealizeFont();
|
||||
|
||||
PR_Free(wildstring);*/
|
||||
|
||||
mFont = new nsFont(aFont);//¥¥¥
|
||||
mContext = aCX;
|
||||
|
||||
if (mFont != nsnull)
|
||||
nsFontMetricsMac::SetFont(*mFont, mContext);
|
||||
|
@ -190,78 +74,7 @@ nsFontMetricsMac :: Destroy()
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
/*char * nsFontMetricsMac::PickAppropriateSize(char **names, XFontStruct *fonts, int cnt, nscoord desired)
|
||||
{
|
||||
int idx;
|
||||
PRInt32 desiredpix = NSToIntRound(mContext->GetAppUnitsToDevUnits() * desired);
|
||||
XFontStruct *curfont;
|
||||
PRInt32 closestmin = -1, minidx;
|
||||
|
||||
//first try an exact or closest smaller match...
|
||||
|
||||
for (idx = 0, curfont = fonts; idx < cnt; idx++, curfont++)
|
||||
{
|
||||
PRInt32 height = curfont->ascent + curfont->descent;
|
||||
|
||||
if (height == desiredpix)
|
||||
break;
|
||||
|
||||
if ((height < desiredpix) && (height > closestmin))
|
||||
{
|
||||
closestmin = height;
|
||||
minidx = idx;
|
||||
}
|
||||
}
|
||||
|
||||
if (idx < cnt)
|
||||
return names[idx];
|
||||
else if (closestmin >= 0)
|
||||
return names[minidx];
|
||||
else
|
||||
{
|
||||
closestmin = 2000000;
|
||||
|
||||
for (idx = 0, curfont = fonts; idx < cnt; idx++, curfont++)
|
||||
{
|
||||
PRInt32 height = curfont->ascent + curfont->descent;
|
||||
|
||||
if ((height > desiredpix) && (height < closestmin))
|
||||
{
|
||||
closestmin = height;
|
||||
minidx = idx;
|
||||
}
|
||||
}
|
||||
|
||||
return names[minidx];
|
||||
}
|
||||
}*/
|
||||
|
||||
/*void nsFontMetricsMac::RealizeFont()
|
||||
{
|
||||
XFontStruct * fs = ::XQueryFont(XtDisplay((Widget)mContext->GetNativeWidget()), mFontHandle);
|
||||
|
||||
float f = mContext->GetDevUnitsToAppUnits();
|
||||
|
||||
mAscent = nscoord(fs->ascent * f);
|
||||
mDescent = nscoord(fs->descent * f);
|
||||
mMaxAscent = nscoord(fs->ascent * f) ;
|
||||
mMaxDescent = nscoord(fs->descent * f);
|
||||
|
||||
mHeight = nscoord((fs->ascent + fs->descent) * f) ;
|
||||
mMaxAdvance = nscoord(fs->max_bounds.width * f);
|
||||
|
||||
PRUint32 i;
|
||||
|
||||
for (i = 0; i < 256; i++)
|
||||
{
|
||||
if ((i < fs->min_char_or_byte2) || (i > fs->max_char_or_byte2))
|
||||
mCharWidths[i] = mMaxAdvance;
|
||||
else
|
||||
mCharWidths[i] = nscoord((fs->per_char[i - fs->min_char_or_byte2].width) * f);
|
||||
}
|
||||
|
||||
mLeading = 0;
|
||||
}*/
|
||||
//------------------------------------------------------------------------
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFontMetricsMac :: GetXHeight(nscoord& aResult)
|
||||
|
@ -340,25 +153,22 @@ NS_IMETHODIMP nsFontMetricsMac :: GetMaxAdvance(nscoord &aAdvance)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsFontMetricsMac :: GetWidths(const nscoord *&aWidths)
|
||||
{
|
||||
//return mCharWidths;
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsFontMetricsMac :: GetFont(const nsFont *&aFont)
|
||||
{
|
||||
aFont = mFont;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsFontMetricsMac :: GetFontHandle(nsFontHandle &aHandle)
|
||||
NS_IMETHODIMP nsFontMetricsMac :: GetWidths(const nscoord *&aWidths)
|
||||
{
|
||||
//return (nsFontHandle)mFontHandle;
|
||||
aHandle = nsnull;
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
return NS_ERROR_NOT_IMPLEMENTED; //XXX
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsFontMetricsMac :: GetFontHandle(nsFontHandle &aHandle)
|
||||
{
|
||||
aHandle = nsnull;
|
||||
return NS_ERROR_NOT_IMPLEMENTED; //XXX
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
|
||||
|
@ -384,12 +194,7 @@ void nsFontMetricsMac :: SetFont(const nsFont& aFont, nsIDeviceContext* aContext
|
|||
case NS_FONT_VARIANT_NORMAL: break;
|
||||
case NS_FONT_VARIANT_SMALL_CAPS: textFace |= condense; break; //XXX
|
||||
}
|
||||
/*switch (aFont.weight)
|
||||
{
|
||||
case NS_FONT_WEIGHT_NORMAL: break;
|
||||
case NS_FONT_WEIGHT_BOLD: textFace |= bold; break;
|
||||
}*/
|
||||
if (aFont.weight > NS_FONT_WEIGHT_NORMAL)
|
||||
if (aFont.weight > NS_FONT_WEIGHT_NORMAL) // don't test NS_FONT_WEIGHT_BOLD
|
||||
textFace |= bold;
|
||||
|
||||
::TextFace(textFace);
|
||||
|
|
|
@ -59,19 +59,7 @@ public:
|
|||
|
||||
static void SetFont(const nsFont& aFont, nsIDeviceContext* aContext);
|
||||
|
||||
/*protected:
|
||||
void RealizeFont();
|
||||
static const char* MapFamilyToFont(const nsString& aLogicalFontName);
|
||||
|
||||
protected:
|
||||
void QueryFont();
|
||||
char *PickAppropriateSize(char **names, XFontStruct *fonts, int cnt, nscoord desired);
|
||||
|
||||
nsFont *mFont;
|
||||
nsIDeviceContext *mContext;
|
||||
XFontStruct *mFontInfo;
|
||||
Font mFontHandle;
|
||||
nscoord mCharWidths[256];*/
|
||||
nscoord mHeight;
|
||||
nscoord mAscent;
|
||||
nscoord mDescent;
|
||||
|
|
Загрузка…
Ссылка в новой задаче