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

Class Index

qt'QFontDatabase (./qt-2.1.0/src/kernel/qfontdatabase.h:44)

class Q_EXPORT QFontDatabase
{
public:
    QFontDatabase();

    QStringList families( bool onlyForLocale = TRUE ) const;
    QValueList<int> pointSizes( const QString &family,
				const QString &style = QString::null,
				const QString &charSet = QString::null );
    QStringList styles( const QString &family,
			const QString &charSet = QString::null ) const;
    QStringList charSets( const QString &familyName,
			  bool onlyForLocale = TRUE ) const;

    QFont font( const QString familyName, const QString &style,
		int pointSize, const QString charSetName = QString::null );

    bool  isBitmapScalable( const QString &family,
			    const QString &style   = QString::null,
			    const QString &charSet = QString::null ) const;
    bool  isSmoothlyScalable( const QString &family,
			      const QString &style   = QString::null,
			      const QString &charSet = QString::null ) const;
    bool  isScalable( const QString &family,
		      const QString &style   = QString::null,
		      const QString &charSet = QString::null ) const;

    QValueList<int> smoothSizes( const QString &family,
				 const QString &style,
				 const QString &charSet = QString::null );

    static QValueList<int> standardSizes();

    bool italic( const QString &family,
		 const QString &style,
		 const QString &charSet = QString::null ) const;

    bool bold( const QString &family,
	       const QString &style,
	       const QString &charSet = QString::null ) const;

    int weight( const QString &family,
		const QString &style,
		const QString &charSet = QString::null ) const;


#if 0
    QValueList<QFont::CharSet> charSets( const QString &familyName ) const;
    bool  supportsCharSet( const QString &familyName,
			   const QString &charSet ) const;
    bool  supportsCharSet( const QString &familyName,
			   QFont::CharSet charSet ) const;
#endif

    QString styleString( const QFont &);

    static QString verboseCharSetName( const QString & charSetName );
    static QString charSetSample( const QString & charSetName );

private:
    static void createDatabase();

    QFontDatabasePrivate *d;

};

qt'QFontDatabase::createDatabase() (./qt-2.1.0/src/kernel/qfontdatabase.cpp:907)

void QFontDatabase::createDatabase()
{
    if ( db ) return;

    db = new QFontDatabasePrivate;

#if 0
    xFontList = readFontDump( "test.fonts", &xFontCount );
    if ( xFontList )
	qWarning("Read font definitions from the file \"test.fonts\""
		 " for debugging\n"
		 "Expect strange results in the font dialog.\n" );
    else
#endif
    xFontList = XListFonts( qt_xdisplay(), "*", 32767, &xFontCount );

    if ( xFontCount >= 32767 )
	qWarning( "More than 32k fonts, please notify qt-bugs@trolltech.com" );

    char *tokens[fontFields];

    for( int i = 0 ; i < xFontCount ; i++ ) {
	QCString fName = xFontList[i];
	if ( qParseXFontName( fName, tokens ) ) {
	    QString foundryName = tokens[Foundry];
	    QtFontFoundry *foundry = db->foundryDict.find( foundryName );
	    if ( !foundry ) {
		//qWarning( "New font foundry [%s]", (const char*) foundryName );
		foundry = new QtFontFoundry( foundryName );
		CHECK_PTR(foundry);
		db->addFoundry( foundry );
	    }
	    QString familyName = tokens[Family];
	    QtFontFamily *family = foundry->familyDict.find( familyName );
	    if ( !family ) {
		//qWarning( "New font family [%s][%s]",
		// (const char*) familyName, (const char*) foundryName );
		family = new QtFontFamily( foundry, familyName );
		CHECK_PTR(family);
		foundry->addFamily( family );
	    }
	    QString charSetName = getCharSetName( tokens[CharsetRegistry],
						 tokens[CharsetEncoding] );
	    QtFontCharSet *charSet = family->charSetDict.find( charSetName );
	    if ( !charSet ) {
		//qWarning( "New charset[%s] for family [%s][%s]",
		// (const char*)charSetName, (const char *)familyName,
		// (const char *)foundryName );
		charSet = new QtFontCharSet( family, charSetName );
		CHECK_PTR(charSet);
		family->addCharSet( charSet );
	    }
	    bool italic;
	    bool lesserItalic;
	    QString styleName = getStyleName( tokens, &italic, &lesserItalic );
	    QtFontStyle *style = charSet->styleDict.find( styleName );
	    if ( !style ) {
		//qWarning( "New style[%s] for [%s][%s][%s]",
		// (const char*)styleName, (const char*)charSetName,
		// (const char*)familyName, (const char *)foundryName );
		style = new QtFontStyle( charSet, styleName );
		CHECK_PTR( style );
		style->ital         = italic;
		style->lesserItal   = lesserItalic;
		style->weightString = tokens[Weight_];
		charSet->addStyle( style );
	    }
	    if ( ::isScalable(tokens) ) {
		if ( ::isSmoothlyScalable( tokens ) ) {
		    style->setSmoothlyScalable();
		    //qWarning( "Smooth [%s][%s][%s]", (const char*) styleName,
		    //     (const char*)charSetName,
		    //     tokens[Family] );
		} else {
		    style->setBitmapScalable();
		    //qWarning( "Scalable, [%s][%s]", (const char*)charSetName,
		    //     tokens[Family] );
		}
	    } else {
		QCString ps = tokens[PointSize];
		int pSize = ps.toInt()/10;
		if ( pSize != 0 ) {
		    style->addPointSize( pSize );
		}
	    }
	} else {
	    //qWarning( "createDatabase: Not XLFD[%s]", xFontList[i] );
	}
    }
}

