Source Code (Use browser search to find items of interest.)

Class Index

qt'QtFontCharSet (./qt-2.1.0/src/kernel/qfontdatabase.cpp:185)

class QtFontCharSet {
public:
    QtFontCharSet( QtFontFamily *prnt, const QString n )
			  { p                = prnt;
			    nm               = n;
			    // charSet          = QFont::AnyCharSet;
			    dirty            = TRUE;
			    namesDirty       = TRUE;
			    bitmapScalable   = FALSE;
			    smoothlyScalable = FALSE;
			    normalStyle      = 0;
			    italicStyle      = 0;
			    boldStyle        = 0;
			    italicBoldStyle  = 0;
			    chSetDirty	     = TRUE;
			    chSet	     = QFont::AnyCharSet;
			  }


    const QString &name() const { return nm; }
    QFont::CharSet charSet() const;

    const QtFontFamily *parent() const { return p; }

    const QStringList &styles() const;
    const QtFontStyle *style( const QString &name ) const;

    bool isLocaleCharSet() const;
    bool isUnicode() const;

    bool isBitmapScalable() const;
    bool isSmoothlyScalable() const;

private:
    void refresh() const;

    QtFontFamily *p;
    QString nm;

    bool dirty;
    bool namesDirty;
    bool bitmapScalable;
    bool smoothlyScalable;

    bool chSetDirty;
    QFont::CharSet chSet;

    QtFontStyle *normalStyle; // Only makes sense if the font is scalable
    QtFontStyle *italicStyle; // Gives information about which
    QtFontStyle *boldStyle;   //  combinations of these are available.
    QtFontStyle *italicBoldStyle;


    void addStyle( QtFontStyle *style )
	{ styleDict.insert( style->name(), style );  }

    QDict<QtFontStyle> styleDict;
    QStringList styleNames;

    friend void QFontDatabase::createDatabase();
#ifdef _WS_WIN_
    friend void newWinFont( void * p );
    friend void add_style( QtFontCharSet *charSet, const QString& styleName,
		bool italic, bool lesserItalic, int weight );
#endif
};


qt'QtFontCharSet::styles() (./qt-2.1.0/src/kernel/qfontdatabase.cpp:476)

const QStringList &QtFontCharSet::styles() const
{
    if ( namesDirty ) {
	QtFontCharSet *that = (QtFontCharSet*) this;  // Mutable function
#ifdef _WS_WIN_
	// Lazy evaluation
	populate_database(parent()->name());
#endif
	QMap<QString, QString> styleMap;
	QDictIterator<QtFontStyle> iter( styleDict );
	QtFontStyle *tmp;
	for( ; (tmp = iter.current()) ; ++iter ) {
	    styleMap.insert( QString().setNum(styleSortValue( tmp ))+
			tmp->name(), tmp->name() );
	}
	QMap<QString,QString>::Iterator it = styleMap.begin();
	for ( ; it != styleMap.end(); ++it )
	    that->styleNames.append( *it );
	that->namesDirty = FALSE;
    }
    return styleNames;
}


qt'QtFontCharSet::style() (./qt-2.1.0/src/kernel/qfontdatabase.cpp:499)

const QtFontStyle *QtFontCharSet::style( const QString &s ) const
{
    return styleDict.find( s );
}


qt'QtFontCharSet::isLocaleCharSet() (./qt-2.1.0/src/kernel/qfontdatabase.cpp:504)

bool QtFontCharSet::isLocaleCharSet() const
{
    return charSet() == QFont::charSetForLocale();
}


qt'QtFontCharSet::isUnicode() (./qt-2.1.0/src/kernel/qfontdatabase.cpp:509)

bool QtFontCharSet::isUnicode() const
{
    return charSet() == QFont::Unicode;
}


qt'QtFontCharSet::isBitmapScalable() (./qt-2.1.0/src/kernel/qfontdatabase.cpp:514)

bool QtFontCharSet::isBitmapScalable() const
{
    refresh();
    return bitmapScalable;
}


