the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 341 lines 12 kB view raw
1#include "stdafx.h" 2#include "UIFontData.h" 3 4 ///////////////////////////////////////////////////// 5 // --- -- --- THIS FILE IS IN UNICODE --- -- --- // 6 ///////////////////////////////////////////////////// 7 8SFontData SFontData::Mojangles_7 9 = { 10 11 /* Font Name */ "Mojangles7", 12 13#ifdef _XBOX 14 /* filename */ L"/font/Mojangles_7.png", 15#else 16 /* Filename */ L"/TitleUpdate/res/font/Mojangles_7.png", 17#endif 18 19 /* Glyph count */ FONTSIZE, 20 /* Codepoints */ SFontData::Codepoints, 21 22 /*img wdth,hght*/ 190, 264, 23 /*img cols,rows*/ FONTCOLS, FONTROWS, 24 25 26 /*glyph dim x,y*/ 8,13, 27 28 /*ascent/descent*/ 7.f/13.f, 8.f/13.f, 29 30 /*advance*/ 1.f/10.f, 31 32 /*whitespace*/ 5, 33 34 }; 35 36 37SFontData SFontData::Mojangles_11 38 = { 39 40 /* Font Name */ "Mojangles11", 41 42#ifdef _XBOX 43 /* filename */ L"/font/Mojangles_11.png", 44#else 45 /* Filename */ L"/TitleUpdate/res/font/Mojangles_11.png", 46#endif 47 48 /* Glyph count */ FONTSIZE, 49 /* Codepoints */ SFontData::Codepoints, 50 51 /*img wdth,hght*/ 305, 348, 52 /*img cols,rows*/ FONTCOLS, FONTROWS, 53 54 /*glyph dim x,y*/ 13,17, 55 56 /*ascent/descent*/ 11.f/17.f, 6.f/17.f, 57 58 /*advance*/ 1.f/13.f, 59 60 /*whitespace*/ 7 61 62 }; 63 64 65 // ----------------------------------------------------------------------------- 66 // 4J-JEV: Glyph -> Unicode Maps, 67 // Unicode search tool: http://www.fileformat.info/info/unicode/char/search.htm 68 //------------------------------------------------------------------------------ 69 70 71// Originally interpretted from 'Chars.txt', required many alterations to work correctly. (New Characters have been also added) 72unsigned short SFontData::Codepoints[FONTSIZE] = 73{ 74 // NOTE: When adding characters here, you may also want to add them to the ignore list 'Mojangles\Dev\Tools\Mojangles.txt' so we know not to panic when localisation uses them. 75 76/* ż Ż ź Ź ć Ć ń Ń */ 77 0x0001, 0x017C, 0x017B, 0x017A, 0x0179, 0x0107, 0x0106, 0x0144, 0x0143, 0x000A, 0x000B, 0x000C, 0x000D, 0x000E, 0x000F, 0x0010, 0x0011, 0x0012, 0x0013, 0x0014, 0x0015, 0x0016, 0x0017, 78 79/* ! " # $ % & ' ( ) * + , - */ 80 0x0018, 0x0019, 0x001A, 0x001B, 0x001C, 0x001D, 0x001E, 0x001F, 0x0020, 0x0000, 0x0021, 0x0022, 0x0023, 0x0024, 0x0025, 0x0026, 0x0027, 0x0028, 0x0029, 0x002A, 0x002B, 0x002C, 0x002D, 81 82/* . / 0 1 2 3 4 5 6 7 8 9 : ; < = > ? @ A B C D */ 83 0x002E, 0x002F, 0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037, 0x0038, 0x0039, 0x003A, 0x003B, 0x003C, 0x003D, 0x003E, 0x003F, 0x0040, 0x0041, 0x0042, 0x0043, 0x0044, 84 85/* E F G H I J K L M N O P Q R S T U V W X Y Z [ */ 86 0x0045, 0x0046, 0x0047, 0x0048, 0x0049, 0x004A, 0x004B, 0x004C, 0x004D, 0x004E, 0x004F, 0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057, 0x0058, 0x0059, 0x005A, 0x005B, 87 88/* \ ] ^ _ ` a b c d e f g h i j k l m n o p q r */ 89 0x005C, 0x005D, 0x005E, 0x005F, 0x0060, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067, 0x0068, 0x0069, 0x006A, 0x006B, 0x006C, 0x006D, 0x006E, 0x006F, 0x0070, 0x0071, 0x0072, 90 91/* s t u v w x y z { | } ~  */ 92 0x0073, 0x0074, 0x0075, 0x0076, 0x0077, 0x0078, 0x0079, 0x007A, 0x007B, 0x007C, 0x007D, 0x007E, 0x007F, 0x0080, 0x0081, 0x0082, 0x0083, 0x0084, 0x0085, 0x0086, 0x0087, 0x0088, 0x0089, 93 94/* */ 95 0x008A, 0x008B, 0x008C, 0x008D, 0x008E, 0x008F, 0x0090, 0x0091, 0x0092, 0x0093, 0x0094, 0x0095, 0x0096, 0x0097, 0x0098, 0x0099, 0x009A, 0x009B, 0x009C, 0x009D, 0x009E, 0x009F, 0x00A0, 96 97/* ¡ ¢ £ ¤ ¥ ¦ § ¨ © ª « ¬ ­ ® ¯ ° ± ² ³ ´ µ ¶ · */ 98 0x00A1, 0x00A2, 0x00A3, 0x00A4, 0x00A5, 0x00A6, 0x00A7, 0x00A8, 0x00A9, 0x00AA, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x00AF, 0x00B0, 0x00B1, 0x00B2, 0x00B3, 0x00B4, 0x00B5, 0x00B6, 0x00B7, 99 100/* ¸ ¹ º » ¼ ½ ¾ ¿ À Á Â Ã Ä Å Æ Ç È É Ê Ë Ì Í Î */ 101 0x00B8, 0x00B9, 0x00BA, 0x00BB, 0x00BC, 0x00BD, 0x00BE, 0x00BF, 0x00C0, 0x00C1, 0x00C2, 0x00C3, 0x00C4, 0x00C5, 0x00C6, 0x00C7, 0x00C8, 0x00C9, 0x00CA, 0x00CB, 0x00CC, 0x00CD, 0x00CE, 102 103/* Ï Ð Ñ Ò Ó Ô Õ Ö × Ø Ù Ú Û Ü Ý Þ ß à á â ã ä å */ 104 0x00CF, 0x00D0, 0x00D1, 0x00D2, 0x00D3, 0x00D4, 0x00D5, 0x00D6, 0x00D7, 0x00D8, 0x00D9, 0x00DA, 0x00DB, 0x00DC, 0x00DD, 0x00DE, 0x00DF, 0x00E0, 0x00E1, 0x00E2, 0x00E3, 0x00E4, 0x00E5, 105 106/* æ ç è é ê ë ì í î ï ð ñ ò ó ô õ ö ÷ ø ù ú û ü */ 107 0x00E6, 0x00E7, 0x00E8, 0x00E9, 0x00EA, 0x00EB, 0x00EC, 0x00ED, 0x00EE, 0x00EF, 0x00F0, 0x00F1, 0x00F2, 0x00F3, 0x00F4, 0x00F5, 0x00F6, 0x00F7, 0x00F8, 0x00F9, 0x00FA, 0x00FB, 0x00FC, 108 109/* ý þ ÿ Œ œ Š š Ÿ Ž ž ƒ ˣ ➄ – — ’ ‚ “ ” „ † ‡ • */ 110 0x00FD, 0x00FE, 0x00FF, 0x0152, 0x0153, 0x0160, 0x0161, 0x0178, 0x017D, 0x017E, 0x0192, 0x02E3, 0x2784, 0x2013, 0x2014, 0x2019, 0x201A, 0x201C, 0x201D, 0x201E, 0x2020, 0x2021, 0x2022, 111 112/* … ‰ ‹ › € ™ ͝ Ş İ Ğ ş ı ğ ę Ę ó Ó ą Ą ś Ś ł Ł */ 113 0x2026, 0x2030, 0x2039, 0x203A, 0x20AC, 0x2122, 0x035D, 0x015E, 0x0130, 0x011E, 0x015F, 0x0131, 0x011F, 0x0119, 0x0118, 0x00F3, 0x00D3, 0x0105, 0x0104, 0x015B, 0x015A, 0x0142, 0x0141, 114 115/* Ё А Б В Г Д Е Ж З И Й К Л М Н О П Р С Т У Ф Х */ 116 0x0401, 0x0410, 0x0411, 0x0412, 0x0413, 0x0414, 0x0415, 0x0416, 0x0417, 0x0418, 0x0419, 0x041A, 0x041B, 0x041C, 0x041D, 0x041E, 0x041F, 0x0420, 0x0421, 0x0422, 0x0423, 0x0424, 0x0425, 117 118/* Ц Ч Ш Щ Ъ Ы Ь Э Ю Я а б в г д е ж з и й к л м */ 119 0x0426, 0x0427, 0x0428, 0x0429, 0x042A, 0x042B, 0x042C, 0x042D, 0x042E, 0x042F, 0x0430, 0x0431, 0x0432, 0x0433, 0x0434, 0x0435, 0x0436, 0x0437, 0x0438, 0x0439, 0x043A, 0x043B, 0x043C, 120 121/* н о п р с т у ф х ц ч ш щ ъ ы ь э ю я ё χ ψ ω */ 122 0x043D, 0x043E, 0x043F, 0x0440, 0x0441, 0x0442, 0x0443, 0x0444, 0x0445, 0x0446, 0x0447, 0x0448, 0x0449, 0x044A, 0x044B, 0x044C, 0x044D, 0x044E, 0x044F, 0x0451, 0x03C7, 0x03C8, 0x03C9, 123 124/* Č Ď Ě Ĺ Ľ Ň Ő Ř Ť Ů Ű č ď ě ĺ ľ ň ő ř ť ů ű */ 125 0x010C, 0x010E, 0x011A, 0x0139, 0x013D, 0x0147, 0x0150, 0x0158, 0x0164, 0x016E, 0x0170, 0x010D, 0x010F, 0x011B, 0x013A, 0x013E, 0x0148, 0x0151, 0x0159, 0x0165, 0x016F, 0x0171, 0x0020, 126 127/* Α Β Γ Δ Ε Ζ Η Θ Ι Κ Λ Μ Ν Ξ Ο Π Ρ Σ Τ Υ Φ Χ Ψ */ 128 0x0391, 0x0392, 0x0393, 0x0394, 0x0395, 0x0396, 0x0397, 0x0398, 0x0399, 0x039A, 0x039B, 0x039C, 0x039D, 0x039E, 0x039F, 0x03A0, 0x03A1, 0x03A3, 0x03A4, 0x03A5, 0x03A6, 0x03A7, 0x03A8, 129 130/* Ω α β γ δ ε ζ η θ ι κ λ μ ν ξ ο π ρ ς σ τ υ φ */ 131 0x03A9, 0x03B1, 0x03B2, 0x03B3, 0x03B4, 0x03B5, 0x03B6, 0x03B7, 0x03B8, 0x03B9, 0x03BA, 0x03BB, 0x03BC, 0x03BD, 0x03BE, 0x03BF, 0x03C0, 0x03C1, 0x03C2, 0x03C3, 0x03C4, 0x03C5, 0x03C6, 132 133/* Ά Έ Ή Ί Ό Ύ Ώ ΐ ά έ ή ί ϊ ό ύ ώ ŕ ΄ ‘ */ 134 0x0386, 0x0388, 0x0389, 0x038A, 0x038C, 0x038E, 0x038F, 0x0390, 0x03AC, 0x03AD, 0x03AE, 0x03AF, 0x03CA, 0x03CC, 0x03CD, 0x03CE, 0x0155, 0x0384, 0x2018, 0x0000, 0x0000, 0x0000, 0x0000, 135}; 136 137 138 139 140 /////////////////////// 141 // --- CFontData --- // 142 /////////////////////// 143 144CFontData::CFontData() 145{ 146 m_unicodeMap = unordered_map<unsigned int, unsigned short>(); 147 148 m_sFontData = NULL; 149 m_kerningTable = NULL; 150 m_pbRawImage = NULL; 151} 152 153CFontData::CFontData(SFontData &sFontData, int *pbRawImage) 154 : m_unicodeMap( sFontData.m_uiGlyphCount + 2 ) 155{ 156 this->m_sFontData = &sFontData; 157 158 // INITIALISE ALPHA CHANNEL // 159 160 // Glyph Archive (1Byte per pixel). 161 unsigned int archiveSize = sFontData.m_uiGlyphMapX * sFontData.m_uiGlyphMapY; 162 163 this->m_pbRawImage = new unsigned char[archiveSize]; 164 165 // 4J-JEV: Take the alpha channel from each pixel. 166 for (unsigned int i = 0; i < archiveSize; i++) 167 { 168 this->m_pbRawImage[i] = (pbRawImage[i] & 0xFF000000) >> 24; 169 } 170 171 // CREATE UNICODE MAP // 172 for (unsigned int i = 0; i < sFontData.m_uiGlyphCount; i++) 173 { 174 unordered_map<unsigned int, unsigned short>::value_type pair(sFontData.Codepoints[i], i); 175 m_unicodeMap.insert( pair ); 176 } 177 178 // CREATE KERNING TABLE // 179 m_kerningTable = new unsigned short[sFontData.m_uiGlyphCount]; 180 for (unsigned short glyph = 0; glyph < sFontData.m_uiGlyphCount; glyph++) 181 { 182 int row,column; 183 getPos(glyph,row,column); 184 185 short xMax = 0, _x=0, _y=0; 186 187 // Find the position of the topLeft corner. 188 unsigned char *topLeft = m_pbRawImage, *cursor; 189 moveCursor( topLeft, column * sFontData.m_uiGlyphWidth, row * sFontData.m_uiGlyphHeight); 190 191 assert( ((column+1)*sFontData.m_uiGlyphWidth) < sFontData.m_uiGlyphMapX ); 192 assert( ((row+1)*sFontData.m_uiGlyphHeight) < sFontData.m_uiGlyphMapY ); 193 194 static int XX = 79; 195 // Find the furthest filled pixel to the right. 196 for (short y = 0; y < sFontData.m_uiGlyphHeight; y++) 197 { 198 for (short x = 0; x < sFontData.m_uiGlyphWidth; x++) 199 { 200 cursor = topLeft; 201 moveCursor(cursor, x, y); 202 203 assert( (cursor-m_pbRawImage) < archiveSize ); 204 205 if ( *cursor > 0 ) 206 { 207 if (x > xMax) xMax = x; 208 _x = x; 209 _y = y; 210 } 211 } 212 } 213 214#if _DEBUG_BLOCK_CHARS 215 for (short y = 0; y < sFontData.m_uiGlyphHeight; y++) 216 { 217 for (short x = 0; x < sFontData.m_uiGlyphWidth; x++) 218 { 219 cursor = topLeft; 220 moveCursor(cursor, x, y); 221 222 if (x==0) *cursor = 0x00; 223 else if (x<=xMax) *cursor = 0xFF; 224 else *cursor = 0x00; 225 } 226 } 227#endif 228 229 // 4J-JEV: Empty glyphs are considered to be whitespace. 230 if (xMax == 0) m_kerningTable[glyph] = sFontData.m_uiWhitespaceWidth; 231 else m_kerningTable[glyph] = xMax + 1; 232 } 233 234 // CACHE GLYPH ADVANCES // 235 m_pfAdvanceTable = new float[sFontData.m_uiGlyphCount]; 236 for (unsigned short glyph = 0; glyph < sFontData.m_uiGlyphCount; glyph++) 237 { 238 m_pfAdvanceTable[glyph] = m_kerningTable[glyph] * m_sFontData->m_fAdvPerPixel; 239 } 240 241 // DEBUG // 242#ifndef _CONTENT_PACKAGE 243 for (int i = 0; i < sFontData.m_uiGlyphCount; i++) 244 { 245 int unicode = getUnicode(i), unicodeChar = 32, row, col; 246 if ( 32 < unicode && unicode < 127 && unicode != 0x0025 ) 247 { 248 unicodeChar = unicode; 249 } 250 251 getPos(i, row, col); 252 253 string state = "ok"; 254 if (i != getGlyphId(unicode)) 255 { 256 state = "MISSMATCHED!"; 257 258 app.DebugPrintf( "<GLYPH_%03i> %i\t%c\tU+%.4X, kerning=%i, (%2i,%2i). %s\n", 259 i, getGlyphId(unicode), unicodeChar, unicode, m_kerningTable[i], row, col, state.c_str() ); 260 } 261 } 262#endif 263} 264 265void CFontData::release() 266{ 267 delete [] m_kerningTable; 268 delete [] m_pfAdvanceTable; 269 delete [] m_pbRawImage; 270} 271 272const string CFontData::getFontName() 273{ 274 return m_sFontData->m_strFontName; 275} 276 277SFontData *CFontData::getFontData() 278{ 279 return m_sFontData; 280} 281 282unsigned short CFontData::getGlyphId(unsigned int unicodepoint) 283{ 284 unordered_map<unsigned int, unsigned short>::iterator out = m_unicodeMap.find(unicodepoint); 285 if (out != m_unicodeMap.end()) 286 return out->second; 287 return 0; 288} 289 290unsigned int CFontData::getUnicode(unsigned short glyphId) 291{ 292 return m_sFontData->Codepoints[glyphId]; 293} 294 295unsigned char *CFontData::topLeftPixel(int row, int col) 296{ 297 unsigned char *out = m_pbRawImage; 298 moveCursor(out, col * m_sFontData->m_uiGlyphWidth, row* m_sFontData->m_uiGlyphHeight); 299 return out; 300} 301 302void CFontData::getPos(unsigned short glyphId, int &rowOut, int &colOut) 303{ 304 rowOut = glyphId / m_sFontData->m_uiGlyphMapCols; 305 colOut = glyphId % m_sFontData->m_uiGlyphMapCols; 306} 307 308float CFontData::getAdvance(unsigned short glyphId) 309{ 310 return m_pfAdvanceTable[glyphId]; 311} 312 313int CFontData::getWidth(unsigned short glyphId) 314{ 315 return m_kerningTable[glyphId]; 316} 317 318bool CFontData::glyphIsWhitespace(unsigned short glyphId) 319{ 320 return unicodeIsWhitespace( getUnicode(glyphId) ); 321} 322 323bool CFontData::unicodeIsWhitespace(unsigned int unicode) 324{ 325 static const unsigned int MAX_WHITESPACE = 1; 326 static const unsigned int whitespace[MAX_WHITESPACE] = { 327 0x0020 328 }; 329 330 for (int i=0; i<MAX_WHITESPACE; i++) 331 { 332 if (unicode == whitespace[i]) return true; 333 } 334 335 return false; 336} 337 338void CFontData::moveCursor(unsigned char *&cursor, unsigned int dx, unsigned int dy) 339{ 340 cursor += (dy * m_sFontData->m_uiGlyphMapX) + dx; 341}