#endif


#ifdef _WS_WIN_

extern Qt::WindowsVersion qt_winver;		// defined in qapplication_win.cpp

static
int CALLBACK

qt'QFontDatabase::createDatabase() (./qt-2.1.0/src/kernel/qfontdatabase.cpp:1210)

void QFontDatabase::createDatabase()
{
    if ( db ) return;
    db = new QFontDatabasePrivate;
    populate_database(0);
}


#endif




#if 0
static QFont::CharSet getCharSet( const char * registry, const char *encoding )
{
    if ( strcmp( registry, "iso8859" ) == 0 ) {
	if ( encoding[0] != 0 && encoding[1] == 0 ) {
	    switch( encoding[0] ) {
	    case '1': return QFont::ISO_8859_1;
	    case '2': return QFont::ISO_8859_2;
	    case '3': return QFont::ISO_8859_3;
	    case '4': return QFont::ISO_8859_4;
	    case '5': return QFont::ISO_8859_5;
	    case '6': return QFont::ISO_8859_6;
	    case '7': return QFont::ISO_8859_7;
	    case '8': return QFont::ISO_8859_8;
	    case '9': return QFont::ISO_8859_9;
	    default: break;
	    }
	} else if ( encoding[0] == '1' && encoding[1] != 0
		    && encoding[2] == 0 ) {
	    switch( encoding[0] ) {
	    case '0': return QFont::ISO_8859_10;
	    case '1': return QFont::ISO_8859_11;
	    case '2': return QFont::ISO_8859_12;
	    case '3': return QFont::ISO_8859_13;
	    case '4': return QFont::ISO_8859_14;
	    case '5': return QFont::ISO_8859_15;
	    default: break;
	    }
	}
	return QFont::AnyCharSet;
    } else if ( strcmp( registry, "koi8" ) == 0 &&
		(strcmp( encoding, "r" ) == 0 ||
		 strcmp( encoding, "1" ) == 0) ) {
	return QFont::KOI8R;
    } else if ( strcmp( registry, "iso10646" ) == 0 ) {
	return QFont::Unicode;
    }
    return QFont::AnyCharSet;
}

qt'QFontDatabase::verboseCharSetName() (./qt-2.1.0/src/kernel/qfontdatabase.cpp:1381)

QString QFontDatabase::verboseCharSetName( const QString &charSetName )
{
    QFont::CharSet cs = getCharSet( charSetName );
    if ( cs != QFont::AnyCharSet )
	return getCharSetName( cs );
    else
	return charSetName;
}


qt'QFontDatabase::charSetSample() (./qt-2.1.0/src/kernel/qfontdatabase.cpp:1495)

QString QFontDatabase::charSetSample( const QString &charSetName )
{
    QFont::CharSet cs = getCharSet( charSetName );
    if ( cs == QFont::AnyCharSet )
	cs = QFont::ISO_8859_1;
    return getCharSetSample( cs );
}


/*!
  Returns a string with describes the style of the font \a f. This is Something like
  "Bold Italic".
*/


