Skip to content

Commit

Permalink
Refactor|Fonts|Client: Added convenience headers for font components
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Nov 10, 2013
1 parent 5a94574 commit 2141c06
Show file tree
Hide file tree
Showing 13 changed files with 125 additions and 77 deletions.
6 changes: 5 additions & 1 deletion doomsday/client/client.pro
Expand Up @@ -109,15 +109,18 @@ DENG_API_HEADERS = \

# Convenience headers.
DENG_CONVENIENCE_HEADERS += \
include/AbstractFont \
include/AtlasProceduralImage \
include/BiasDigest \
include/BiasIllum \
include/BiasSource \
include/BiasSurface \
include/BiasTracker \
include/BitmapFont \
include/BspLeaf \
include/BspNode \
include/CommandAction \
include/CompositeBitmapFont \
include/ChildWidgetOrganizer \
include/Contact \
include/ContactSpreader \
Expand Down Expand Up @@ -325,12 +328,13 @@ DENG_HEADERS += \
include/render/vlight.h \
include/render/walledge.h \
include/render/wallspec.h \
include/resource/abstractfont.h \
include/resource/animgroups.h \
include/resource/bitmapfont.h \
include/resource/colorpalette.h \
include/resource/colorpalettes.h \
include/resource/compositebitmapfont.h \
include/resource/compositetexture.h \
include/resource/font.h \
include/resource/fonts.h \
include/resource/hq2x.h \
include/resource/image.h \
Expand Down
1 change: 1 addition & 0 deletions doomsday/client/include/AbstractFont
@@ -0,0 +1 @@
#include "resource/abstractfont.h"
1 change: 1 addition & 0 deletions doomsday/client/include/BitmapFont
@@ -0,0 +1 @@
#include "resource/bitmapfont.h"
1 change: 1 addition & 0 deletions doomsday/client/include/CompositeBitmapFont
@@ -0,0 +1 @@
#include "resource/compositebitmapfont.h"
2 changes: 1 addition & 1 deletion doomsday/client/include/de_resource.h
Expand Up @@ -25,7 +25,7 @@

#include "resource/animgroups.h"
#include "resource/colorpalettes.h"
#include "resource/font.h"
#include "resource/abstractfont.h"
#include "resource/fonts.h"
#include "resource/r_data.h"
#include "Materials"
Expand Down
@@ -1,4 +1,4 @@
/** @file font.h
/** @file abstractfont.h Abstract font.
*
* @authors Copyright © 2003-2013 Jaakko Keränen <jaakko.keranen@iki.fi>
* @authors Copyright © 2006-2013 Daniel Swanson <danij@dengine.net>
Expand All @@ -17,8 +17,8 @@
* http://www.gnu.org/licenses</small>
*/

#ifndef CLIENT_RESOURCE_FONT_H
#define CLIENT_RESOURCE_FONT_H
#ifndef CLIENT_RESOURCE_ABSTRACTFONT_H
#define CLIENT_RESOURCE_ABSTRACTFONT_H

