From: Cyril Deguet Date: Mon, 22 Mar 2004 20:38:15 +0000 (+0000) Subject: * all : skeleton of a future bitmap font support X-Git-Tag: 0.7.2~605 X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=a8283ef69a99c7786f303a8df5ce580ce395713b;p=vlc * all : skeleton of a future bitmap font support * skin.dtd : new BitmapFont element --- diff --git a/modules/gui/skins2/Modules.am b/modules/gui/skins2/Modules.am index e35c6af2da..deddb4a9eb 100644 --- a/modules/gui/skins2/Modules.am +++ b/modules/gui/skins2/Modules.am @@ -79,12 +79,15 @@ SOURCES_skins2 = \ \ src/anchor.cpp \ src/anchor.hpp \ + src/bitmap_font.cpp \ + src/bitmap_font.hpp \ src/dialogs.cpp \ src/dialogs.hpp \ src/ft2_bitmap.cpp \ src/ft2_bitmap.hpp \ src/ft2_font.cpp \ src/ft2_font.hpp \ + src/generic_bitmap.cpp \ src/generic_bitmap.hpp \ src/generic_font.hpp \ src/generic_layout.cpp \ diff --git a/modules/gui/skins2/src/bitmap_font.cpp b/modules/gui/skins2/src/bitmap_font.cpp new file mode 100644 index 0000000000..566c7c4598 --- /dev/null +++ b/modules/gui/skins2/src/bitmap_font.cpp @@ -0,0 +1,39 @@ +/***************************************************************************** + * bitmap_font.cpp + ***************************************************************************** + * Copyright (C) 2004 VideoLAN + * $Id$ + * + * Authors: Cyril Deguet + * + * 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, USA. + *****************************************************************************/ + +#include "bitmap_font.hpp" +#include "generic_bitmap.hpp" + + +BitmapFont::BitmapFont( intf_thread_t *pIntf, const GenericBitmap &rBitmap ): + GenericFont( pIntf ), m_rBitmap( rBitmap ) +{ +} + + +GenericBitmap *BitmapFont::drawString( const UString &rString, + uint32_t color, int maxWidth ) const +{ + return NULL; +} + diff --git a/modules/gui/skins2/src/bitmap_font.hpp b/modules/gui/skins2/src/bitmap_font.hpp new file mode 100644 index 0000000000..436abd0875 --- /dev/null +++ b/modules/gui/skins2/src/bitmap_font.hpp @@ -0,0 +1,54 @@ +/***************************************************************************** + * bitmap_font.hpp + ***************************************************************************** + * Copyright (C) 2004 VideoLAN + * $Id$ + * + * Authors: Cyril Deguet + * + * 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, USA. + *****************************************************************************/ + +#ifndef BITMAP_FONT_HPP +#define BITMAP_FONT_HPP + +#include "generic_font.hpp" + +class GenericBitmap; + + +/// Class to handle bitmap fonts +class BitmapFont: public GenericFont +{ + public: + BitmapFont( intf_thread_t *pIntf, const GenericBitmap &rBitmap ); + virtual ~BitmapFont() {} + + virtual bool init() { return true; } + + /// Render a string on a bitmap. + /// If maxWidth != -1, the text is truncated with '...' + virtual GenericBitmap *drawString( const UString &rString, + uint32_t color, int maxWidth = -1 ) const; + + /// Get the font size + virtual int getSize() const { return 12; } + + private: + /// Bitmap + const GenericBitmap &m_rBitmap; +}; + +#endif diff --git a/modules/gui/skins2/src/ft2_font.hpp b/modules/gui/skins2/src/ft2_font.hpp index b1b32a3ef8..278ae85638 100644 --- a/modules/gui/skins2/src/ft2_font.hpp +++ b/modules/gui/skins2/src/ft2_font.hpp @@ -2,7 +2,7 @@ * ft2_font.hpp ***************************************************************************** * Copyright (C) 2003 VideoLAN - * $Id: ft2_font.hpp,v 1.1 2004/01/03 23:31:33 asmax Exp $ + * $Id$ * * Authors: Cyril Deguet * Olivier Teulière @@ -47,9 +47,6 @@ class FT2Font: public GenericFont /// Render a string on a bitmap. /// If maxWidth != -1, the text is truncated with '...' - /// rAscent is filled with the maximum ascent of the glyphs in - /// the string (for explanations, see: - /// http://www.freetype.org/freetype2/docs/tutorial/step2.html) virtual GenericBitmap *drawString( const UString &rString, uint32_t color, int maxWidth = -1 ) const; diff --git a/modules/gui/skins2/src/generic_bitmap.cpp b/modules/gui/skins2/src/generic_bitmap.cpp new file mode 100644 index 0000000000..b9a088745f --- /dev/null +++ b/modules/gui/skins2/src/generic_bitmap.cpp @@ -0,0 +1,50 @@ +/***************************************************************************** + * generic_bitmap.cpp + ***************************************************************************** + * Copyright (C) 2004 VideoLAN + * $Id$ + * + * Authors: Cyril Deguet + * + * 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, USA. + *****************************************************************************/ + +#include "generic_bitmap.hpp" + + +SubBitmap::SubBitmap( intf_thread_t *pIntf, const GenericBitmap &rSource, + int left, int top, int width, int height ): + GenericBitmap( pIntf ), m_width( width ), m_height( height ), + m_pData( NULL ) +{ + m_pData = new uint8_t[width * height * 4]; + + uint32_t *pSrc = (uint32_t*)rSource.getData(); + uint32_t *pDest = (uint32_t*)m_pData; + int srcWidth = rSource.getWidth(); + for( int y = top; y < top + height; y++ ) + { + memcpy( pDest, pSrc, 4 * width ); + pSrc += srcWidth; + pDest += width; + } +} + + +SubBitmap::~SubBitmap() +{ + delete[] m_pData; +} + diff --git a/modules/gui/skins2/src/generic_bitmap.hpp b/modules/gui/skins2/src/generic_bitmap.hpp index b88b1ac4dc..f59a4e1518 100644 --- a/modules/gui/skins2/src/generic_bitmap.hpp +++ b/modules/gui/skins2/src/generic_bitmap.hpp @@ -2,7 +2,7 @@ * generic_bitmap.hpp ***************************************************************************** * Copyright (C) 2003 VideoLAN - * $Id: generic_bitmap.hpp,v 1.1 2004/01/03 23:31:33 asmax Exp $ + * $Id$ * * Authors: Cyril Deguet * Olivier Teulière @@ -29,7 +29,7 @@ #include "../utils/pointer.hpp" -/// base class for bitmaps +/// Base class for bitmaps class GenericBitmap: public SkinObject { public: @@ -49,6 +49,33 @@ class GenericBitmap: public SkinObject GenericBitmap( intf_thread_t *pIntf ): SkinObject( pIntf ) {} }; + +/// Bitmap created from a region of another bitmap +class SubBitmap: public GenericBitmap +{ + public: + SubBitmap( intf_thread_t *pIntf, const GenericBitmap &rSource, + int left, int top, int width, int height ); + ~SubBitmap(); + + /// Get the width of the bitmap + virtual int getWidth() const { return m_width; } + + /// Get the heighth of the bitmap + virtual int getHeight() const { return m_height; } + + /// Get a linear buffer containing the image data. + /// Each pixel is stored in 4 bytes in the order B,G,R,A + virtual uint8_t *getData() const { return m_pData; } + + private: + /// Size of the bitmap. + int m_width, m_height; + /// Buffer containing the image data. + uint8_t *m_pData; +}; + + typedef CountedPtr GenericBitmapPtr; #endif diff --git a/modules/gui/skins2/src/generic_font.hpp b/modules/gui/skins2/src/generic_font.hpp index b67faafd93..55fd286028 100644 --- a/modules/gui/skins2/src/generic_font.hpp +++ b/modules/gui/skins2/src/generic_font.hpp @@ -2,7 +2,7 @@ * generic_font.hpp ***************************************************************************** * Copyright (C) 2003 VideoLAN - * $Id: generic_font.hpp,v 1.1 2004/01/03 23:31:33 asmax Exp $ + * $Id$ * * Authors: Cyril Deguet * Olivier Teulière @@ -41,13 +41,10 @@ class GenericFont: public SkinObject /// Render a string on a bitmap. /// If maxWidth != -1, the text is truncated with '...' - /// rAscent is filled with the maximum ascent of the glyphs in - /// the string (for explanations, see: - /// http://www.freetype.org/freetype2/docs/tutorial/step2.html) + /// The Bitmap is _not_ owned by this object virtual GenericBitmap *drawString( const UString &rString, uint32_t color, int maxWidth = -1 ) const = 0; - /// Get the font size virtual int getSize() const = 0; diff --git a/share/skins2/default/skin.dtd b/share/skins2/default/skin.dtd index 17a6706019..9ff0b2a5fc 100644 --- a/share/skins2/default/skin.dtd +++ b/share/skins2/default/skin.dtd @@ -28,6 +28,12 @@ italic CDATA "false" underline CDATA "false" > + +