qt'QtFontCharSet::isSmoothlyScalable() (./qt-2.1.0/src/kernel/qfontdatabase.cpp:520)

bool QtFontCharSet::isSmoothlyScalable() const
{
    refresh();
    return smoothlyScalable;
}

/*!
  Traverses all styles. If all of them are scalable, scalable is set to
  TRUE, if all of them are smoothly scalable smoothlyScalable is set to
  TRUE.

  The styles that most closely resemble a normal, italic, bold and bold
  italc font are found.
*/

qt'QtFontCharSet::refresh() (./qt-2.1.0/src/kernel/qfontdatabase.cpp:534)

void QtFontCharSet::refresh() const
{
    if ( !dirty )
	return;
    QtFontCharSet *that = (QtFontCharSet*)this; // mutable function
    that->smoothlyScalable = FALSE;
    that->bitmapScalable   = FALSE;

    that->normalStyle       = 0;
    that->italicStyle       = 0;
    that->boldStyle         = 0;
    that->italicBoldStyle   = 0;

    QtFontStyle *lesserItalicStyle     = 0;
    QtFontStyle *lesserItalicBoldStyle = 0;

    bool smooth = TRUE;
    bool bitmap = TRUE;
		 // Anything bolder than Normal qualifies as bold:
    int  bestBoldDiff             = QFont::Bold - QFont::Normal;
    int  bestItalicBoldDiff       = QFont::Bold - QFont::Normal;
    //int  bestLesserItalicBoldDiff = QFont::Bold - QFont::Normal; NOT USED
    int  bestNormal               = 0;
    int  bestItalicNormal         = 0;
    int  bestLesserItalicNormal   = 0;
    int  boldDiff;
    QtFontStyle *tmp;
    QDictIterator<QtFontStyle> iter(styleDict);
    for( ; (tmp = iter.current()) ; ++iter ) {
	if ( !tmp->isSmoothlyScalable() ) {
	    smooth = FALSE;
	    if ( !tmp->isBitmapScalable() )
		bitmap = FALSE;
	}
	if ( tmp->italic() ) {
	    if ( tmp->weight() < QFont::Normal ) {
		if ( tmp->weight() > bestItalicNormal ) {
		    that->italicStyle      = tmp;
		    bestItalicNormal = tmp->weight();
		}
	    } else {
		boldDiff = abs( tmp->weight() - QFont::Bold );
		if ( boldDiff < bestItalicBoldDiff ) {
		    that->italicBoldStyle    = tmp;
		    bestItalicBoldDiff = boldDiff;
		}

	    }
	} else if ( tmp->lesserItalic() ){
	    if ( tmp->weight() < QFont::Normal ) {
		if ( tmp->weight() > bestLesserItalicNormal ) {
		    lesserItalicStyle      = tmp;
		    bestLesserItalicNormal = tmp->weight();
		}
	    } else {
		boldDiff = abs( tmp->weight() - QFont::Bold );
		if ( boldDiff < bestItalicBoldDiff ) {
		    lesserItalicBoldStyle    = tmp;
		    //bestLesserItalicBoldDiff = boldDiff; NOT USED
		}

	    }
	} else {
	    if ( tmp->weight() < QFont::Normal ) {
		if ( tmp->weight() > bestNormal ) {
		    that->normalStyle = tmp;
		    bestNormal  = tmp->weight();
		}
	    } else {
		boldDiff = abs( tmp->weight() - QFont::Bold );
		if ( boldDiff < bestBoldDiff ) {
		    that->boldStyle    = tmp;
		    bestBoldDiff = boldDiff;
		}

	    }
	}
    }
    if ( !that->italicStyle && lesserItalicStyle )
	that->italicStyle = lesserItalicStyle;
    if ( !that->italicBoldStyle && lesserItalicBoldStyle )
	that->italicBoldStyle = lesserItalicBoldStyle;
    if ( smooth )
	that->smoothlyScalable = TRUE;
    else if ( bitmap )
	that->bitmapScalable = TRUE;
    that->dirty    = FALSE;
}