From 6f06793f58f520ec7d44683f6447c0b540a265b3 Mon Sep 17 00:00:00 2001 From: Robert Bieber Date: Wed, 7 Jul 2010 08:41:36 +0000 Subject: Theme Editor: Fixed rendering bug that caused text in sublines not to appear, implemented a global font cache git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27331 a1c6a512-1295-4272-9138-f99709370657 --- utils/themeeditor/graphics/rbfont.cpp | 29 ++++++++++++++---- utils/themeeditor/graphics/rbfontcache.cpp | 24 +++++++++++++++ utils/themeeditor/graphics/rbfontcache.h | 48 ++++++++++++++++++++++++++++++ utils/themeeditor/graphics/rbviewport.h | 6 ++++ 4 files changed, 101 insertions(+), 6 deletions(-) create mode 100644 utils/themeeditor/graphics/rbfontcache.cpp create mode 100644 utils/themeeditor/graphics/rbfontcache.h (limited to 'utils/themeeditor/graphics') diff --git a/utils/themeeditor/graphics/rbfont.cpp b/utils/themeeditor/graphics/rbfont.cpp index 07308fac7e..cd68af99fe 100644 --- a/utils/themeeditor/graphics/rbfont.cpp +++ b/utils/themeeditor/graphics/rbfont.cpp @@ -20,6 +20,7 @@ ****************************************************************************/ #include "rbfont.h" +#include "rbfontcache.h" #include #include @@ -29,6 +30,8 @@ #include #include +#include + quint16 RBFont::maxFontSizeFor16BitOffsets = 0xFFDB; RBFont::RBFont(QString file) @@ -52,6 +55,18 @@ RBFont::RBFont(QString file) } header.insert("filename", file); + /* Checking for a cache entry */ + RBFontCache::CacheInfo* cache = RBFontCache::lookup(file); + if(cache) + { + imageData = cache->imageData; + offsetData = cache->offsetData; + widthData = cache->widthData; + header = cache->header; + + return; + } + /* Opening the file */ QFile fin(file); fin.open(QFile::ReadOnly); @@ -134,16 +149,18 @@ RBFont::RBFont(QString file) fin.close(); + /* Caching the font data */ + cache = new RBFontCache::CacheInfo; + cache->imageData = imageData; + cache->offsetData = offsetData; + cache->widthData = widthData; + cache->header = header; + RBFontCache::insert(file, cache); + } RBFont::~RBFont() { - if(imageData) - delete[] imageData; - if(offsetData) - delete[] offsetData; - if(widthData) - delete[] widthData; } RBText* RBFont::renderText(QString text, QColor color, int viewWidth, diff --git a/utils/themeeditor/graphics/rbfontcache.cpp b/utils/themeeditor/graphics/rbfontcache.cpp new file mode 100644 index 0000000000..3b6d56fd58 --- /dev/null +++ b/utils/themeeditor/graphics/rbfontcache.cpp @@ -0,0 +1,24 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2010 Robert Bieber + * + * 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 software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ + +#include "rbfontcache.h" + +QHash RBFontCache::cache; diff --git a/utils/themeeditor/graphics/rbfontcache.h b/utils/themeeditor/graphics/rbfontcache.h new file mode 100644 index 0000000000..50a6d2ec48 --- /dev/null +++ b/utils/themeeditor/graphics/rbfontcache.h @@ -0,0 +1,48 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2010 Robert Bieber + * + * 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 software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ + +#ifndef RBFONTCACHE_H +#define RBFONTCACHE_H + +#include + +class RBFontCache +{ + +public: + struct CacheInfo + { + quint8* imageData; + quint16* offsetData; + quint8* widthData; + + QHash header; + }; + + static CacheInfo* lookup(QString key){ return cache.value(key, 0); } + static void insert(QString key, CacheInfo* data){ cache.insert(key, data); } + +private: + static QHash cache; + +}; + +#endif // RBFONTCACHE_H diff --git a/utils/themeeditor/graphics/rbviewport.h b/utils/themeeditor/graphics/rbviewport.h index 81841d5cfa..c557632a40 100644 --- a/utils/themeeditor/graphics/rbviewport.h +++ b/utils/themeeditor/graphics/rbviewport.h @@ -60,6 +60,12 @@ public: void alignText(Alignment align){ textAlign = align; } int getTextOffset(){ return textOffset.y(); } void addTextOffset(int height){ textOffset.setY(textOffset.y() + height); } + void flushText() + { + alignLeft(); + alignRight(); + alignCenter(); + } void enableStatusBar(){ showStatusBar = true; } -- cgit v1.2.3