Bug 4573. Was not dealing with the case where only a scalable font was

available (no bitmap fonts). Fixed.
This commit is contained in:
erik%netscape.com 1999-04-06 19:45:38 +00:00
Родитель 3028d55fda
Коммит b2c378b19c
1 изменённых файлов: 101 добавлений и 89 удалений

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

@ -1310,113 +1310,125 @@ void
PickASizeAndLoad(nsFontSearch* aSearch, nsFontStretch* aStretch, PickASizeAndLoad(nsFontSearch* aSearch, nsFontStretch* aStretch,
nsFontCharSet* aCharSet) nsFontCharSet* aCharSet)
{ {
nsFontGTK* s; nsFontGTK* s = nsnull;
nsFontGTK* begin = aStretch->mSizes; nsFontGTK* begin;
nsFontGTK* end = &aStretch->mSizes[aStretch->mSizesCount]; nsFontGTK* end;
nsFontMetricsGTK* m = aSearch->mMetrics; nsFontMetricsGTK* m = aSearch->mMetrics;
int desiredSize = m->mPixelSize; int desiredSize = m->mPixelSize;
int scalable = 0;
for (s = begin; s < end; s++) { if (aStretch->mSizes) {
if (s->mSize >= desiredSize) { begin = aStretch->mSizes;
break; end = &aStretch->mSizes[aStretch->mSizesCount];
} for (s = begin; s < end; s++) {
} if (s->mSize >= desiredSize) {
if (s == end) {
s--;
}
else if (s != begin) {
if ((s->mSize - desiredSize) > (desiredSize - (s - 1)->mSize)) {
s--;
}
}
if (!s->mFont) {
s->LoadFont(aCharSet, m);
if (!s->mFont) {
return;
}
}
if (s->mActualSize > desiredSize) {
for (; s >= begin; s--) {
if (!s->mFont) {
s->LoadFont(aCharSet, m);
if (!s->mFont) {
return;
}
}
if (s->mActualSize <= desiredSize) {
if (((s + 1)->mActualSize - desiredSize) <=
(desiredSize - s->mActualSize)) {
s++;
}
break;
}
}
if (s < begin) {
s = begin;
}
}
else if (s->mActualSize < desiredSize) {
for (; s < end; s++) {
if (!s->mFont) {
s->LoadFont(aCharSet, m);
if (!s->mFont) {
return;
}
}
if (s->mActualSize >= desiredSize) {
if ((s->mActualSize - desiredSize) >
(desiredSize - (s - 1)->mActualSize)) {
s--;
}
break; break;
} }
} }
if (s == end) { if (s == end) {
s--; s--;
} }
} else if (s != begin) {
if ((s->mSize - desiredSize) > (desiredSize - (s - 1)->mSize)) {
if (aStretch->mScalable) { s--;
double ratio = (s->mActualSize / ((double) desiredSize)); }
if ((ratio > 1.2) || (ratio < 0.8)) { }
begin = aStretch->mScaledFonts;
end = &aStretch->mScaledFonts[aStretch->mScaledFontsCount]; if (!s->mFont) {
for (s = begin; s < end; s++) { s->LoadFont(aCharSet, m);
if (s->mSize == desiredSize) { if (!s->mFont) {
return;
}
}
if (s->mActualSize > desiredSize) {
for (; s >= begin; s--) {
if (!s->mFont) {
s->LoadFont(aCharSet, m);
if (!s->mFont) {
return;
}
}
if (s->mActualSize <= desiredSize) {
if (((s + 1)->mActualSize - desiredSize) <=
(desiredSize - s->mActualSize)) {
s++;
}
break;
}
}
if (s < begin) {
s = begin;
}
}
else if (s->mActualSize < desiredSize) {
for (; s < end; s++) {
if (!s->mFont) {
s->LoadFont(aCharSet, m);
if (!s->mFont) {
return;
}
}
if (s->mActualSize >= desiredSize) {
if ((s->mActualSize - desiredSize) >
(desiredSize - (s - 1)->mActualSize)) {
s--;
}
break; break;
} }
} }
if (s == end) { if (s == end) {
if (aStretch->mScaledFontsCount == aStretch->mScaledFontsAlloc) { s--;
int newSize = 2 * }
(aStretch->mScaledFontsAlloc ? aStretch->mScaledFontsAlloc : 1); }
nsFontGTK* newPointer = new nsFontGTK[newSize];
if (newPointer) { if (aStretch->mScalable) {
for (int i = aStretch->mScaledFontsAlloc - 1; i >= 0; i--) { double ratio = (s->mActualSize / ((double) desiredSize));
newPointer[i] = aStretch->mScaledFonts[i]; if ((ratio > 1.2) || (ratio < 0.8)) {
} scalable = 1;
aStretch->mScaledFontsAlloc = newSize; }
delete [] aStretch->mScaledFonts; }
aStretch->mScaledFonts = newPointer; }
} else {
else { scalable = 1;
return; }
if (scalable) {
begin = aStretch->mScaledFonts;
end = &aStretch->mScaledFonts[aStretch->mScaledFontsCount];
for (s = begin; s < end; s++) {
if (s->mSize == desiredSize) {
break;
}
}
if (s == end) {
if (aStretch->mScaledFontsCount == aStretch->mScaledFontsAlloc) {
int newSize = 2 *
(aStretch->mScaledFontsAlloc ? aStretch->mScaledFontsAlloc : 1);
nsFontGTK* newPointer = new nsFontGTK[newSize];
if (newPointer) {
for (int i = aStretch->mScaledFontsAlloc - 1; i >= 0; i--) {
newPointer[i] = aStretch->mScaledFonts[i];
} }
aStretch->mScaledFontsAlloc = newSize;
delete [] aStretch->mScaledFonts;
aStretch->mScaledFonts = newPointer;
} }
s = &aStretch->mScaledFonts[aStretch->mScaledFontsCount++]; else {
s->mName = PR_smprintf(aStretch->mScalable, desiredSize);
if (!s->mName) {
return;
}
s->mSize = desiredSize;
s->mBaselineAdjust = 0;
s->mCharSetInfo = aCharSet->mInfo;
s->LoadFont(aCharSet, m);
if (!s->mFont) {
return; return;
} }
} }
s = &aStretch->mScaledFonts[aStretch->mScaledFontsCount++];
s->mName = PR_smprintf(aStretch->mScalable, desiredSize);
if (!s->mName) {
return;
}
s->mSize = desiredSize;
s->mBaselineAdjust = 0;
s->mCharSetInfo = aCharSet->mInfo;
s->LoadFont(aCharSet, m);
if (!s->mFont) {
return;
}
} }
} }