⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 font.h

📁 Linux下比较早的基于命令行的DVD播放器
💻 H
字号:
//// Copyright (c) 2005 by Istv醤 V醨adi//// This file is part of dxr3Player, a DVD player written specifically // for the DXR3 (aka Hollywood+) decoder card, but now handles other// hardware as well. These files contain a (mostly) user-space driver // for the Unichrome board found on Via's EPIA motherboards.//// The information for implementing this driver has been gathered// from the following sources://// - The DirectFB Unichrome driver//   Copyright (c) 2003 Andreas Robinson, All rights reserved.//// - Andreas Robinson's MPEG-2 decoder for the Unichrome board.//   Copyright (c) 2003 Andreas Robinson, All rights reserved.//// - Via's Unichrome Framebuffer driver//   Copyright 1998-2003 VIA Technologies, Inc. All Rights Reserved.//   Copyright 2001-2003 S3 Graphics, Inc. All Rights Reserved.// 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-1307  USA#ifndef UNICHROME_FONT_H#define UNICHROME_FONT_H//------------------------------------------------------------------------------#include <cstdlib>#include <cstdio>//------------------------------------------------------------------------------class FileReader;class FileWriter;//------------------------------------------------------------------------------namespace unichrome {//------------------------------------------------------------------------------class MemoryBlock;class Unichrome;class Window;//------------------------------------------------------------------------------/** * A font displayable on the Unichrome. */class Font{private:    /**     * A font chunk. This is a contiguous area containing the bitmaps     * for some fonts. It may be in host memory or in the board's memory.     */    struct Chunk    {        /**         * The next chunk.         */        Chunk* next;        /**         * The number of characters in this chunk.         */        size_t numChars;        /**         * The width of this chunk.         */        size_t width;        /**         * The height of this chunk.         */        size_t height;        /**         * The location of this chunk.         */        enum {            HOST_MEMORY,            BOARD_MEMORY        } location;        union {            /**             * The host-memory buffer for this chunk. This is valid,             * if location is HOST_MEMORY.             */            unsigned char* buffer;            /**             * The Unichrome memory block. This is valid, if location             * is BOARD_MEMORY.             */            MemoryBlock* memoryBlock;        };        /**         * Construct the chunk in the host memory.         */        Chunk(Chunk* next, size_t numChars, size_t width, size_t height);                /**         * Construct the chunk in the board's memory by reading data         * from the given file.         */        Chunk(Chunk* next, size_t numChars,               Unichrome& unichrome, FileReader& reader, unsigned version);        /**         * Destroy the chunk. It destroys the next one as well.         */        ~Chunk();        /**         * Get the memory buffer of the chunk.         */        volatile unsigned char* getBuffer();        /**         * Set this chunk as the source for some graphics operation.          *         * The chunk must be in the board's memory!         */        void setSource();        /**         * Write the chunk into the given file.         */        void write(FileWriter& writer);    };    /**     * A glyph in the font.     */    struct Glyph    {        /**         * The next glyph.         */        Glyph* next;                /**         * The character code represented by this glyph.         */        char code;        /**         * The chunk this glyph belongs to.         */        Chunk* chunk;        /**         * The offset of this glyph within the associated chunk.         */        size_t offset;        /**         * The width of this glyph.         */        size_t width;        /**         * The height of this glyph.         */        size_t height;        /**         * The left bearing of this glyph.         */        ssize_t left;        /**         * The top bearing of this glyph.         */        ssize_t top;        /**         * The advance of this glyph.         */        ssize_t advance;        /**         * Construct a glyph with the given parameters.         */        Glyph(Glyph* next, char code,              Chunk* chunk, size_t offset,              size_t width, size_t height,               ssize_t left, ssize_t top,              ssize_t advance);        /**         * Construct a glyph by reading its parameters from the given         * file.         */        Glyph(Glyph* next, Chunk* chunk,               FileReader& reader, unsigned version);        /**         * Destroy the glyph. It destroys the next one.         */        ~Glyph();        /**         * Set the given pixel of the glyph.         */        void setPixel(size_t x, size_t y, bool bit);        /**         * Blit the glyph to the given Window.         *         * @return the x-coordinate of the next character         */        size_t blit(Window& window, size_t x, size_t y, bool transparent);                /**         * Write the glyph into the given file.         */        void write(FileWriter& writer);    };    /**     * The magic number for font files.     */    static const char magic[4];    /**     * The current font version.     */    static const unsigned currentVersion = 1;    /**     * Get the index for the given character code.     */    static size_t char2Index(char code);        /**     * The first chunk in the list of chunks.     */    Chunk* firstChunk;    /**     * The first glyph in the list of glyphs.     */    Glyph* firstGlyph;    /**     * Mapping from character codes to glyphs.     */    Glyph* glyphTable[256];    /**     * The maximal top value for the font.     */    ssize_t maxTop;    /**     * The maximal bottom value for the font.     */    ssize_t maxBottom;public:    /**     * Construct a font.     */    Font();    /**     * Construct a font by reading it from the given file.     */    Font(Unichrome& unichrome, FILE* file);    /**     * Construct a font by reading it from the given file in     * the given directory. If the file cannot be opened, it will abort!     */    Font(Unichrome& unichrome, const char* name, const char* directory = 0);    /**     * Destroy the font.     */    ~Font();    /**     * Start a new host-memory chunk.     */    void startChunk(size_t numChars, size_t width, size_t height);    /**     * Start a new glyph with the given parameters in the chunk     * started last     */    void startGlyph(char code, size_t offset,                     size_t width, size_t height,                    ssize_t top, ssize_t left,                    ssize_t advance);    /**     * Set the pixel in the glyph last started.     */    void setGlyphPixel(size_t x, size_t y, bool bit);    /**     * Display the given character at the given position.     *     * @return the x-coordinate of the next character     */    size_t displayCharacter(Window& window,                            size_t x, size_t y, char code,                            bool transparent = true);    /**     * Display the given text starting at the given position.     */    size_t displayText(Window& window,                       size_t x, size_t y, const char* text,                       bool transparent = true);    /**     * Display the given text centered in both directions at the given position.     */    void displayTextAround(Window& window,                           size_t x, size_t y, const char* text,                           bool transparent = true);    /**     * Get the dimensions of the given text.     */    void getDimensions(const char* text, size_t& width, size_t& height,                       ssize_t& left, ssize_t& top);    /**     * Get the maximal height of the font.     */    size_t getHeight(ssize_t& maxTop, ssize_t& maxBottom, const char* charset = 0);    /**     * Write the font to the given file.     */    void write(FILE* f);private:    /**     * Search for the glyph with the given code.     */    Glyph* findGlyph(char code);    /**     * Initialize the font by reading it from the given file.     */    void init(Unichrome& unichrome, FILE* file);};//------------------------------------------------------------------------------} /* namespace unichrome *///------------------------------------------------------------------------------#endif // UNICHROME_FONT_H// Local variables:// mode: c++// End:

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -