b=454720 Add GetThebesStyle and GetThebesWeight to gfxFontconfigUtils r=pavlov

This commit is contained in:
Karl Tomlinson 2008-09-16 16:40:57 +12:00
parent 429447431f
commit a0bbe3e00b
3 changed files with 65 additions and 37 deletions

View File

@ -37,6 +37,7 @@
* ***** END LICENSE BLOCK ***** */
#include "gfxFontconfigUtils.h"
#include "gfxFont.h"
#include <fontconfig/fontconfig.h>
@ -49,6 +50,63 @@
/* static */ gfxFontconfigUtils* gfxFontconfigUtils::sUtils = nsnull;
/* static */ PRUint8
gfxFontconfigUtils::GetThebesStyle(FcPattern *aPattern)
{
int slant;
if (FcPatternGetInteger(aPattern, FC_SLANT, 0, &slant) == FcResultMatch) {
if (slant == FC_SLANT_ITALIC)
return FONT_STYLE_ITALIC;
if (slant == FC_SLANT_OBLIQUE)
return FONT_STYLE_OBLIQUE;
}
return FONT_STYLE_NORMAL;
}
// OS/2 weight classes were introduced in fontconfig-2.1.93 (2003).
#ifndef FC_WEIGHT_THIN
#define FC_WEIGHT_THIN 0 // 2.1.93
#define FC_WEIGHT_EXTRALIGHT 40 // 2.1.93
#define FC_WEIGHT_REGULAR 80 // 2.1.93
#define FC_WEIGHT_EXTRABOLD 205 // 2.1.93
#endif
// book was introduced in fontconfig-2.2.90 (and so fontconfig-2.3.0 in 2005)
#ifndef FC_WEIGHT_BOOK
#define FC_WEIGHT_BOOK 75
#endif
/* static */ PRUint16
gfxFontconfigUtils::GetThebesWeight(FcPattern *aPattern)
{
int weight;
if (FcPatternGetInteger(aPattern, FC_WEIGHT, 0, &weight) != FcResultMatch)
return FONT_WEIGHT_NORMAL;
if (weight <= (FC_WEIGHT_THIN + FC_WEIGHT_EXTRALIGHT) / 2)
return 100;
if (weight <= (FC_WEIGHT_EXTRALIGHT + FC_WEIGHT_LIGHT) / 2)
return 200;
if (weight <= (FC_WEIGHT_LIGHT + FC_WEIGHT_BOOK) / 2)
return 300;
if (weight <= (FC_WEIGHT_REGULAR + FC_WEIGHT_MEDIUM) / 2)
// This includes FC_WEIGHT_BOOK
return 400;
if (weight <= (FC_WEIGHT_MEDIUM + FC_WEIGHT_DEMIBOLD) / 2)
return 500;
if (weight <= (FC_WEIGHT_DEMIBOLD + FC_WEIGHT_BOLD) / 2)
return 600;
if (weight <= (FC_WEIGHT_BOLD + FC_WEIGHT_EXTRABOLD) / 2)
return 700;
if (weight <= (FC_WEIGHT_EXTRABOLD + FC_WEIGHT_BLACK) / 2)
return 800;
if (weight <= FC_WEIGHT_BLACK)
return 900;
// FC_WEIGHT_EXTRABLACK was introduced in fontconfig-2.4.91 (2007)
return 901;
}
gfxFontconfigUtils::gfxFontconfigUtils()
{
mAliasTable.Init(50);

View File

@ -43,6 +43,8 @@
#include "nsTArray.h"
#include "nsDataHashtable.h"
#include <fontconfig/fontconfig.h>
class gfxFontNameList : public nsTArray<nsString>
{
public:
@ -77,6 +79,9 @@ public:
nsresult GetStandardFamilyName(const nsAString& aFontName, nsAString& aFamilyName);
static PRUint8 GetThebesStyle(FcPattern *aPattern); // slant
static PRUint16 GetThebesWeight(FcPattern *aPattern);
protected:
static gfxFontconfigUtils* sUtils;

View File

@ -370,43 +370,8 @@ gfxPlatformGtk::UpdateFontList()
fe->mFTFontIndex = 0;
}
if (FcPatternGetInteger(fs->fonts[i], FC_WEIGHT, 0, &x) == FcResultMatch) {
switch(x) {
case 0:
fe->mWeight = 100;
break;
case 40:
fe->mWeight = 200;
break;
case 50:
fe->mWeight = 300;
break;
case 75:
case 80:
fe->mWeight = 400;
break;
case 100:
fe->mWeight = 500;
break;
case 180:
fe->mWeight = 600;
break;
case 200:
fe->mWeight = 700;
break;
case 205:
fe->mWeight = 800;
break;
case 210:
fe->mWeight = 900;
break;
default:
// rough estimate
fe->mWeight = (((x * 4) + 100) / 100) * 100;
break;
}
//printf(" - weight: %d\n", fe->mWeight);
}
fe->mWeight = gfxFontconfigUtils::GetThebesWeight(fs->fonts[i]);
//printf(" - weight: %d\n", fe->mWeight);
fe->mItalic = PR_FALSE;
if (FcPatternGetInteger(fs->fonts[i], FC_SLANT, 0, &x) == FcResultMatch) {