Clamp final font size (after font-size-adjust) to a reasonable value. b=383473 r+sr=vladimir

This commit is contained in:
mats.palmgren%bredband.net 2007-06-08 08:22:04 +00:00
Родитель 87ff23baae
Коммит e3517d0ca0
5 изменённых файлов: 16 добавлений и 10 удалений

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

@ -49,6 +49,7 @@
#include "gfxSkipChars.h"
#include "gfxRect.h"
#include "nsExpirationTracker.h"
#include "nsMathUtils.h"
class gfxContext;
class gfxTextRun;
@ -64,6 +65,8 @@ typedef struct _cairo cairo_t;
#define FONT_WEIGHT_NORMAL 400
#define FONT_WEIGHT_BOLD 700
#define FONT_MAX_SIZE 2000.0
struct THEBES_API gfxFontStyle {
gfxFontStyle(PRUint8 aStyle, PRUint16 aWeight, gfxFloat aSize,
const nsACString& aLangGroup,
@ -102,6 +105,14 @@ struct THEBES_API gfxFontStyle {
// needs to be done.
float sizeAdjust;
// Return the final adjusted font size for the given aspect ratio.
// Not meant to be called when sizeAdjust = 0.
gfxFloat GetAdjustedSize(gfxFloat aspect) const {
NS_ASSERTION(sizeAdjust != 0.0, "Not meant to be called when sizeAdjust = 0");
gfxFloat adjustedSize = PR_MAX(NS_round(size*(sizeAdjust/aspect)), 1.0);
return PR_MIN(adjustedSize, FONT_MAX_SIZE);
}
PLDHashNumber Hash() const {
return ((style + (systemFont << 7) + (familyNameQuirks << 8) +
(weight << 9)) + PRUint32(size*1000) + PRUint32(sizeAdjust*1000)) ^

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

@ -156,8 +156,7 @@ gfxAtsuiFont::InitMetrics(ATSUFontID aFontID, ATSFontRef aFontRef)
if (mAdjustedSize == 0) {
if (GetStyle()->sizeAdjust != 0) {
gfxFloat aspect = mMetrics.xHeight / size;
mAdjustedSize =
PR_MAX(ROUND(size * (GetStyle()->sizeAdjust / aspect)), 1.0f);
mAdjustedSize = GetStyle()->GetAdjustedSize(aspect);
InitMetrics(aFontID, aFontRef);
return;
}

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

@ -560,15 +560,13 @@ gfxFontStyle::gfxFontStyle(PRUint8 aStyle, PRUint16 aWeight, gfxFloat aSize,
familyNameQuirks(aFamilyNameQuirks), weight(aWeight),
size(aSize), langGroup(aLangGroup), sizeAdjust(aSizeAdjust)
{
static const gfxFloat kMaxFontSize = 2000.0;
if (weight > 900)
weight = 900;
if (weight < 100)
weight = 100;
if (size >= kMaxFontSize) {
size = kMaxFontSize;
if (size >= FONT_MAX_SIZE) {
size = FONT_MAX_SIZE;
sizeAdjust = 0.0;
} else if (size < 0.0) {
NS_WARNING("negative font size");

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

@ -412,8 +412,7 @@ gfxPangoFont::RealizeFont(PRBool force)
gfxSize isz, lsz;
GetCharSize('x', isz, lsz);
gfxFloat aspect = isz.height / GetStyle()->size;
mAdjustedSize =
PR_MAX(NS_round(GetStyle()->size*(GetStyle()->sizeAdjust/aspect)), 1.0);
mAdjustedSize = GetStyle()->GetAdjustedSize(aspect);
RealizeFont(PR_TRUE);
}

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

@ -238,8 +238,7 @@ gfxWindowsFont::MakeHFONT()
Metrics *oldMetrics = mMetrics;
ComputeMetrics();
gfxFloat aspect = mMetrics->xHeight / mMetrics->emHeight;
mAdjustedSize =
PR_MAX(ROUND(GetStyle()->size * (GetStyle()->sizeAdjust / aspect)), 1.0f);
mAdjustedSize = GetStyle()->GetAdjustedSize(aspect);
if (mMetrics != oldMetrics) {
delete mMetrics;