qt'QFontDatabase::styleString() (./qt-2.1.0/src/kernel/qfontdatabase.cpp:1509)

QString QFontDatabase::styleString( const QFont &f )  // ### fttb
{

    QString result;
    if ( f.weight() >= QFont::Bold ) {
	if ( f.italic() )
	    result = "Bold Italic";
	else
	    result = "Bold";
    } else {
	if ( f.italic() )
	    result = "Italic";
	else
	    result = "Normal";
    }
    return result;
}

qt'QFontDatabase::QFontDatabase() (./qt-2.1.0/src/kernel/qfontdatabase.cpp:1600)

QFontDatabase::QFontDatabase()
{
    createDatabase();
    d = db;
}

/*!
  Retrurns a list of names of all available font families in the current locale if
  \a onlyForLocale is TRUE, otherwise really all available font families independent
  of the current locale are returned.
*/


qt'QFontDatabase::families() (./qt-2.1.0/src/kernel/qfontdatabase.cpp:1612)

QStringList QFontDatabase::families( bool onlyForLocale ) const
{
    return d->families( onlyForLocale );
}

/*!
  Retruns all available styles of the font \a family in the
  char set \a charSet.
*/


qt'QFontDatabase::styles() (./qt-2.1.0/src/kernel/qfontdatabase.cpp:1622)

QStringList QFontDatabase::styles( const QString &family,
					  const QString &charSet ) const
{
    QString cs( charSet );
    if ( charSet.isEmpty() ) {
	QStringList lst = charSets( family );
	cs = lst.first();
    }
    const QtFontFamily *fam = d->family( family );
    if ( !fam )
	return emptyList;
    const QtFontCharSet * chSet = fam->charSet( cs );
    return chSet ? chSet->styles() : emptyList;
}

/*!
  Returns whether the font which matches \a family, \a style and \a charSet is
  a scaleable bitmap font. Scaling a bitmap font produces a bad, often hardly
  readable result, as the pixels of the font are scaled. It's better to scale such
  a font only to the available fixed sizes (which you can get with smoothSizes()).

  \sa isScalable(), isSmoothlyScalable()
*/


qt'QFontDatabase::isBitmapScalable() (./qt-2.1.0/src/kernel/qfontdatabase.cpp:1646)

bool  QFontDatabase::isBitmapScalable( const QString &family,
				       const QString &style,
				       const QString &charSet ) const
{
    const QtFontFamily *fam = d->family( family );
    if ( !fam )
	return FALSE;
    if ( style.isEmpty() )
	return fam->isBitmapScalable();
    const QtFontCharSet * chSet = fam->charSet( charSet );;
    if ( !chSet )
	return FALSE;
    if ( style.isEmpty() )
	return chSet->isBitmapScalable();
    const QtFontStyle *sty = chSet->style( style );
    return sty && sty->isBitmapScalable();
}

/*!
  Returns whether the font which matches \a family, \a style and \a charSet is
  a smoothly scaleable. If this function returns TRUE, it's save to scale this font
  to every size as the result will always look good.

  \sa isScalable(), isBitmapScalable()
*/


qt'QFontDatabase::isSmoothlyScalable() (./qt-2.1.0/src/kernel/qfontdatabase.cpp:1672)

bool  QFontDatabase::isSmoothlyScalable( const QString &family,
					 const QString &style,
					 const QString &charSet ) const
{
    const QtFontFamily *fam = d->family( family );
    if ( !fam )
	return FALSE;
    if ( style.isEmpty() )
	return fam->isSmoothlyScalable();
    const QtFontCharSet * chSet = fam->charSet( charSet );;
    if ( !chSet )
	return FALSE;
    if ( style.isEmpty() )
	return chSet->isSmoothlyScalable();
    const QtFontStyle *sty = chSet->style( style );
    return sty && sty->isSmoothlyScalable();
}

/*!
  Returns TRUE if the font which matches the settings \a family, \a style and \a charSet
  is scaleable.

  \sa isBitmapScalable(), isSmoothlyScalable()
*/


qt'QFontDatabase::isScalable() (./qt-2.1.0/src/kernel/qfontdatabase.cpp:1697)

bool  QFontDatabase::isScalable( const QString &family,
				 const QString &style,
				 const QString &charSet ) const
{
    if ( isSmoothlyScalable( family, style, charSet) )
	return TRUE;
    return isBitmapScalable( family, style, charSet );
}


