Commit d79560a6 authored by Andrea Iacovitti's avatar Andrea Iacovitti

Initialize family to standard font name in FontDef() and simply/optimize the code.

parent 6abefd29
......@@ -506,11 +506,7 @@ void CSSStyleSelector::computeFontSizesFor(int logicalDpiY, int zoomFactor, QVec
const float toPix = 1.0;
#else
Q_UNUSED( isFixed );
// ### get rid of float / double
float toPix = logicalDpiY/72.0f;
if (toPix < 96.0f/72.0f)
toPix = 96.0f/72.0f;
const float toPix = qMax(logicalDpiY, 96) / 72.0f;
#endif // ######### fix isFixed code again.
fontSizes.resize( MAXFONTSIZES );
......@@ -3765,7 +3761,7 @@ void CSSStyleSelector::applyRule( int id, DOM::CSSValueImpl *value )
#ifdef APPLE_CHANGES
fontDef.family = initialDef.firstFamily();
#else
fontDef.family.clear();
fontDef.family = initialDef.family;
#endif
if (style->setFontDef(fontDef))
fontDirty = true;
......
......@@ -36,9 +36,6 @@
# endif
#endif
#include <khtml_global.h>
#include <khtml_settings.h>
#include <kdebug.h>
#include <kglobal.h>
......@@ -627,11 +624,9 @@ unsigned CachedFontInstance::calcAndCacheWidth(unsigned short codePoint)
void Font::update(int logicalDpiY) const
{
QString familyName = fontDef.family.isEmpty() ? KHTMLGlobal::defaultHTMLSettings()->stdFontName() : fontDef.family;
CachedFontFamily* family = queryFamily(familyName, fontDef.weight, fontDef.italic);
CachedFontFamily* family = queryFamily(fontDef.family, fontDef.weight, fontDef.italic);
int size = fontDef.size;
const int lDpiY = qMax(logicalDpiY, 96);
// ok, now some magic to get a nice unscaled font
// all other font properties should be set before this one!!!!
......@@ -641,6 +636,7 @@ void Font::update(int logicalDpiY) const
// lets see if we find a nice looking font, which is not too far away
// from the requested one.
// kDebug(6080) << "khtml::setFontSize family = " << f.family() << " size requested=" << size;
const float toPix = qMax(logicalDpiY, 96) / 72.0f;
float diff = 1; // ### 100% deviation
float bestSize = 0;
......@@ -650,7 +646,7 @@ void Font::update(int logicalDpiY) const
for( ; it != itEnd; ++it )
{
float newDiff = ((*it)*(lDpiY/72.) - float(size))/float(size);
float newDiff = (((*it) * toPix) - float(size)) / float(size);
//kDebug( 6080 ) << "smooth font size: " << *it << " diff=" << newDiff;
if(newDiff < 0) newDiff = -newDiff;
if(newDiff < diff)
......@@ -661,7 +657,7 @@ void Font::update(int logicalDpiY) const
}
//kDebug( 6080 ) << "best smooth font size: " << bestSize << " diff=" << diff;
if ( bestSize != 0 && diff < 0.2 ) // 20% deviation, otherwise we use a scaled font...
size = (int)((bestSize*lDpiY) / 72);
size = static_cast<int>(bestSize * toPix);
}
// make sure we don't bust up X11
......
......@@ -25,6 +25,9 @@
#ifndef KHTMLFONT_H
#define KHTMLFONT_H
#include <khtml_global.h>
#include <khtml_settings.h>
#include <QCache>
#include <QtGui/QFont>
#include <QtGui/QFontMetrics>
......@@ -104,7 +107,7 @@ class FontDef
{
public:
FontDef()
: size( 0 ), italic( false ), smallCaps( false ), weight( QFont::Normal/*50*/ ) {}
: family(KHTMLGlobal::defaultHTMLSettings()->stdFontName()), size(0), italic(false), smallCaps(false), weight(QFont::Normal) {}
bool operator == ( const FontDef &other ) const {
return ( family == other.family &&
size == other.size &&
......
......@@ -1409,25 +1409,14 @@ void DocumentImpl::recalcStyle( StyleChange change )
RenderStyle* _style = new RenderStyle();
_style->setDisplay(BLOCK);
_style->setVisuallyOrdered( visuallyOrdered );
// ### make the font stuff _really_ work!!!!
khtml::FontDef fontDef;
QFont f = KGlobalSettings::generalFont();
fontDef.family = f.family();
fontDef.italic = f.italic();
fontDef.weight = f.weight();
if (m_view) {
const KHTMLSettings *settings = m_view->part()->settings();
QString stdfont = settings->stdFontName();
if ( !stdfont.isEmpty() )
fontDef.family = stdfont;
fontDef.size = m_styleSelector->fontSizes()[3];
}
// ### make the font stuff _really_ work!!!! (??)
//kDebug() << "DocumentImpl::attach: setting to charset " << settings->charset();
FontDef fontDef = FontDef();
// Initial fontDef.size is 0
fontDef.size = m_styleSelector->fontSizes()[3];
_style->setFontDef(fontDef);
_style->htmlFont().update( 0 );
_style->htmlFont().update(0);
if ( inCompatMode() )
_style->setHtmlHacks(true); // enable html specific rendering tricks
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment