00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #include "Image/SimpleFont.H"
00038
00039 #include "Util/Assert.H"
00040 #include "Util/log.H"
00041
00042 #include <sstream>
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062 #include "Image/font6x10.h"
00063 #include "Image/font7x13.h"
00064 #include "Image/font8x13bold.h"
00065 #include "Image/font9x15bold.h"
00066 #include "Image/font10x20.h"
00067 #include "Image/font11x22.h"
00068 #include "Image/font12x22.h"
00069 #include "Image/font14x26.h"
00070 #include "Image/font15x28.h"
00071 #include "Image/font16x29.h"
00072 #include "Image/font20x38.h"
00073
00074 static const SimpleFont g_std_fonts[11] =
00075 {
00076 SimpleFont(6U, 10U, &font6x10[0][0]),
00077 SimpleFont(7U, 13U, &font7x13[0][0]),
00078 SimpleFont(8U, 13U, &font8x13bold[0][0]),
00079 SimpleFont(9U, 15U, &font9x15bold[0][0]),
00080 SimpleFont(10U, 20U, &font10x20[0][0]),
00081 SimpleFont(11U, 22U, &font11x22[0][0]),
00082 SimpleFont(12U, 22U, &font12x22[0][0]),
00083 SimpleFont(14U, 26U, &font14x26[0][0]),
00084 SimpleFont(15U, 28U, &font15x28[0][0]),
00085 SimpleFont(16U, 29U, &font16x29[0][0]),
00086 SimpleFont(20U, 38U, &font20x38[0][0])
00087 };
00088
00089
00090 SimpleFont::SimpleFont(const uint cw, const uint ch,
00091 const unsigned char *cdata) :
00092 ww(cw), hh(ch), data(cdata)
00093 { }
00094
00095
00096 SimpleFont::~SimpleFont()
00097 { }
00098
00099
00100 const unsigned char * SimpleFont::charptr(const int c) const
00101 {
00102 if (c < 32 || c > 126) return data;
00103 return data + (c - 32) * ww * hh;
00104 }
00105
00106
00107 SimpleFont SimpleFont::FIXED(const uint width)
00108 {
00109 std::ostringstream oss;
00110
00111 for (size_t i = 0; i < numStdFonts(); ++i)
00112 {
00113 if (g_std_fonts[i].ww == width)
00114 return g_std_fonts[i];
00115
00116 if (i > 0)
00117 oss << ", ";
00118 oss << g_std_fonts[i].ww;
00119 }
00120
00121 LFATAL("Invalid width %u - valid are: %s", width, oss.str().c_str());
00122 return SimpleFont(0U, 0U, NULL);
00123 }
00124
00125
00126 SimpleFont SimpleFont::fixedMaxWidth(const uint maxwidth)
00127 {
00128 ASSERT(numStdFonts() > 0);
00129
00130 size_t best_match = 0;
00131
00132 for (size_t i = 0; i < numStdFonts(); ++i)
00133 {
00134 if (g_std_fonts[i].ww <= maxwidth ||
00135 g_std_fonts[i].ww < g_std_fonts[best_match].ww)
00136 best_match = i;
00137 }
00138
00139 return g_std_fonts[best_match];
00140 }
00141
00142
00143 SimpleFont SimpleFont::fixedMaxHeight(const uint maxheight)
00144 {
00145 ASSERT(numStdFonts() > 0);
00146
00147 size_t best_match = 0;
00148
00149 for (size_t i = 0; i < numStdFonts(); ++i)
00150 {
00151 if (g_std_fonts[i].hh <= maxheight ||
00152 g_std_fonts[i].hh < g_std_fonts[best_match].hh)
00153 best_match = i;
00154 }
00155
00156 return g_std_fonts[best_match];
00157 }
00158
00159
00160 SimpleFont SimpleFont::stdFont(const size_t n)
00161 {
00162 if (n >= numStdFonts())
00163 LFATAL("expected n < %"ZU", but got n = %"ZU, numStdFonts(), n);
00164
00165 return g_std_fonts[n];
00166 }
00167
00168
00169 size_t SimpleFont::numStdFonts()
00170 {
00171 return sizeof(g_std_fonts) / sizeof(g_std_fonts[0]);
00172 }