+++ /dev/null
-// fontlist.cpp
-//
-// Part of the Architektonas Project
-// Originally part of QCad Community Edition by Andrew Mustun
-// Extensively rewritten and refactored by James L. Hammons
-// Portions copyright (C) 2001-2003 RibbonSoft
-// Copyright (C) 2010 Underground Software
-// See the README and GPLv2 files for licensing and warranty information
-//
-// JLH = James L. Hammons <jlhamm@acm.org>
-//
-// Who When What
-// --- ---------- -----------------------------------------------------------
-// JLH 05/27/2010 Added this text. :-)
-//
-
-#include "fontlist.h"
-
-#include "font.h"
-#include "entity.h"
-#include "system.h"
-
-//[DONE] #warning "!!! NEED TO FIX ITERATORS IN THIS CLASS !!!"
-
-FontList * FontList::uniqueInstance = NULL;
-
-/**
- * Default constructor.
- */
-FontList::FontList(): fontIterator(fonts)
-{
-//Dealt with here...
-//#warning "!!! Need to deal with setAutoDelete() Qt3->Qt4 !!!"
-// fonts.setAutoDelete(true);
- //fontListListeners.setAutoDelete(false);
-}
-
-/*static*/ FontList * FontList::instance()
-{
- if (uniqueInstance == NULL)
- uniqueInstance = new FontList();
-
- return uniqueInstance;
-}
-
-FontList::~FontList()
-{
- clearFonts();
-}
-
-/**
- * Initializes the font list by creating empty Font
- * objects, one for each font that could be found.
- */
-void FontList::init()
-{
- DEBUG->print("FontList::initFonts");
-
- QStringList list = SYSTEM->getFontList();
-// Q3Dict<char> added; //used to remeber added fonts (avoid duplication)
- QMultiHash<QString, char *> added; //used to remeber added fonts (avoid duplication)
-
- for(QStringList::Iterator it=list.begin(); it!=list.end(); ++it)
- {
- DEBUG->print("font: %s:", (*it).toLatin1().data());
-//printf("FontList::init(): font: %s:\n", (*it).toLatin1().data());
-
- QFileInfo fi(*it);
-
-// if (!added[fi.baseName()])
- if (added.value(fi.baseName()) == 0)
- {
- Font * font = new Font(fi.baseName());
- fonts.append(font);
- added.insert(fi.baseName(), (char *)1);
- }
-
- DEBUG->print("base: %s", fi.baseName().toLatin1().data());
- }
-}
-
-/**
- * Removes all fonts in the fontlist.
- */
-void FontList::clearFonts()
-{
-// fonts.clear();
- while (!fonts.isEmpty())
- delete fonts.takeFirst();
-}
-
-int FontList::countFonts()
-{
- return fonts.count();
-}
-
-/**
- * Removes a font from the list.
- * Listeners are notified after the font was removed from
- * the list but before it gets deleted.
- */
-void FontList::removeFont(Font * font)
-{
- DEBUG->print("FontList::removeFont()");
-
- // here the font is removed from the list but not deleted
-// fonts.remove(font);
- // Here we have to delete this ourselves, because there is no AutoDelete
- // for QLists
- int i = fonts.indexOf(font);
-
- if (i != -1)
- delete fonts.takeAt(i);
-
- //for (uint i=0; i<fontListListeners.count(); ++i) {
- // FontListListener* l = fontListListeners.at(i);
- // l->fontRemoved(font);
- //}
-}
-
-/**
- * @return Pointer to the font with the given name or
- * \p NULL if no such font was found. The font will be loaded into
- * memory if it's not already.
- */
-Font * FontList::requestFont(const QString & name)
-{
- DEBUG->print("FontList::requestFont %s", name.toLatin1().data());
-
- QString name2 = name.toLower();
- Font * foundFont = NULL;
-
- // QCad 1 compatibility:
- if (name2.contains('#') && name2.contains('_'))
-// name2 = name2.left(name2.find('_'));
- name2 = name2.left(name2.indexOf('_'));
- else if (name2.contains('#'))
-// name2 = name2.left(name2.find('#'));
- name2 = name2.left(name2.indexOf('#'));
-
- DEBUG->print("name2: %s", name2.toLatin1().data());
-
- // Search our list of available fonts:
-// for(Font * f=fonts.first(); f!=NULL; f=fonts.next())
- for(int i=0; i<fonts.size(); i++)
- {
- Font * f = fonts[i];
-
- if (f->getFileName() == name2)
- {
- // Make sure this font is loaded into memory:
- f->loadFont();
- foundFont = f;
- break;
- }
- }
-
- if (foundFont == NULL && name != "standard")
- foundFont = requestFont("standard");
-
- return foundFont;
-}
-
-//! @return First font of the list.
-Font * FontList::firstFont()
-{
-// return fonts.first();
-// fontIterator.toFront();
-// return fontIterator.next();
-
- fontIterator = fonts;
- return (fontIterator.hasNext() ? fontIterator.next() : NULL);
-}
-
-/**
- * @return Next font from the list after
- * calling firstFont() or nextFont().
- */
-Font * FontList::nextFont()
-{
-// return fonts.next();
-// return fontIterator.next();
- return (fontIterator.hasNext() ? fontIterator.next() : NULL);
-}
-
-/**
- * Dumps the fonts to stdout.
- */
-std::ostream & operator<<(std::ostream & os, FontList & l)
-{
- os << "Fontlist: \n";
-
- for(Font * f=l.firstFont(); f!=NULL; f=l.nextFont())
- os << *f << "\n";
-
- return os;
-}