Source Code (Use browser search to find items of interest.)
Class Index
kdelibs'KCharsets (./kdelibs/kdecore/kcharsets.h:44)
class KCharsets
{
friend class KGlobal;
protected:
/** protected constructor. If you need the kcharsets object, use
@ref KGlobal::charsets() instead.
*/
KCharsets();
public:
/** destructor */
virtual ~KCharsets(){}
/**
* converts an entity to a character. The string must contain only the
* entity without the trailing ';'.
* @returns QChar::null if the entity could not be decoded.
*/
QChar fromEntity(const QString &str) const;
/**
* Overloaded member function. Tries to find an entity in the
* @ref QString str.
* @returns a decoded entity if one could be found, @ref QChar::null
* otherwise
* @param len is a return value, that gives the length of the decoded
* entity.
*/
QChar fromEntity(const QString &str, int &len) const;
/**
* converts a QChar to an entity. The returned string does already
* contain the leading '&' and the trailing ';'.
*/
QString toEntity(const QChar &ch) const;
/**
* lists all available charsets for a given family.
* if family is omitted, it will return all charsets available.
*/
QList<QFont::CharSet> availableCharsets(QString family = QString::null);
/**
* as above, but returns the names of the charsets
*/
QStringList availableCharsetNames(QString family = QString::null);
/**
* @returns a QFont, which can print the character given, and is closest
* to the font given. if no mathing font could be found, the returned font
* will have the charset @ref QFont::Any.
*/
QFont fontForChar( const QChar &ch, const QFont &f ) const;
//FIXME: setQfont without ecnod arg should return charsetforlocale
// or unicode...
/**
* sets the @ref QFont f to the charset given in charset.
* Opposed to @ref QFont's setCharset() function, this function will do
* it's best to find a font which can display the given charset. It might
* change the font's family for this purpose, but care is taken to find
* a family which is as close as possible to the font given.
*/
void setQFont(QFont &f, QFont::CharSet charset = QFont::Unicode) const;
/**
* overloaded member function. Provided for convenience.
*/
void setQFont(QFont &f, QString charset) const;
/**
* @returns the name of the charset f is set to.
*/
QString name(const QFont &f);
/**
* @returns the name of the Charset c.
*/
QString name(QFont::CharSet c);
/**
* is a font with the given charset available?
*/
bool isAvailable(QFont::CharSet charset);
/**
* overloaded member function. Provided for convenience.
*/
bool isAvailable(const QString &charset);
/**
* @returns the charset for the locale.
*/
QFont::CharSet charsetForLocale();
/**
* does the given font family have a unicode encoding?
*/
bool hasUnicode(QString family) const;
/**
* does given font exist with a unicode encoding?
*/
bool hasUnicode(QFont &font) const;
enum FixedType { FixedUnknown, Fixed, Proportional };
enum WeightType { WeightUnknown, Medium, Bold };
enum SlantType { SlantUnknown, Normal, Italic };
protected:
void getFontList(KFontStruct mask, KFontStructList& lst) const;
public:
QString xCharsetName(QFont::CharSet) const;
QFont::CharSet nameToID(QString name) const;
QFont::CharSet xNameToID(QString name) const;
private:
KCharsetsPrivate *d;
};
/**
* Information about a font.
* @internal
* @deprecated
*/
kdelibs'KCharsets::KCharsets() (./kdelibs/kdecore/kcharsets.cpp:178)
KCharsets::KCharsets()
{
// do some initialization
}
kdelibs'KCharsets::fromEntity() (./kdelibs/kdecore/kcharsets.cpp:183)
QChar KCharsets::fromEntity(const QString &str) const
{
QChar res = QChar::null;
int pos = 0;
if(str[pos] == '&') pos++;
// Check for '' or '' sequence
if (str[pos] == '#' && str.length()-pos > 1) {
bool ok;
pos++;
if (str[pos] == 'x' || str[pos] == 'X') {
pos++;
// '', hexadeciaml character reference
QString tmp(str.unicode()+pos, str.length()-pos);
res = tmp.toInt(&ok, 16);
} else {
// '', deciaml character reference
QString tmp(str.unicode()+pos, str.length()-pos);
res = tmp.toInt(&ok, 10);
}
return res;
}
const entity *e = findEntity(str.ascii(), str.length());
if(!e)
{
kdDebug( 0 ) << "unknown entity '%s', len = %d\n" << str.ascii() << str.length() << endl;
return QChar::null;
}
//printf("got entity %s = %x\n", str.ascii(), e->code);
return QChar(e->code);
}
kdelibs'KCharsets::fromEntity() (./kdelibs/kdecore/kcharsets.cpp:219)
QChar KCharsets::fromEntity(const QString &str, int &len) const
{
// entities are never longer than 8 chars... we start from
// that length and work backwards...
len = 8;
while(len > 0)
{
QString tmp = str.left(len);
QChar res = fromEntity(tmp);
if( res != QChar::null ) return res;
len--;
}
return QChar::null;
}
kdelibs'KCharsets::toEntity() (./kdelibs/kdecore/kcharsets.cpp:235)
QString KCharsets::toEntity(const QChar &ch) const
{
QString ent;
ent.sprintf("&0x%x;", ch.unicode());
return ent;
}
kdelibs'KCharsets::availableCharsets() (./kdelibs/kdecore/kcharsets.cpp:242)
QList<QFont::CharSet> KCharsets::availableCharsets(QString family)
{
KFontStruct mask;
mask.family = family;
KFontStructList lst;
getFontList(mask, lst);
QList<QFont::CharSet> chList;
KFontStruct *fs;
for(fs = lst.first(); fs != 0; fs = lst.next() )
{
if(!chList.contains(&(fs->charset)))
{
QFont::CharSet *c = new QFont::CharSet;
*c = fs->charset;
chList.append(c);
}
return chList;
}
}
kdelibs'KCharsets::availableCharsetNames() (./kdelibs/kdecore/kcharsets.cpp:266)
QStringList KCharsets::availableCharsetNames(QString family)
{
KFontStruct mask;
mask.family = family;
KFontStructList lst;
getFontList(mask, lst);
QStringList chList;
KFontStruct *fs;
for(fs = lst.first(); fs != 0; fs = lst.next() )
{
if(fs->charset != QFont::AnyCharSet )
{
QString name = this->name(fs->charset);
if(!chList.contains(name))
chList.append(name);
}
}
return chList;
}
kdelibs'KCharsets::fontForChar() (./kdelibs/kdecore/kcharsets.cpp:289)
QFont KCharsets::fontForChar( const QChar &c, const QFont &_f ) const
{
QFontInfo fi(_f);
// unicode can display any char...
if (fi.charSet() == QFont::Unicode) return _f;
// here comes the work...
// we look at the range the char is in, and try charsets which can
// map the char...
QFont f = _f;
int uc = c.unicode();
if( uc < 0xff ) // 8859-1
setQFont( f, QFont::Latin1 );
else if ( uc > 0x0400 && uc < 0x0460 )
setQFont( f, QFont::Latin5 );
else if ( uc > 0x0600 && uc < 0x0660 )
setQFont( f, QFont::Latin6 );
else if ( uc > 0x0380 && uc < 0x03e0 )
setQFont( f, QFont::Latin7 );
else if ( uc >= 0x05d0 && uc < 0x05f0 )
setQFont( f, QFont::Latin8 );
else if ( hasUnicode( f ) ) // don't know, let's try Unicode
setQFont( f, QFont::Unicode );
return f;
}
kdelibs'KCharsets::setQFont() (./kdelibs/kdecore/kcharsets.cpp:318)
void KCharsets::setQFont(QFont &f, QString charset) const
{
setQFont(f, nameToID(charset));
}
kdelibs'KCharsets::setQFont() (./kdelibs/kdecore/kcharsets.cpp:322)
void KCharsets::setQFont(QFont &f, QFont::CharSet charset) const
{
KFontStruct mask;
KFontStructList list;
mask = f;
mask.charset = charset;
getFontList(mask, list);
if(!list.isEmpty()) {
f.setCharSet(charset);
return;
}
// let's try unicode...
mask.charset = QFont::Unicode;
getFontList(mask, list);
if(!list.isEmpty()) {
// just setting the charset to unicode should work
f.setCharSet(QFont::Unicode);
return;
}
// ok... we don't have the charset in the specified family, let's
// try to find a replacement.
mask.charset = charset;
getFontList(mask, list);
if(!list.isEmpty()) {
f.setFamily(list.first()->family);
f.setCharSet(charset);
return;
}
mask.charset = QFont::Unicode;
mask.family = QString::null;
getFontList(mask, list);
if(!list.isEmpty()) {
f.setFamily(list.first()->family);
f.setCharSet(QFont::Unicode);
return;
}
KFontStruct m;
m.charset = charset;
getFontList(m, list);
if(!list.isEmpty()) {
f.setFamily(list.first()->family);
f.setCharSet(charset);
return;
}
f.setCharSet(QFont::AnyCharSet);
return;
}
kdelibs'KCharsets::isAvailable() (./kdelibs/kdecore/kcharsets.cpp:377)
bool KCharsets::isAvailable(const QString &charset)
{
return isAvailable(nameToID(charset));
}
kdelibs'KCharsets::isAvailable() (./kdelibs/kdecore/kcharsets.cpp:382)
bool KCharsets::isAvailable(QFont::CharSet charset)
{
KFontStruct fs;
fs.charset = charset;
KFontStructList list;
getFontList(fs, list);
if(!list.isEmpty())
return true;
return false;
}
kdelibs'KCharsets::getFontList() (./kdelibs/kdecore/kcharsets.cpp:398)
void KCharsets::getFontList(KFontStruct mask, KFontStructList& lst) const
{
char **fontNames;
int numFonts;
Display *kde_display;
kde_display = kapp->getDisplay();
lst.setAutoDelete(true);
lst.clear();
QString maskStr("-*-");
if(!mask.family.isEmpty())
maskStr += mask.family;
else
maskStr += "*";
// we sort out wrong slants afterwards...
switch ( mask.weight ) {
case WeightUnknown:
maskStr += "-*-*-*-*-";
break;
case Medium:
maskStr += "-medium-*-*-*-";
break;
case Bold:
maskStr += "-bold-*-*-*-";
break;
}
if(mask.scalable)
maskStr += "0-0-*-*-*-"; // perhaps "0-0-0-0-*-" ????
else
maskStr += "*-*-*-*-*-";
maskStr += xCharsetName(mask.charset);
fontNames = XListFonts(kde_display, maskStr.latin1(), 32767, &numFonts);
for(int i = 0; i < numFonts; i++) {
KFontStruct *f = new KFontStruct;
QCString qfontname = fontNames[i];
int dash = qfontname.find ('-', 1, true); // find next dash
if (dash == -1) continue;
// the font name is between the second and third dash so:
// let's find the third dash:
int dash_two = qfontname.find ('-', dash + 1 , true);
if (dash == -1) continue;
// fish the name of the font info string
f->family = qfontname.mid(dash +1, dash_two - dash -1);
if(qfontname.find("-p-") != -1)
f->fixed = Proportional;
else
f->fixed = Fixed;
if(qfontname.find("-r-") != -1)
f->slant = Normal;
else
f->slant = Italic;
if(qfontname.find("-0-0-") != -1)
f->scalable = true;
if(qfontname.find("-b-") != -1)
f->weight = Bold;
else
f->weight = Medium;
// get the charset...
dash = qfontname.findRev('-');
dash = qfontname.findRev('-', dash-1);
QString xname = qfontname.right(qfontname.length()-dash-1);
f->charset = xNameToID(xname);
lst.append(f);
}
XFreeFontNames(fontNames);
}
QFont::CharSet KCharsets::charsetForLocale()
{
return nameToID(KGlobal::locale()->charset());
}
kdelibs'KCharsets::hasUnicode() (./kdelibs/kdecore/kcharsets.cpp:483)
bool KCharsets::hasUnicode(QString family) const
{
KFontStruct fs;
fs.family = family;
fs.charset = QFont::Unicode;
KFontStructList l;
getFontList(fs, l);
return !l.isEmpty();
}
kdelibs'KCharsets::hasUnicode() (./kdelibs/kdecore/kcharsets.cpp:495)
bool KCharsets::hasUnicode(QFont &font) const
{
return hasUnicode(font.family());
}
kdelibs'KCharsets::xCharsetName() (./kdelibs/kdecore/kcharsets.cpp:501)
QString KCharsets::xCharsetName(QFont::CharSet charSet) const
{
switch( charSet )
{
case QFont::Unicode:
return "iso10646-1";
case QFont::ISO_8859_1:
return "iso8859-1";
case QFont::ISO_8859_2:
return "iso8859-2";
case QFont::ISO_8859_3:
return "iso8859-3";
case QFont::ISO_8859_4:
return "iso8859-4";
case QFont::ISO_8859_5:
return "iso8859-5";
case QFont::ISO_8859_6:
return "iso8859-6";
case QFont::ISO_8859_7:
return "iso8859-7";
case QFont::ISO_8859_8:
return "iso8859-8";
case QFont::ISO_8859_9:
return "iso8859-9";
case QFont::ISO_8859_10:
return "iso8859-10";
case QFont::ISO_8859_11:
return "iso8859-11";
case QFont::ISO_8859_12:
return "iso8859-12";
case QFont::ISO_8859_13:
return "iso8859-13";
case QFont::ISO_8859_14:
return "iso8859-14";
case QFont::ISO_8859_15:
return "iso8859-15";
case QFont::KOI8R:
return "koi8-*";
case QFont::Set_Ko:
return "ksc5601.1987-0";
case QFont::Set_Ja:
return "jisx0208.1983-0";
case QFont::Set_Th_TH:
case QFont::Set_Zh:
case QFont::Set_Zh_TW:
case QFont::AnyCharSet:
default:
break;
}
return "*-*";
}
QFont::CharSet KCharsets::nameToID(QString name) const
{
name = name.lower();
int i = 0;
while(i < CHARSETS_COUNT)
{
if( name == charsetsStr[i] )
return charsetsIds[i];
i++;
}
while(i < CHARSETS_COUNT)
{
if( name == xNames[i] )
return charsetsIds[i];
i++;
}
return QFont::AnyCharSet;
}
kdelibs'KCharsets::name() (./kdelibs/kdecore/kcharsets.cpp:573)
QString KCharsets::name(const QFont &f)
{
QFont::CharSet c = f.charSet();
return name(c);
}
kdelibs'KCharsets::name() (./kdelibs/kdecore/kcharsets.cpp:580)
QString KCharsets::name(QFont::CharSet c)
{
int i = 0;
while(i < CHARSETS_COUNT)
{
if( c == charsetsIds[i] )
return charsetsStr[i];
i++;
}
return "any";
}
QFont::CharSet KCharsets::xNameToID(QString name) const
{
name = name.lower();
int i = 0;
while(i < CHARSETS_COUNT)
{
if( name == xNames[i] )
return charsetsIds[i];
i++;
}
return QFont::AnyCharSet;
}