URBprobar.c 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888
  1. #include <common.h>
  2. #include <asm/arch/ark-common.h>
  3. #include "URBprobar.h"
  4. static void Memcpy(void * dest, const void *src, int n)
  5. {
  6. char * d = (char *)dest;
  7. const char * s = (const char *)src;
  8. while (n--)
  9. *d++ = *s++;
  10. }
  11. typedef unsigned short GlyphScatter;
  12. typedef struct {
  13. unsigned short ucs2Start;
  14. unsigned short ucs2End;
  15. }GlyphRange;
  16. //
  17. // 字体文件布局
  18. // ----------------
  19. // | 文件头 | // FontFileHead
  20. // ---------------|
  21. // | 区间信息数组 | // 连续区间数据 GlyphRange[]
  22. // ----------------
  23. // | 离散信息数组 | // 离散点数据 GlyphScatter[] 已经排序
  24. // ---------------|
  25. // | missing点阵 | // missing glyph 点阵,额外的一个点阵用于显示无法找到的字符
  26. // ----------------
  27. // | 区间1点阵 | // 连续区间点阵数据
  28. // | 区间2点阵 | // 连续区间点阵数据
  29. // | 区间... | // 连续区间点阵数据
  30. // ----------------
  31. // | 离散1点阵 | // 离散的点阵
  32. // | 离散2点阵 | // 离散的点阵
  33. // | 离散... | // 离散的点阵
  34. // ----------------
  35. static __attribute__ ((aligned (4))) const unsigned char s_fontData[]=
  36. {
  37. 0x46,0x54,0x02,0x10,0x46,0x6F,0x6E,0x74,0x20,0x38,0x78,0x31,0x36,0x00,0x00,0x00,
  38. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  39. 0x00,0x00,0x00,0x00,0x08,0x10,0x10,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x7F,0x00,
  40. 0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,
  41. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  42. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1E,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x00,
  43. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xF0,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x00,
  44. 0x00,0x10,0x10,0x10,0x10,0x10,0x10,0x1E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  45. 0x00,0x10,0x10,0x10,0x10,0x10,0x10,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  46. 0x00,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x00,
  47. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  48. 0x00,0x00,0x00,0x00,0x00,0x38,0x7C,0x7C,0x7C,0x38,0x00,0x00,0x00,0x00,0x00,0x00,
  49. 0x00,0xFE,0xFE,0xFE,0xFE,0xC6,0x82,0x82,0x82,0xC6,0xFE,0xFE,0xFE,0xFE,0xFE,0x00,
  50. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  51. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  52. 0x00,0x00,0x00,0x1E,0x06,0x0A,0x0A,0x10,0x10,0x30,0x48,0x48,0x30,0x00,0x00,0x00,
  53. 0x00,0x00,0x00,0x38,0x44,0x44,0x38,0x10,0x7C,0x10,0x10,0x10,0x10,0x00,0x00,0x00,
  54. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  55. 0x00,0x00,0x00,0x06,0x3A,0x26,0x3A,0x22,0x22,0x22,0x26,0x66,0x60,0x00,0x00,0x00,
  56. 0x00,0x00,0x00,0x54,0x54,0x28,0x28,0x6C,0x28,0x28,0x54,0x54,0x00,0x00,0x00,0x00,
  57. 0x00,0x10,0x10,0x10,0x10,0x10,0x10,0xFE,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x00,
  58. 0x00,0x00,0x02,0x06,0x0E,0x1E,0x3E,0x7E,0x3E,0x1E,0x0E,0x06,0x02,0x00,0x00,0x00,
  59. 0x00,0x10,0x38,0x54,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x54,0x38,0x10,0x00,0x00,
  60. 0x00,0x00,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x00,0x00,0x24,0x24,0x00,0x00,
  61. 0x00,0x00,0x34,0x54,0x54,0x54,0x54,0x54,0x34,0x14,0x14,0x14,0x14,0x14,0x00,0x00,
  62. 0x00,0x10,0x10,0x10,0x10,0x10,0x10,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  63. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFE,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x00,
  64. 0x00,0x10,0x10,0x10,0x10,0x10,0x10,0xF0,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x00,
  65. 0x00,0x00,0x10,0x38,0x54,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x00,0x00,
  66. 0x00,0x10,0x10,0x10,0x10,0x10,0x10,0x1E,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x00,
  67. 0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x04,0x7E,0x04,0x08,0x00,0x00,0x00,0x00,0x00,
  68. 0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x20,0x7E,0x20,0x10,0x00,0x00,0x00,0x00,0x00,
  69. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  70. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  71. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  72. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  73. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  74. 0x00,0x00,0x00,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x00,0x00,0x18,0x18,0x00,0x00,
  75. 0x00,0x12,0x36,0x24,0x48,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  76. 0x00,0x00,0x00,0x24,0x24,0x24,0xFE,0x48,0x48,0x48,0xFE,0x48,0x48,0x48,0x00,0x00,
  77. 0x00,0x00,0x10,0x38,0x54,0x54,0x50,0x30,0x18,0x14,0x14,0x54,0x54,0x38,0x10,0x10,
  78. 0x00,0x00,0x00,0x44,0xA4,0xA8,0xA8,0xA8,0x54,0x1A,0x2A,0x2A,0x2A,0x44,0x00,0x00,
  79. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  80. 0x00,0x60,0x60,0x20,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  81. 0x00,0x02,0x04,0x08,0x08,0x10,0x10,0x10,0x10,0x10,0x10,0x08,0x08,0x04,0x02,0x00,
  82. 0x00,0x40,0x20,0x10,0x10,0x08,0x08,0x08,0x08,0x08,0x08,0x10,0x10,0x20,0x40,0x00,
  83. 0x00,0x00,0x00,0x00,0x10,0x10,0xD6,0x38,0x38,0xD6,0x10,0x10,0x00,0x00,0x00,0x00,
  84. 0x00,0x00,0x00,0x00,0x10,0x10,0x10,0x10,0xFE,0x10,0x10,0x10,0x10,0x00,0x00,0x00,
  85. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x60,0x60,0x20,0xC0,
  86. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  87. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x60,0x60,0x00,0x00,
  88. 0x00,0x00,0x01,0x02,0x02,0x04,0x04,0x08,0x08,0x10,0x10,0x20,0x20,0x40,0x40,0x00,
  89. 0x00,0x00,0x00,0x18,0x24,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x24,0x18,0x00,0x00,
  90. 0x00,0x00,0x00,0x10,0x70,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x7C,0x00,0x00,
  91. 0x00,0x00,0x00,0x3C,0x42,0x42,0x42,0x04,0x04,0x08,0x10,0x20,0x42,0x7E,0x00,0x00,
  92. 0x00,0x00,0x00,0x3C,0x42,0x42,0x04,0x18,0x04,0x02,0x02,0x42,0x44,0x38,0x00,0x00,
  93. 0x00,0x00,0x00,0x04,0x0C,0x14,0x24,0x24,0x44,0x44,0x7E,0x04,0x04,0x1E,0x00,0x00,
  94. 0x00,0x00,0x00,0x7E,0x40,0x40,0x40,0x58,0x64,0x02,0x02,0x42,0x44,0x38,0x00,0x00,
  95. 0x00,0x00,0x00,0x1C,0x24,0x40,0x40,0x58,0x64,0x42,0x42,0x42,0x24,0x18,0x00,0x00,
  96. 0x00,0x00,0x00,0x7E,0x44,0x44,0x08,0x08,0x10,0x10,0x10,0x10,0x10,0x10,0x00,0x00,
  97. 0x00,0x00,0x00,0x3C,0x42,0x42,0x42,0x24,0x18,0x24,0x42,0x42,0x42,0x3C,0x00,0x00,
  98. 0x00,0x00,0x00,0x18,0x24,0x42,0x42,0x42,0x26,0x1A,0x02,0x02,0x24,0x38,0x00,0x00,
  99. 0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x00,0x00,0x00,0x00,0x18,0x18,0x00,0x00,
  100. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x10,0x10,0x20,
  101. 0x00,0x00,0x00,0x02,0x04,0x08,0x10,0x20,0x40,0x20,0x10,0x08,0x04,0x02,0x00,0x00,
  102. 0x00,0x00,0x00,0x00,0x00,0x00,0xFE,0x00,0x00,0x00,0xFE,0x00,0x00,0x00,0x00,0x00,
  103. 0x00,0x00,0x00,0x40,0x20,0x10,0x08,0x04,0x02,0x04,0x08,0x10,0x20,0x40,0x00,0x00,
  104. 0x00,0x00,0x00,0x3C,0x42,0x42,0x62,0x02,0x04,0x08,0x08,0x00,0x18,0x18,0x00,0x00,
  105. 0x00,0x00,0x00,0x38,0x44,0x5A,0xAA,0xAA,0xAA,0xAA,0xB4,0x42,0x44,0x38,0x00,0x00,
  106. 0x00,0x00,0x00,0x10,0x10,0x18,0x28,0x28,0x24,0x3C,0x44,0x42,0x42,0xE7,0x00,0x00,
  107. 0x00,0x00,0x00,0xF8,0x44,0x44,0x44,0x78,0x44,0x42,0x42,0x42,0x44,0xF8,0x00,0x00,
  108. 0x00,0x00,0x00,0x3E,0x42,0x42,0x80,0x80,0x80,0x80,0x80,0x42,0x44,0x38,0x00,0x00,
  109. 0x00,0x00,0x00,0xF8,0x44,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x44,0xF8,0x00,0x00,
  110. 0x00,0x00,0x00,0xFC,0x42,0x48,0x48,0x78,0x48,0x48,0x40,0x42,0x42,0xFC,0x00,0x00,
  111. 0x00,0x00,0x00,0xFC,0x42,0x48,0x48,0x78,0x48,0x48,0x40,0x40,0x40,0xE0,0x00,0x00,
  112. 0x00,0x00,0x00,0x3C,0x44,0x44,0x80,0x80,0x80,0x8E,0x84,0x44,0x44,0x38,0x00,0x00,
  113. 0x00,0x00,0x00,0xE7,0x42,0x42,0x42,0x42,0x7E,0x42,0x42,0x42,0x42,0xE7,0x00,0x00,
  114. 0x00,0x00,0x00,0x7C,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x7C,0x00,0x00,
  115. 0x00,0x00,0x00,0x3E,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x88,0xF0,
  116. 0x00,0x00,0x00,0xEE,0x44,0x48,0x50,0x70,0x50,0x48,0x48,0x44,0x44,0xEE,0x00,0x00,
  117. 0x00,0x00,0x00,0xE0,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x42,0xFE,0x00,0x00,
  118. 0x00,0x00,0x00,0xEE,0x6C,0x6C,0x6C,0x6C,0x54,0x54,0x54,0x54,0x54,0xD6,0x00,0x00,
  119. 0x00,0x00,0x00,0xC7,0x62,0x62,0x52,0x52,0x4A,0x4A,0x4A,0x46,0x46,0xE2,0x00,0x00,
  120. 0x00,0x00,0x00,0x38,0x44,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x44,0x38,0x00,0x00,
  121. 0x00,0x00,0x00,0xFC,0x42,0x42,0x42,0x42,0x7C,0x40,0x40,0x40,0x40,0xE0,0x00,0x00,
  122. 0x00,0x00,0x00,0x38,0x44,0x82,0x82,0x82,0x82,0x82,0xB2,0xCA,0x4C,0x38,0x06,0x00,
  123. 0x00,0x00,0x00,0xFC,0x42,0x42,0x42,0x7C,0x48,0x48,0x44,0x44,0x42,0xE3,0x00,0x00,
  124. 0x00,0x00,0x00,0x3E,0x42,0x42,0x40,0x20,0x18,0x04,0x02,0x42,0x42,0x7C,0x00,0x00,
  125. 0x00,0x00,0x00,0xFE,0x92,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x38,0x00,0x00,
  126. 0x00,0x00,0x00,0xE7,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x3C,0x00,0x00,
  127. 0x00,0x00,0x00,0xE7,0x42,0x42,0x44,0x24,0x24,0x28,0x28,0x18,0x10,0x10,0x00,0x00,
  128. 0x00,0x00,0x00,0xD6,0x92,0x92,0x92,0x92,0xAA,0xAA,0x6C,0x44,0x44,0x44,0x00,0x00,
  129. 0x00,0x00,0x00,0xE7,0x42,0x24,0x24,0x18,0x18,0x18,0x24,0x24,0x42,0xE7,0x00,0x00,
  130. 0x00,0x00,0x00,0xEE,0x44,0x44,0x28,0x28,0x10,0x10,0x10,0x10,0x10,0x38,0x00,0x00,
  131. 0x00,0x00,0x00,0x7E,0x84,0x04,0x08,0x08,0x10,0x20,0x20,0x42,0x42,0xFC,0x00,0x00,
  132. 0x00,0x1E,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x1E,0x00,
  133. 0x00,0x00,0x40,0x40,0x20,0x20,0x10,0x10,0x10,0x08,0x08,0x04,0x04,0x04,0x02,0x02,
  134. 0x00,0x78,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x78,0x00,
  135. 0x00,0x1C,0x22,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  136. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,
  137. 0x00,0x60,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  138. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x42,0x1E,0x22,0x42,0x42,0x3F,0x00,0x00,
  139. 0x00,0x00,0x00,0xC0,0x40,0x40,0x40,0x58,0x64,0x42,0x42,0x42,0x64,0x58,0x00,0x00,
  140. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1C,0x22,0x40,0x40,0x40,0x22,0x1C,0x00,0x00,
  141. 0x00,0x00,0x00,0x06,0x02,0x02,0x02,0x1E,0x22,0x42,0x42,0x42,0x26,0x1B,0x00,0x00,
  142. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x42,0x7E,0x40,0x40,0x42,0x3C,0x00,0x00,
  143. 0x00,0x00,0x00,0x0F,0x11,0x10,0x10,0x7E,0x10,0x10,0x10,0x10,0x10,0x7C,0x00,0x00,
  144. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3E,0x44,0x44,0x38,0x40,0x3C,0x42,0x42,0x3C,
  145. 0x00,0x00,0x00,0xC0,0x40,0x40,0x40,0x5C,0x62,0x42,0x42,0x42,0x42,0xE7,0x00,0x00,
  146. 0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x70,0x10,0x10,0x10,0x10,0x10,0x7C,0x00,0x00,
  147. 0x00,0x00,0x00,0x0C,0x0C,0x00,0x00,0x1C,0x04,0x04,0x04,0x04,0x04,0x04,0x44,0x78,
  148. 0x00,0x00,0x00,0xC0,0x40,0x40,0x40,0x4E,0x48,0x50,0x68,0x48,0x44,0xEE,0x00,0x00,
  149. 0x00,0x00,0x00,0x70,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x7C,0x00,0x00,
  150. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFE,0x49,0x49,0x49,0x49,0x49,0xED,0x00,0x00,
  151. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xDC,0x62,0x42,0x42,0x42,0x42,0xE7,0x00,0x00,
  152. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x42,0x42,0x42,0x42,0x42,0x3C,0x00,0x00,
  153. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xD8,0x64,0x42,0x42,0x42,0x44,0x78,0x40,0xE0,
  154. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1E,0x22,0x42,0x42,0x42,0x22,0x1E,0x02,0x07,
  155. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xEE,0x32,0x20,0x20,0x20,0x20,0xF8,0x00,0x00,
  156. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3E,0x42,0x40,0x3C,0x02,0x42,0x7C,0x00,0x00,
  157. 0x00,0x00,0x00,0x00,0x00,0x10,0x10,0x7C,0x10,0x10,0x10,0x10,0x10,0x0C,0x00,0x00,
  158. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC6,0x42,0x42,0x42,0x42,0x46,0x3B,0x00,0x00,
  159. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xE7,0x42,0x24,0x24,0x28,0x10,0x10,0x00,0x00,
  160. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xD7,0x92,0x92,0xAA,0xAA,0x44,0x44,0x00,0x00,
  161. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x6E,0x24,0x18,0x18,0x18,0x24,0x76,0x00,0x00,
  162. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xE7,0x42,0x24,0x24,0x28,0x18,0x10,0x10,0xE0,
  163. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7E,0x44,0x08,0x10,0x10,0x22,0x7E,0x00,0x00,
  164. 0x00,0x03,0x04,0x04,0x04,0x04,0x04,0x08,0x04,0x04,0x04,0x04,0x04,0x04,0x03,0x00,
  165. 0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,
  166. 0x00,0x60,0x10,0x10,0x10,0x10,0x10,0x08,0x10,0x10,0x10,0x10,0x10,0x10,0x60,0x00,
  167. 0x30,0x4C,0x43,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  168. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  169. };
  170. /**
  171. * the VGUI private Font file version 1.0 head struct, internally used only.
  172. */
  173. typedef struct {
  174. char magic[2]; // "FT"
  175. unsigned short version;// 0x1001 (1.01)
  176. char name[32];// description
  177. unsigned char charWidth;
  178. unsigned char charHeight;
  179. unsigned short glyphBytes;
  180. unsigned short rangeCount;
  181. unsigned short scatterCount;
  182. }FontFileHeadV1;
  183. static mv_surface s_primary;
  184. static unsigned char * m_fileStart =NULL;
  185. static unsigned char * m_glyphStart=NULL;
  186. static unsigned int g_bpp;
  187. FontFileHeadV1 * m_fh=NULL;
  188. static int setFontFileDat(const unsigned char * dat);
  189. unsigned int mv_RGB2Color(unsigned char r, unsigned char g, unsigned char b)
  190. {
  191. if(g_bpp == 16)
  192. return ((r >> 3) << 11) |( (g >> 2) << 5) | (b >> 3);
  193. else if(g_bpp == 32)
  194. return (r << 16) | (g << 8) | b;
  195. }
  196. static mv_color * getXYData(const mv_surface * s,
  197. int x, int y)
  198. {
  199. return(mv_color*)(s->startAddr + x * sizeof(mv_color) + s->lineBytes * y);
  200. }
  201. static unsigned short * getXYData16(const mv_surface * s,
  202. int x, int y)
  203. {
  204. return(unsigned short*)(s->startAddr + x * sizeof(unsigned short) + s->lineBytes * y);
  205. }
  206. static unsigned int * getXYData32(const mv_surface * s,
  207. int x, int y)
  208. {
  209. return(unsigned int*)(s->startAddr + x * sizeof(unsigned int) + s->lineBytes * y);
  210. }
  211. void mv_initPrimary(const mv_surface * s)
  212. {
  213. //s_primary = *s;
  214. Memcpy(&s_primary, s, sizeof(s_primary));
  215. setFontFileDat(s_fontData); //defined in "fontdata.h"
  216. g_bpp = s->bpp;
  217. }
  218. void mv_putPixel(int x, int y, mv_color color)
  219. {
  220. *getXYData(&s_primary, x, y) = color;
  221. }
  222. void mv_putPixel16(int x, int y, unsigned short color)
  223. {
  224. *getXYData16(&s_primary, x, y) = color;
  225. }
  226. void mv_putPixel32(int x, int y, unsigned int color)
  227. {
  228. *getXYData32(&s_primary, x, y) = color;
  229. }
  230. void mv_drawLine(int x1, int y1, int x2, int y2, mv_color color)
  231. {
  232. int i;
  233. mv_color* p;
  234. if ( y1 == y2 ) {
  235. if (x1 > x2) {
  236. int tmp = x1;
  237. x1 = x2;
  238. x2 = tmp;
  239. }
  240. // horz line
  241. p = getXYData(&s_primary, x1, y1);
  242. for (i = x1; i < x2; ++i)
  243. *p++ = color;
  244. }
  245. else if ( x1 == x2 ) {
  246. if (y1 > y2) {
  247. int tmp = y1;
  248. y1 = y2;
  249. y2 = tmp;
  250. }
  251. // vert line
  252. p = getXYData(&s_primary, x1,y1);
  253. for (i = y1; i < y2; ++i) {
  254. *p = color;
  255. p = p + s_primary.lineBytes;
  256. }
  257. }
  258. }
  259. void mv_drawLine16(int x1, int y1, int x2, int y2, unsigned short color)
  260. {
  261. int i;
  262. unsigned short* p;
  263. if ( y1 == y2 ) {
  264. if (x1 > x2) {
  265. int tmp = x1;
  266. x1 = x2;
  267. x2 = tmp;
  268. }
  269. // horz line
  270. p = getXYData16(&s_primary, x1, y1);
  271. for (i = x1; i < x2; ++i)
  272. *p++ = color;
  273. }
  274. else if ( x1 == x2 ) {
  275. if (y1 > y2) {
  276. int tmp = y1;
  277. y1 = y2;
  278. y2 = tmp;
  279. }
  280. // vert line
  281. p = getXYData16(&s_primary, x1,y1);
  282. for (i = y1; i < y2; ++i) {
  283. *p = color;
  284. p = p + s_primary.lineBytes;
  285. }
  286. }
  287. }
  288. void mv_drawLine32(int x1, int y1, int x2, int y2, unsigned int color)
  289. {
  290. int i;
  291. unsigned int* p;
  292. if ( y1 == y2 ) {
  293. if (x1 > x2) {
  294. int tmp = x1;
  295. x1 = x2;
  296. x2 = tmp;
  297. }
  298. // horz line
  299. p = getXYData32(&s_primary, x1, y1);
  300. for (i = x1; i < x2; ++i)
  301. *p++ = color;
  302. }
  303. else if ( x1 == x2 ) {
  304. if (y1 > y2) {
  305. int tmp = y1;
  306. y1 = y2;
  307. y2 = tmp;
  308. }
  309. // vert line
  310. p = getXYData32(&s_primary, x1,y1);
  311. for (i = y1; i < y2; ++i) {
  312. *p = color;
  313. p = p + s_primary.lineBytes;
  314. }
  315. }
  316. }
  317. void mv_drawRect(const mv_Rect* rect, mv_color color)
  318. {
  319. mv_drawLine(rect->left, rect->top, rect->right, rect->top, color);
  320. mv_drawLine(rect->left, rect->bottom, rect->right, rect->bottom, color);
  321. mv_drawLine(rect->left, rect->top, rect->left, rect->bottom, color);
  322. mv_drawLine(rect->right, rect->top, rect->right, rect->bottom, color);
  323. }
  324. void mv_drawRect16(const mv_Rect* rect, unsigned short color)
  325. {
  326. mv_drawLine16(rect->left, rect->top, rect->right, rect->top, color);
  327. mv_drawLine16(rect->left, rect->bottom, rect->right, rect->bottom, color);
  328. mv_drawLine16(rect->left, rect->top, rect->left, rect->bottom, color);
  329. mv_drawLine16(rect->right, rect->top, rect->right, rect->bottom, color);
  330. }
  331. void mv_drawRect32(const mv_Rect* rect, unsigned int color)
  332. {
  333. mv_drawLine32(rect->left, rect->top, rect->right, rect->top, color);
  334. mv_drawLine32(rect->left, rect->bottom, rect->right, rect->bottom, color);
  335. mv_drawLine32(rect->left, rect->top, rect->left, rect->bottom, color);
  336. mv_drawLine32(rect->right, rect->top, rect->right, rect->bottom, color);
  337. }
  338. void mv_fillRect(const mv_Rect* rect, unsigned int color)
  339. {
  340. if(g_bpp == 16)
  341. mv_fillRect16(rect, color);
  342. else if(g_bpp == 32)
  343. mv_fillRect32(rect, color);
  344. }
  345. void mv_fillRect16(const mv_Rect* rect, unsigned short color){
  346. int y;
  347. for (y = rect->top; y < rect->bottom ; y++)
  348. mv_drawLine16(rect->left, y, rect->right, y, color);
  349. }
  350. void mv_fillRect32(const mv_Rect* rect, unsigned int color){
  351. int y;
  352. for (y = rect->top; y < rect->bottom ; y++)
  353. mv_drawLine32(rect->left, y, rect->right, y, color);
  354. }
  355. void mv_drawBitmap(int x, int y,
  356. const mv_surface* bmp,
  357. const mv_Rect * bmpRect,
  358. const mv_color * transColor){
  359. int width, height;
  360. int line, i;
  361. const char* from;
  362. char* to;
  363. if ( bmpRect) {
  364. width = bmpRect->right - bmpRect->left;
  365. height = bmpRect->bottom - bmpRect->top;
  366. from = (const char *)getXYData(bmp, bmpRect->left, bmpRect->top);
  367. }
  368. else {
  369. width = bmp->width;
  370. height = bmp->height;
  371. from = bmp->startAddr;
  372. }
  373. to = (char *)getXYData(&s_primary, x, y);
  374. if ( !transColor) {
  375. for (line = 0; line < height; line++) {
  376. Memcpy(to, from, width * sizeof(mv_color));
  377. from += bmp->lineBytes;
  378. to += s_primary.lineBytes;
  379. }
  380. }
  381. else {
  382. const mv_color* src;
  383. mv_color * dst;
  384. for (line = 0; line < height; line++) {
  385. src = (mv_color*)from;
  386. dst = (mv_color*)to;
  387. for (i = 0; i < width; i++) {
  388. if ( *src != *transColor)
  389. *dst = *src;
  390. src++;
  391. dst++;
  392. }
  393. from += bmp->lineBytes;
  394. to += s_primary.lineBytes;
  395. }
  396. }
  397. }
  398. void mv_drawBitmap16(int x, int y,
  399. const mv_surface* bmp,
  400. const mv_Rect * bmpRect,
  401. const unsigned short * transColor)
  402. {
  403. int width, height;
  404. int line, i;
  405. const char* from;
  406. char* to;
  407. if ( bmpRect) {
  408. width = bmpRect->right - bmpRect->left;
  409. height = bmpRect->bottom - bmpRect->top;
  410. from = (const char *)getXYData16(bmp, bmpRect->left, bmpRect->top);
  411. }
  412. else {
  413. width = bmp->width;
  414. height = bmp->height;
  415. from = bmp->startAddr;
  416. }
  417. to = (char *)getXYData16(&s_primary, x, y);
  418. if ( !transColor) {
  419. for (line = 0; line < height; line++) {
  420. Memcpy(to, from, width * sizeof(unsigned short));
  421. from += bmp->lineBytes;
  422. to += s_primary.lineBytes;
  423. }
  424. }
  425. else {
  426. const unsigned short* src;
  427. unsigned short * dst;
  428. for (line = 0; line < height; line++) {
  429. src = (unsigned short*)from;
  430. dst = (unsigned short*)to;
  431. for (i = 0; i < width; i++) {
  432. if ( *src != *transColor)
  433. *dst = *src;
  434. src++;
  435. dst++;
  436. }
  437. from += bmp->lineBytes;
  438. to += s_primary.lineBytes;
  439. }
  440. }
  441. }
  442. void mv_drawBitmap32(int x, int y,
  443. const mv_surface* bmp,
  444. const mv_Rect * bmpRect,
  445. const unsigned int * transColor)
  446. {
  447. int width, height;
  448. int line, i;
  449. const char* from;
  450. char* to;
  451. if ( bmpRect) {
  452. width = bmpRect->right - bmpRect->left;
  453. height = bmpRect->bottom - bmpRect->top;
  454. from = (const char *)getXYData32(bmp, bmpRect->left, bmpRect->top);
  455. }
  456. else {
  457. width = bmp->width;
  458. height = bmp->height;
  459. from = bmp->startAddr;
  460. }
  461. to = (char *)getXYData32(&s_primary, x, y);
  462. if ( !transColor) {
  463. for (line = 0; line < height; line++) {
  464. Memcpy(to, from, width * sizeof(unsigned int));
  465. from += bmp->lineBytes;
  466. to += s_primary.lineBytes;
  467. }
  468. }
  469. else {
  470. const unsigned int* src;
  471. unsigned int * dst;
  472. for (line = 0; line < height; line++) {
  473. src = (unsigned int*)from;
  474. dst = (unsigned int*)to;
  475. for (i = 0; i < width; i++) {
  476. if ( *src != *transColor)
  477. *dst = *src;
  478. src++;
  479. dst++;
  480. }
  481. from += bmp->lineBytes;
  482. to += s_primary.lineBytes;
  483. }
  484. }
  485. }
  486. int mv_loadBmp(const void* bmpData, mv_surface* img)
  487. {
  488. unsigned char r,g,b;
  489. int i, j, bytes;
  490. int width, height, offset;
  491. short colorBits;
  492. unsigned char *colorMap;
  493. const unsigned char* fileBuffer = (const unsigned char*)bmpData;
  494. if (*fileBuffer != 'B')
  495. return -1;
  496. offset = *(int*)(fileBuffer + 10); //ƫ����, 4Byte
  497. width = *(int*)(fileBuffer + 18); //����, 4Byte
  498. height = *(int*)(fileBuffer + 22); //�߶�, 4Byte
  499. colorBits = *(short*)(fileBuffer + 28); //ɫ��, 2Byte
  500. colorMap = (unsigned char*)(fileBuffer + 54); //��ɫ����ַ(8bitʱʹ��)
  501. img->width = width;
  502. img->height = height;
  503. img->lineBytes = width * sizeof(mv_color);
  504. switch (colorBits) {
  505. case 32: // r,g,b,a
  506. for (i = height - 1; i >= 0; i--) {
  507. for (j = 0; j < width; j++) {
  508. b = *(fileBuffer + offset);
  509. g = *(fileBuffer + offset + 1);
  510. r = *(fileBuffer + offset + 2);
  511. // a = *(unsigned char*)(fileBuffer + offset + 3);
  512. *getXYData(img, j, i) = mv_RGB2Color(r,g,b);
  513. offset += 4;
  514. }
  515. }
  516. break;
  517. case 24: // r,g,b
  518. bytes = 4 - (width * 3) % 4;
  519. if (bytes == 4)
  520. bytes = 0;
  521. for (i = height - 1; i >= 0; i--) {
  522. for (j = 0; j < width; j++) {
  523. b = *(fileBuffer + offset);
  524. g = *(fileBuffer + offset + 1);
  525. r = *(fileBuffer + offset + 2);
  526. *getXYData(img, j, i) = mv_RGB2Color(r,g,b);
  527. offset += 3;
  528. }
  529. offset += bytes;
  530. }
  531. break;
  532. case 16: //16bit 555
  533. {
  534. unsigned short color16;
  535. bytes = 4 - (width * 2) % 4;
  536. if (bytes == 4)
  537. bytes = 0;
  538. for (i = height - 1; i >= 0; i--) {
  539. for (j = 0; j < width; j++) {
  540. color16 = *(unsigned short *)(fileBuffer+offset);
  541. #if ( GUI_RGB_FORMAT == RGB_FORMAT_565)
  542. *getXYData(img, j, i) = (color16<<1) & 0xFFC0 | (color16 & 0x1F);
  543. #else
  544. *getXYData(img, j, i) = mv_RGB2Color((color16 & 0x7C00) >> 7, (color16 & 0x03E0) >> 2, (color16 & 0x001F) << 3);
  545. #endif
  546. offset += 2;
  547. }
  548. offset += bytes;
  549. }
  550. }
  551. break;
  552. case 8: //256 colormap
  553. bytes = 4 - width % 4;
  554. if (bytes == 4)
  555. bytes = 0;
  556. for (i = height - 1; i >= 0; i--) {
  557. for (j = 0; j < width; j++) {
  558. int offSet = *(fileBuffer + offset) * 4;
  559. b = colorMap[offSet];
  560. g = colorMap[offSet + 1];
  561. r = colorMap[offSet + 2];
  562. *getXYData(img, j, i) = mv_RGB2Color(r,g,b);
  563. offset ++;
  564. }
  565. offset += bytes;
  566. }
  567. break;
  568. default:
  569. break;
  570. }
  571. return 0;
  572. }
  573. int mv_loadBmp16(const void* bmpData, mv_surface* img)
  574. {
  575. unsigned char r,g,b;
  576. int i, j, bytes;
  577. int width, height, offset;
  578. short colorBits;
  579. unsigned char *colorMap;
  580. const unsigned char* fileBuffer = (const unsigned char*)bmpData;
  581. if (*fileBuffer != 'B')
  582. return -1;
  583. offset = *(int*)(fileBuffer + 10); //ƫ����, 4Byte
  584. width = *(int*)(fileBuffer + 18); //����, 4Byte
  585. height = *(int*)(fileBuffer + 22); //�߶�, 4Byte
  586. colorBits = *(short*)(fileBuffer + 28); //ɫ��, 2Byte
  587. colorMap = (unsigned char*)(fileBuffer + 54); //��ɫ����ַ(8bitʱʹ��)
  588. img->width = width;
  589. img->height = height;
  590. img->lineBytes = width * sizeof(unsigned short);
  591. switch (colorBits) {
  592. case 32: // r,g,b,a
  593. for (i = height - 1; i >= 0; i--) {
  594. for (j = 0; j < width; j++) {
  595. b = *(fileBuffer + offset);
  596. g = *(fileBuffer + offset + 1);
  597. r = *(fileBuffer + offset + 2);
  598. // a = *(unsigned char*)(fileBuffer + offset + 3);
  599. *getXYData16(img, j, i) = mv_RGB2Color(r,g,b);
  600. offset += 4;
  601. }
  602. }
  603. break;
  604. case 24: // r,g,b
  605. bytes = 4 - (width * 3) % 4;
  606. if (bytes == 4)
  607. bytes = 0;
  608. for (i = height - 1; i >= 0; i--) {
  609. for (j = 0; j < width; j++) {
  610. b = *(fileBuffer + offset);
  611. g = *(fileBuffer + offset + 1);
  612. r = *(fileBuffer + offset + 2);
  613. *getXYData16(img, j, i) = mv_RGB2Color(r,g,b);
  614. offset += 3;
  615. }
  616. offset += bytes;
  617. }
  618. break;
  619. case 16: //16bit 555
  620. {
  621. unsigned short color16;
  622. bytes = 4 - (width * 2) % 4;
  623. if (bytes == 4)
  624. bytes = 0;
  625. for (i = height - 1; i >= 0; i--) {
  626. for (j = 0; j < width; j++) {
  627. color16 = *(unsigned short *)(fileBuffer+offset);
  628. #if (GUI_RGB_FORMAT == RGB_FORMAT_565)
  629. *getXYData16(img, j, i) = (color16<<1) & 0xFFC0 | (color16 & 0x1F);
  630. #else
  631. *getXYData16(img, j, i) = mv_RGB2Color((color16 & 0x7C00) >> 7, (color16 & 0x03E0) >> 2, (color16 & 0x001F) << 3);
  632. #endif
  633. offset += 2;
  634. }
  635. offset += bytes;
  636. }
  637. }
  638. break;
  639. case 8: //256 colormap
  640. bytes = 4 - width % 4;
  641. if (bytes == 4)
  642. bytes = 0;
  643. for (i = height - 1; i >= 0; i--) {
  644. for (j = 0; j < width; j++) {
  645. int offSet = *(fileBuffer + offset) * 4;
  646. b = colorMap[offSet];
  647. g = colorMap[offSet + 1];
  648. r = colorMap[offSet + 2];
  649. *getXYData16(img, j, i) = mv_RGB2Color(r,g,b);
  650. offset ++;
  651. }
  652. offset += bytes;
  653. }
  654. break;
  655. default:
  656. break;
  657. }
  658. return 0;
  659. }
  660. int mv_loadBmp32(const void* bmpData, mv_surface* img)
  661. {
  662. unsigned char r,g,b;
  663. int i, j, bytes;
  664. int width, height, offset;
  665. short colorBits;
  666. unsigned char *colorMap;
  667. const unsigned char* fileBuffer = (const unsigned char*)bmpData;
  668. if (*fileBuffer != 'B')
  669. return -1;
  670. offset = *(int*)(fileBuffer + 10);//偏移量, 4Byte
  671. width = *(int*)(fileBuffer + 18);//宽度, 4Byte
  672. height = *(int*)(fileBuffer + 22);//高度, 4Byte
  673. colorBits = *(short*)(fileBuffer + 28); //色深, 2Byte
  674. colorMap = (unsigned char*)(fileBuffer + 54); //颜色表地址(8bit时使用)
  675. img->width = width;
  676. img->height = height;
  677. img->lineBytes = width * sizeof(unsigned int);
  678. switch (colorBits) {
  679. case 32: // r,g,b,a
  680. for (i = height - 1; i >= 0; i--) {
  681. for (j = 0; j < width; j++) {
  682. b = *(fileBuffer + offset);
  683. g = *(fileBuffer + offset + 1);
  684. r = *(fileBuffer + offset + 2);
  685. // a = *(unsigned char*)(fileBuffer + offset + 3);
  686. *getXYData32(img, j, i) = mv_RGB2Color(r,g,b);
  687. offset += 4;
  688. }
  689. }
  690. break;
  691. case 24:// r,g,b
  692. bytes = 4 - (width * 3) % 4;
  693. if (bytes == 4)
  694. bytes = 0;
  695. for (i = height - 1; i >= 0; i--) {
  696. for (j = 0; j < width; j++) {
  697. b = *(fileBuffer + offset);
  698. g = *(fileBuffer + offset + 1);
  699. r = *(fileBuffer + offset + 2);
  700. *getXYData32(img, j, i) = mv_RGB2Color(r,g,b);
  701. offset += 3;
  702. }
  703. offset += bytes;
  704. }
  705. break;
  706. case 16://16bit 555
  707. {
  708. unsigned short color16;
  709. bytes = 4 - (width * 2) % 4;
  710. if (bytes == 4)
  711. bytes = 0;
  712. for (i = height - 1; i >= 0; i--) {
  713. for (j = 0; j < width; j++) {
  714. color16 = *(unsigned short *)(fileBuffer+offset);
  715. #if ( GUI_RGB_FORMAT == RGB_FORMAT_565)
  716. *getXYData32(img, j, i) = (color16<<1) & 0xFFC0 | (color16 & 0x1F);
  717. #else
  718. *getXYData32(img, j, i) = mv_RGB2Color((color16 & 0x7C00) >> 7, (color16 & 0x03E0) >> 2, (color16 & 0x001F) << 3);
  719. #endif
  720. offset += 2;
  721. }
  722. offset += bytes;
  723. }
  724. }
  725. break;
  726. case 8: //256 colormap
  727. bytes = 4 - width % 4;
  728. if (bytes == 4)
  729. bytes = 0;
  730. for (i = height - 1; i >= 0; i--) {
  731. for (j = 0; j < width; j++) {
  732. int offSet = *(fileBuffer + offset) * 4;
  733. b = colorMap[offSet];
  734. g = colorMap[offSet + 1];
  735. r = colorMap[offSet + 2];
  736. *getXYData32(img, j, i) = mv_RGB2Color(r,g,b);
  737. offset ++;
  738. }
  739. offset += bytes;
  740. }
  741. break;
  742. default:
  743. break;
  744. }
  745. return 0;
  746. }
  747. static int getGlyphIndex(unsigned short unicode)
  748. {
  749. int i;
  750. GlyphRange * const range = (GlyphRange*)(m_fh+1);
  751. GlyphScatter * start;
  752. GlyphScatter * scatter;
  753. int low;
  754. int high;
  755. int mid;
  756. int glyphIndex = 1; // == 1 to skip missing lattice
  757. for (i = 0 ; i < m_fh->rangeCount; i++) {
  758. if ( unicode >= range[i].ucs2Start && unicode <= range[i].ucs2End) {
  759. glyphIndex += (unicode - range[i].ucs2Start);
  760. return glyphIndex;
  761. }
  762. glyphIndex += range[i].ucs2End - range[i].ucs2Start + 1;
  763. }
  764. start = (GlyphScatter*)(range + m_fh->rangeCount);
  765. low = 0;
  766. high = m_fh->scatterCount - 1;
  767. while (low <= high) {
  768. mid = (low + high) / 2;
  769. scatter = start + mid;
  770. if ( *scatter < unicode)
  771. low = mid + 1;
  772. else if ( *scatter > unicode)
  773. high = mid - 1;
  774. else
  775. return(glyphIndex + mid);
  776. }
  777. return 0;// the missing glyph
  778. }
  779. static unsigned char * getLattice(int glyphIndex)
  780. {
  781. return m_glyphStart + glyphIndex * m_fh->glyphBytes;
  782. }
  783. static int setFontFileDat(const unsigned char * dat)
  784. {
  785. FontFileHeadV1 * fh = (FontFileHeadV1*)dat;
  786. if ( fh->magic[0] != 'F' || fh->magic[1] != 'T') {
  787. printf("fh->magic[0] %c,fh->magic[1] %c\n",fh->magic[0],fh->magic[1]);
  788. return -1;
  789. }
  790. m_fileStart = (unsigned char * )dat;
  791. m_fh = (FontFileHeadV1*)m_fileStart;
  792. m_glyphStart = m_fileStart + sizeof(FontFileHeadV1)
  793. + m_fh->rangeCount * sizeof(GlyphRange)
  794. + m_fh->scatterCount * sizeof(GlyphScatter);
  795. return 0;
  796. }
  797. static void loadFontImage(int code, mv_surface* img)
  798. {
  799. int idx = 0;
  800. idx = getGlyphIndex((unsigned short)code);
  801. img->width = m_fh->charWidth;
  802. img->height = m_fh->charHeight;
  803. img->startAddr = (char *)getLattice(idx);
  804. }
  805. int mv_textOut(int x, int y, const char * string, unsigned int textColor)
  806. {
  807. if(g_bpp == 16)
  808. mv_textOut16(x, y, string, textColor);
  809. else if(g_bpp == 32)
  810. mv_textOut32(x, y, string, textColor);
  811. }
  812. int mv_textOut16(int x, int y, const char * string, unsigned short textColor)
  813. {
  814. mv_surface img;
  815. const char * p;
  816. const unsigned char * lattice;
  817. int h,w;
  818. int height = 0;
  819. for (p = string; *p != '\0'; p++) {
  820. loadFontImage(*p, &img);
  821. if(img.height > height)
  822. height = img.height;
  823. lattice = (const unsigned char * )img.startAddr;
  824. if (!lattice)
  825. continue;
  826. for ( h = 0 ; h < img.height; ++h) {
  827. unsigned char mask = 0x80;
  828. for ( w = 0 ; w < img.width; ++w) {
  829. if (*lattice & mask) {
  830. *(getXYData16(&s_primary, x + w, y + h)) = textColor;
  831. }
  832. mask >>= 1;
  833. if ( mask == 0 ) {
  834. mask = 0x80;
  835. ++lattice;// next byte
  836. }
  837. }
  838. if (mask != 0x80) {
  839. ++lattice;// next byte
  840. }
  841. }
  842. x += img.width;
  843. }
  844. return height;
  845. }
  846. int mv_textOut32(int x, int y, const char * string, unsigned int textColor)
  847. {
  848. mv_surface img;
  849. const char * p;
  850. const unsigned char * lattice;
  851. int h,w;
  852. int height = 0;
  853. for (p = string; *p != '\0'; p++) {
  854. loadFontImage(*p, &img);
  855. if(img.height > height)
  856. height = img.height;
  857. lattice = (const unsigned char * )img.startAddr;
  858. if (!lattice)
  859. continue;
  860. for ( h = 0 ; h < img.height; ++h) {
  861. unsigned char mask = 0x80;
  862. for ( w = 0 ; w < img.width; ++w) {
  863. if (*lattice & mask) {
  864. *(getXYData32(&s_primary, x + w, y + h)) = textColor;
  865. }
  866. mask >>= 1;
  867. if ( mask == 0 ) {
  868. mask = 0x80;
  869. ++lattice;// next byte
  870. }
  871. }
  872. if (mask != 0x80) {
  873. ++lattice;// next byte
  874. }
  875. }
  876. x += img.width;
  877. }
  878. return height;
  879. }