qt'QFontDatabase::pointSizes() (./qt-2.1.0/src/kernel/qfontdatabase.cpp:1729)

QValueList<int> QFontDatabase::pointSizes( const QString &family,
						 const QString &style,
						 const QString &charSet )
{
    QString cs( charSet );
    if ( charSet.isEmpty() ) {
	QStringList lst = charSets( family );
	cs = lst.first();
    }
    QString s( style );
    if ( style.isEmpty() ) {
	QStringList lst = styles( family, cs );
	s = lst.first();
    }
    const QtFontStyle *sty = getStyle( d, family, s, cs );
    return sty ? sty->pointSizes() : emptySizeList;
}


/*!
  Returns a QFont object which matches the settings of \a family, \a style,
  \a pointsize and \a charSet. If no matching font could be created
  an empty QFont object is returned.
*/


qt'QFontDatabase::font() (./qt-2.1.0/src/kernel/qfontdatabase.cpp:1754)

QFont QFontDatabase::font( const QString family, const QString &style,
			   int pointSize, const QString charSet )
{
    const QtFontStyle *sty = getStyle( d, family, style, charSet );
    if ( !sty ) {
	qWarning( "QFontDatabase::font: Style not found for\n"
		  "%s, %s, %s", (const char*)family,
		  (const char*)style, (const char*)charSet );
	return QFont();
    }
    return sty->font( family, pointSize );
}

/*!
  Returns the point sizes of a font which matches \a family, \a style and \a charSet,
  that is guaranteed to look good. For non-scalable fonts and smoothly scalable fonts this function
  is equivalent to pointSizes().

  \sa pointSizes(), standardSizes()
*/


qt'QFontDatabase::smoothSizes() (./qt-2.1.0/src/kernel/qfontdatabase.cpp:1775)

QValueList<int> QFontDatabase::smoothSizes( const QString &family,
						  const QString &style,
						  const QString &charSet )
{
    const QtFontStyle *sty = getStyle( d, family, style, charSet );
    return sty ? sty->smoothSizes() : emptySizeList;
}

/*!
  Returns a list of standard fontsizes.

  \sa smoothSizes(), pointSizes()
*/


qt'QFontDatabase::standardSizes() (./qt-2.1.0/src/kernel/qfontdatabase.cpp:1789)

QValueList<int> QFontDatabase::standardSizes()
{
    return QtFontStyle::standardSizes();
}

/*!
  Returns if the font witch matches the settings \a family, \a style and
  \a charSet is italic or not.

  \sa weight(), bold()
*/


qt'QFontDatabase::italic() (./qt-2.1.0/src/kernel/qfontdatabase.cpp:1801)

bool QFontDatabase::italic( const QString &family,
			    const QString &style,
			    const QString &charSet ) const
{
    const QtFontStyle *sty = getStyle( d, family, style, charSet );
    return sty && sty->italic();
}

/*!
  Returns if the font witch matches the settings \a family, \a style and
  \a charSet is bold or not.

  \sa italic(), weight()
*/


qt'QFontDatabase::bold() (./qt-2.1.0/src/kernel/qfontdatabase.cpp:1816)

bool QFontDatabase::bold( const QString &family,
			    const QString &style,
			    const QString &charSet ) const
{
    const QtFontStyle *sty = getStyle( d, family, style, charSet );
    return sty && sty->weight() >= QFont::Bold;
}

/*!
  Returns the weight of the font witch matches the settings \a family, \a style and
  \a charSet.

  \sa italic(), bold()
*/


qt'QFontDatabase::weight() (./qt-2.1.0/src/kernel/qfontdatabase.cpp:1831)

int QFontDatabase::weight( const QString &family,
			   const QString &style,
			   const QString &charSet ) const
{
    const QtFontStyle *sty = getStyle( d, family, style, charSet );
    return sty ? sty->weight() : -1;
}

/*!
  Returns a list of all char sets in which the font \a family is available in the
  current locale if \a onlyForLocale is TRUE, otherwise all charsets of \a family
  independent of the locale are returned.
*/


qt'QFontDatabase::charSets() (./qt-2.1.0/src/kernel/qfontdatabase.cpp:1845)

QStringList QFontDatabase::charSets( const QString &family,
					   bool onlyForLocale ) const
{
    const QtFontFamily *fam = d->family( family );
    return fam ? fam->charSets( onlyForLocale ) : emptyList;
}