#include "dd_types.h"
#include "def_main.h"
Expand All @@ -42,12 +42,13 @@ typedef enum {
#define FF_SHADOWED 0x2 /// Font has an embedded shadow.
/*@}*/

/**
* Abstract Font base. To be used as the basis for all types of font.
* @ingroup refresh
*/
#define MAX_CHARS 256 // Normal 256 ANSI characters.

/**
* Abstract font resource.
*
* @ingroup resource
*/
class font_t
{
public:
Expand All @@ -69,8 +70,8 @@ class font_t

Size2Raw _noCharSize;

/// dj: Do fonts have margins? Is this a pixel border in the composited
/// character map texture (perhaps per-glyph)?
/// Do fonts have margins? Is this a pixel border in the composited character
/// map texture (perhaps per-glyph)?
int _marginWidth, _marginHeight;

font_t(fonttype_t type = FT_FIRST, fontid_t bindId = 0);
Expand Down Expand Up @@ -101,4 +102,4 @@ class font_t
void charSize(Size2Raw *size, unsigned char ch);
};

#endif // CLIENT_RESOURCE_FONT_H
#endif // CLIENT_RESOURCE_ABSTRACTFONT_H
69 changes: 10 additions & 59 deletions doomsday/client/include/resource/bitmapfont.h
@@ -1,4 +1,4 @@
/** @file bitmapfont.h
/** @file bitmapfont.h Bitmap font.
*
* @authors Copyright © 2003-2013 Jaakko Keränen <jaakko.keranen@iki.fi>
* @authors Copyright © 2006-2013 Daniel Swanson <danij@dengine.net>
Expand All @@ -17,16 +17,21 @@
* http://www.gnu.org/licenses</small>
*/

#ifndef LIBDENG_BITMAPFONT_H
#define LIBDENG_BITMAPFONT_H
#ifndef CLIENT_RESOURCE_BITMAPFONT_H
#define CLIENT_RESOURCE_BITMAPFONT_H

#include "font.h"
#include "abstractfont.h"
#include "Texture"
#include <de/point.h>
#include <de/rect.h>
#include <de/size.h>
#include <de/str.h>

/**
* Bitmap font.
*
* @ingroup resource
*/
class bitmapfont_t : public font_t
{
public:
Expand Down Expand Up @@ -74,58 +79,4 @@ class bitmapfont_t : public font_t
int charHeight(unsigned char ch);
};

class bitmapcompositefont_t : public font_t
{
public:
// Data for a character.
struct bitmapcompositefont_char_t
{
RectRaw geometry;
patchid_t patch;
de::Texture::Variant *tex;
uint8_t border;
};

/// Definition used to construct this else @c NULL if not applicable.
struct ded_compositefont_s *_def;

/// Character map.
bitmapcompositefont_char_t _chars[MAX_CHARS];

public:
bitmapcompositefont_t(fontid_t bindId);
~bitmapcompositefont_t();

static bitmapcompositefont_t *fromDef(fontid_t bindId, ded_compositefont_t *def);

struct ded_compositefont_s *definition() const;
void setDefinition(struct ded_compositefont_s *def);

/**
* Update the font according to the supplied definition. To be called after
* an engine update/reset.
*
* @param def Definition to update using.
*
* @todo Should observe engine reset.
*/
void rebuildFromDef(ded_compositefont_t *def);

patchid_t charPatch(unsigned char ch);
void charSetPatch(unsigned char ch, char const *encodedPatchName);

de::Texture::Variant *charTexture(unsigned char ch);

uint8_t charBorder(unsigned char chr);

void charCoords(unsigned char chr, Point2Raw coords[4]);

void glInit();
void glDeinit();

RectRaw const *charGeometry(unsigned char ch);
int charWidth(unsigned char ch);
int charHeight(unsigned char ch);
};

#endif /* LIBDENG_BITMAPFONT_H */
#endif // CLIENT_RESOURCE_BITMAPFONT_H
89 changes: 89 additions & 0 deletions doomsday/client/include/resource/compositebitmapfont.h
@@ -0,0 +1,89 @@
/** @file compositebitmapfont.h Composite bitmap font.
*
* @authors Copyright © 2003-2013 Jaakko Keränen <jaakko.keranen@iki.fi>
* @authors Copyright © 2006-2013 Daniel Swanson <danij@dengine.net>
*
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
*
* <small>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, see:
* http://www.gnu.org/licenses</small>
*/

#ifndef CLIENT_RESOURCE_COMPOSITEBITMAPFONT_H
#define CLIENT_RESOURCE_COMPOSITEBITMAPFONT_H

#include "abstractfont.h"
#include "Texture"
#include <de/point.h>
#include <de/rect.h>
#include <de/size.h>
#include <de/str.h>

/**
* Composite bitmap font.
*
* @ingroup resource
*/
class bitmapcompositefont_t : public font_t
{
public:
// Data for a character.
struct bitmapcompositefont_char_t
{
RectRaw geometry;
patchid_t patch;
de::Texture::Variant *tex;
uint8_t border;
};

/// Definition used to construct this else @c NULL if not applicable.
struct ded_compositefont_s *_def;

/// Character map.
bitmapcompositefont_char_t _chars[MAX_CHARS];

public:
bitmapcompositefont_t(fontid_t bindId);
~bitmapcompositefont_t();

static bitmapcompositefont_t *fromDef(fontid_t bindId, ded_compositefont_t *def);

struct ded_compositefont_s *definition() const;
void setDefinition(struct ded_compositefont_s *def);

/**
* Update the font according to the supplied definition. To be called after
* an engine update/reset.
*
* @param def Definition to update using.
*
* @todo Should observe engine reset.
*/
void rebuildFromDef(ded_compositefont_t *def);

patchid_t charPatch(unsigned char ch);
void charSetPatch(unsigned char ch, char const *encodedPatchName);

de::Texture::Variant *charTexture(unsigned char ch);

uint8_t charBorder(unsigned char chr);

void charCoords(unsigned char chr, Point2Raw coords[4]);

void glInit();
void glDeinit();

RectRaw const *charGeometry(unsigned char ch);
int charWidth(unsigned char ch);
int charHeight(unsigned char ch);
};

#endif // CLIENT_RESOURCE_COMPOSITEBITMAPFONT_H
4 changes: 3 additions & 1 deletion doomsday/client/include/resource/fonts.h
Expand Up @@ -23,7 +23,9 @@

#include "dd_share.h" // fontschemeid_t
#include "def_data.h"
#include "resource/font.h"
#include "AbstractFont"
#include "BitmapFont"
#include "CompositeBitmapFont"
#include "uri.hh"

/// Special value used to signify an invalid font id.
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/render/rend_font.cpp
Expand Up @@ -35,7 +35,7 @@
#include "de_system.h"
#include "de_ui.h"

#include "resource/font.h"
#include "resource/abstractfont.h"
#include "resource/fonts.h"
#include "resource/bitmapfont.h"
#include "m_misc.h"
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/resource/abstractfont.cpp
Expand Up @@ -18,7 +18,7 @@
* 02110-1301 USA</small>
*/

#include "resource/font.h"
#include "resource/abstractfont.h"

using namespace de;

Expand Down
2 changes: 0 additions & 2 deletions doomsday/client/src/resource/fonts.cpp
Expand Up @@ -24,8 +24,6 @@
#include "de_console.h"
#include "de_filesys.h"
#include "dd_main.h" // App_ResourceSystem(), verbose
#include "resource/font.h"
#include "resource/bitmapfont.h"
#ifdef __CLIENT__
# include "gl/gl_main.h"
# include "gl/gl_texmanager.h"
Expand Down
2 changes: 1 addition & 1 deletion doomsday/server/server.pro
Expand Up @@ -199,7 +199,7 @@ DENG_HEADERS += \
$$SRC/include/resource/colorpalette.h \
$$SRC/include/resource/colorpalettes.h \
$$SRC/include/resource/compositetexture.h \
$$SRC/include/resource/font.h \
$$SRC/include/resource/abstractfont.h \
$$SRC/include/resource/image.h \
$$SRC/include/resource/lumpcache.h \
$$SRC/include/resource/material.h \
Expand Down

0 comments on commit 2141c06

Please sign in to comment.