зеркало из https://github.com/mozilla/pjs.git
Clamp final font size (after font-size-adjust) to a reasonable value. b=383473 r+sr=vladimir
This commit is contained in:
Родитель
87ff23baae
Коммит
e3517d0ca0
|
@ -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;
|
||||
|
|
Загрузка…
Ссылка в новой задаче