Permalink
Browse files

Changed - fontbook engine rewrite (2/n)

  • Loading branch information...
1 parent fbaecec commit e137c81695f499673f20dc6ac9eef5b6d71bc4c1 Pierre Marchand committed Sep 22, 2010
Showing with 59 additions and 3 deletions.
  1. +44 −3 src/fontbook.cpp
  2. +1 −0 src/fontbook.h
  3. +13 −0 src/fontitem.cpp
  4. +1 −0 src/fontitem.h
View
@@ -114,11 +114,13 @@ void FontBook::doFullBook()
{
// Full book
// <img>
- painter->drawText(printerRect, QString("Fontbook produced by Fontmatrix"));
progress = new ProgressBarDuo(typotek::getInstance());
- progress->setLabel(QString("Family"), 0);
- progress->setLabel(QString("Variant"), 1);
+
+ doFullBookCover();
+
+ progress->setLabel(QString("-"), 0);
+ progress->setLabel(QString("-"), 1);
progress->setMax(FMFontDb::DB()->getFilteredFonts(true).count(), 0);
progress->setMax(0, 1);
progress->show();
@@ -139,6 +141,44 @@ void FontBook::doFullBook()
delete progress;
}
+void FontBook::doFullBookCover()
+{
+ QGraphicsScene pScene(printerRect);
+
+ QFont aFont;
+ aFont.setPointSizeF(26.0);
+ QGraphicsSimpleTextItem * title(pScene.addSimpleText(QString("Fontmatrix"),aFont));
+ title->setPos(60, printerRect.height()*.9);
+
+ int module(250);
+ double x(0);
+ double y(0);
+ double fsize(qrand() % module);
+ int gray(qrand() % 160);
+ foreach(FontItem * f, FMFontDb::DB()->getFilteredFonts())
+ {
+ int lc(f->lastChar());
+ int charcode(qrand() % lc);
+ while(!f->hasCharcode(charcode))
+ charcode = qrand() % lc;
+
+ QGraphicsPathItem *p(f->itemFromChar(charcode, fsize));
+ if(p->data(GLYPH_DATA_ERROR).toBool())
+ {
+ delete p;
+ continue;
+ }
+ pScene.addItem(p);
+ p->setPos(x + (qrand() % qRound(printerRect.width())), y + (qrand() % qRound(printerRect.height())));
+ p->setBrush(QColor(gray, gray, gray));
+ p->setPen(Qt::NoPen);
+ gray = qrand() % 160;
+ fsize = qrand() % module;
+ }
+
+ pScene.render(painter, printer->paperRect(), printerRect);
+}
+
void FontBook::doFullBookPageRight(const QString &family)
{
qDebug()<<"=>"<<family;
@@ -399,6 +439,7 @@ bool FontBook::doFullBookPageLeft(const QString &family)
continue;
}
pScene.addItem(p);
+ p->setPen(Qt::NoPen);
double advance(p->data(GLYPH_DATA_HADVANCE_SCALED).toDouble());
double fakeAdvance(advance * 1.5);
if((ccX + fakeAdvance) > ccW)
View
@@ -111,6 +111,7 @@ class FontBook : public QObject
private:
void doFullBook();
+ void doFullBookCover();
// return true if uses only its page, false if it spreads over the 2 pages
bool doFullBookPageLeft(const QString& family);
void doFullBookPageRight(const QString& family);
View
@@ -1783,6 +1783,19 @@ int FontItem::countCoverage ( int begin_code, int end_code )
return count;//something weird with freetype which put a valid glyph at the beginning of each lang ??? Or a bug here...
}
+bool FontItem::hasCharcode(int cc)
+{
+ if(!ensureFace())
+ return false;
+ bool ret(true);
+ if( !FT_Get_Char_Index( m_face, cc ) )
+ {
+ ret = false;
+ }
+ releaseFace();
+ return ret;
+}
+
bool FontItem::hasChars(const QString & s)
{
if(!ensureFace())
View
@@ -244,6 +244,7 @@ class FontItem : public QObject
public slots:
QString renderSVG(const QString& s, const double& size);
int countCoverage ( int begin_code, int end_code );
+ bool hasCharcode(int cc);
bool hasChars(const QString& s);
int firstChar();
int lastChar();

0 comments on commit e137c81

Please sign in to comment.