sprint 1-alpha
|
00001 /****************************************************************************** 00002 * sprint::font 00003 * 00004 * Copyright (C) 2005-2011 Paolo Medici <www.pmx.it> 00005 * 00006 * This library is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU Lesser General Public 00008 * License as published by the Free Software Foundation; either 00009 * version 2.1 of the License, or (at your option) any later version. 00010 * 00011 * This library is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 * Lesser General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Lesser General Public 00017 * License along with this library; if not, write to the Free Software 00018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00019 * 00020 *******************************************************************************/ 00021 00022 #ifndef _SPRINT_BITMAP_FONT_H 00023 #define _SPRINT_BITMAP_FONT_H 00024 00029 #include <sprint/image/image.h> 00030 #include <vector> 00031 00032 namespace sprint { 00033 00035 struct CharDescr 00036 { 00037 CharDescr() : srcX(0), srcY(0), srcW(0), srcH(0), xOff(0), yOff(0), xAdv(0), page(0) {} 00038 00039 short srcX; 00040 short srcY; 00041 short srcW; 00042 short srcH; 00043 short xOff; 00044 short yOff; 00045 short xAdv; 00046 short page; 00047 unsigned int chnl; 00048 }; 00049 00051 struct kerning_pair { 00052 int first, second; 00053 int xOff; 00054 }; 00055 00057 struct font { 00058 00059 private: 00060 00061 void AddChar(int id, int x, int y, int w, int h, int xoffset, int yoffset, int xadvance, int page, int chnl); 00062 00063 public: 00065 int base; 00067 unsigned int txtW, txtH; 00069 int nPages; 00070 /*** TODO **/ 00071 int packed, encoded; 00072 00074 int nChars; 00075 00077 CharDescr def; 00079 std::vector<CharDescr> chars; 00081 sprint::iimage texture; 00082 00084 std::vector<kerning_pair> kernings; 00085 00086 public: 00087 00088 font(); 00089 ~font(); 00090 00091 // Load a Bitmap Font file 00092 bool LoadDescription(const char *txt); 00093 00095 void GetTextSize(const char *txt, int *width, int*height) const; 00096 00098 const CharDescr & GetChar(int c) const; 00099 00100 00101 }; 00102 00104 enum TextAlign { 00105 TextAlign_Default = 0, 00106 00107 TextAlign_Left = 1, 00108 TextAlign_Right = 2, 00109 TextAlign_HCenter = 3, 00110 TextAlign_HMask = 3, 00111 00112 TextAlign_Top = 4, 00113 TextAlign_Bottom = 8, 00114 TextAlign_VCenter = 12, 00115 TextAlign_VMask = 12 00116 }; 00117 00119 void print(imageview & dst, int x, int y, const char *text, unsigned int color, const font & font, int text_align = TextAlign_Default); 00120 00121 00122 } 00123 00124 #endif 00125