#ifndef __ENCODINGS_H__
#define __ENCODINGS_H__

////////////////////////////////////////////////////////////////////////////////
//
// Class Name    : CEncodings
// Author        : Craig Drummond
// Project       : K Font Installer
// Creation Date : 29/04/2001
// Version       : $Revision: 1.1 $ $Date: 2003/07/18 22:46:16 $
//
////////////////////////////////////////////////////////////////////////////////
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
//
////////////////////////////////////////////////////////////////////////////////
// (C) Craig Drummond, 2001, 2002, 2003
////////////////////////////////////////////////////////////////////////////////

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <qstring.h>

#ifdef HAVE_FONT_ENC
#include <qstringlist.h>
#else
#include <qglobal.h>
#include <qptrlist.h>
#endif

class CEncodings
{
    public:

#ifndef HAVE_FONT_ENC
    struct T8Bit
    {
        enum EConstants
        {
            INDEX_OFFSET=32,
            NUM_MAP_ENTRIES = 256-INDEX_OFFSET
        };
 
        T8Bit(const QString &f, const QString &n, int *m=NULL) : file(f), name(n), map(m) {}
        virtual ~T8Bit();
 
        bool load();  // Load data in from file (if applicable...)
        QString file,
                name;
        int     *map;
    };

    struct T16Bit
    {
        T16Bit(const QString &f, const QString &n) : file(f), name(n) {}

        QString file,
                name;
    };
#endif

    CEncodings();
    virtual ~CEncodings()                                  { }

    bool                     createEncodingsDotDir(const QString &dir);

#ifdef HAVE_FONT_ENC
    const QStringList &      getList()                     { return itsList; }
    const QStringList &      getExtraList()                { return itsExtraList; }
#else
    void                     addDir(const QString &path)   { addDir(path, 0); }
    void                     clear()                       { its8BitList.clear(); its16BitList.clear(); }
    const QPtrList<T8Bit> &  list8Bit()                    { return its8BitList; }
    T8Bit *                  first8Bit()                   { return its8BitList.first(); }
    T8Bit *                  next8Bit()                    { return its8BitList.next(); }
    const QPtrList<T16Bit> & list16Bit()                   { return its16BitList; }
    T16Bit *                 first16Bit()                  { return its16BitList.first(); }
    T16Bit *                 next16Bit()                   { return its16BitList.next(); }
    T8Bit *                  get8Bit(const QString &enc);
    QString                  getFile8Bit(const QString &enc);
    static bool              isBuiltin(const T8Bit &enc);
    static bool              isAEncFile(const char *file);
    static bool              isUnicode(const QString &enc) { return strcmp(constUnicode.latin1(), enc.latin1())==0 ? true : false; }

#endif

    static const QString constUnicode;
    static const QString constT1Symbol;
    static const QString constTTSymbol;

    private:

#ifndef HAVE_FONT_ENC
    void                     addDir(const QString &path, int sub);
#endif

#ifdef HAVE_FONT_ENC
    QStringList      itsList,
                     itsExtraList;
#else
    QPtrList<T8Bit>  its8BitList;
    QPtrList<T16Bit> its16BitList;
    unsigned int     itsNumBuiltin;
#endif
};

#endif
