You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

fonts.c 7.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  1. #include "fonts.h"
  2. /*Here is how a character is defined.
  3. Each character is 7 pixels high. The length is defined by you in the length array.
  4. Because some characters (ex: m, M) are 5 px wide, the total amount is >32 bit,
  5. so the character is stored in an array of 2 longs. The first long is only used if
  6. the character is >32 bit.
  7. For example, the character 'M', of length 3, is the following in binary:
  8. 00000
  9. 10001
  10. 11011
  11. 10101
  12. 10001
  13. 10001
  14. 00000
  15. You must not forget the "00000" at the end, else your character will be shifted down by a pixel.
  16. Now just remove the newlines in the character. You should get: 00000100011101110101100011000100000
  17. Put that in a binary to decimal converter and you've got your number representing the character.
  18. Also, make sure to define the correct length, else it will display gibberish.
  19. */
  20. struct Font normfont = {
  21. {{ //letters
  22. 0 //space
  23. },{0, 58 //!
  24. },{0, 184320 //" replaced by 0x81
  25. },{0, 368409920 //#
  26. },{0, 524752832 //$
  27. },{0, 136456 //%
  28. },{0, 6838992 //&
  29. },{0, 48 //'
  30. },{0, 1700 //(
  31. },{0, 2392 //)
  32. },{0, 174592 //*
  33. },{0, 11904 //+
  34. },{0, 3 //
  35. },{0, 3584 //-
  36. },{0, 2 //.
  37. },{0, 38176 ///
  38. },{0, 252792 //0
  39. },{0, 206008 //1
  40. },{0, 237368 //2
  41. },{0, 235128 //3
  42. },{0, 187976 //4
  43. },{0, 249464 //5
  44. },{0, 249720 //6
  45. },{0, 234640 //7
  46. },{0, 253816 //8
  47. },{0, 253560 //9
  48. },{0, 10 //:
  49. },{0, 11 //;
  50. },{0, 43144 //< replaced by 0x7F
  51. },{0, 29120 //=
  52. },{0, 139936 //> replaced by 0x80
  53. },{0, 201744 //?
  54. },{0, 488035776 //@
  55. },{0, 6922128 //A
  56. },{0, 15329760 //B
  57. },{0, 6916448 //C
  58. },{0, 15309280 //D
  59. },{0, 16312560 //E
  60. },{0, 16312448 //F
  61. },{0, 7911776 //G
  62. },{0, 10090896 //H
  63. },{0, 238776 //I
  64. },{0, 7480000 //J
  65. },{0, 10144400 //K
  66. },{0, 8947952 //L
  67. },{0, 599442976 //M
  68. },{0, 10336656 //N
  69. },{0, 6920544 //O
  70. },{0, 15310464 //P
  71. },{0, 6921072 //Q
  72. },{0, 15310480 //R
  73. },{0, 7889376 //S
  74. },{0, 238736 //T
  75. },{0, 10066288 //U
  76. },{0, 588818560 //V
  77. },{0, 588961088 //W
  78. },{0, 185704 //X
  79. },{0, 187024 //Y
  80. },{0, 15878384 //Z
  81. },{0, 3756 //[
  82. },{0, 148552 //backslash
  83. },{0, 3420 //]
  84. },{0, 86016 //^
  85. },{0, 7 //_
  86. },{0, 3648 //`
  87. },{0, 15192 //a
  88. },{0, 158576 //b
  89. },{0, 14616 //c
  90. },{0, 47960 //d
  91. },{0, 15256 //e
  92. },{0, 118048 //f
  93. },{0, 15310 //g
  94. },{0, 158568 //h
  95. },{0, 46 //i
  96. },{0, 1111 //j
  97. },{0, 154984 //k
  98. },{0, 62 //l
  99. },{0, 27973280 //m
  100. },{0, 27496 //n
  101. },{0, 11088 //o
  102. },{0, 27508 //p
  103. },{0, 15193 //q
  104. },{0, 23840 //r
  105. },{0, 924 //s
  106. },{0, 2988 //t
  107. },{0, 23416 //u
  108. },{0, 23376 //v
  109. },{0, 18535744 //w
  110. },{0, 21864 //x
  111. },{0, 23246 //y
  112. },{0, 30008 //z
  113. },{0, 108696 //{
  114. },{0, 62 //|
  115. },{0, 205488 //}
  116. },{0, 448512 //~
  117. },{0, 43144 //< 0x7F
  118. },{0, 139936 //> 0x80
  119. },{0, 184320 //" 0x81
  120. },{0, 50022784 //look of disapproval 0x82
  121. },{0, 496640000 //lenny face eye 0x83
  122. },{0, 138482222 //lenny face nose/mouth 0x84
  123. },{0, 4088 //sunglasses 0x85
  124. },{0, 3840 //*puts on sunglasses* 0x86
  125. },{0, 229376 //overline 0x87
  126. },{0, 693142620 //shrug face 0x88
  127. },{0, 801688 //é 0x89
  128. },{0, 201744 //for some reason, when the dispStr() function seeks the character at 0x90 and above
  129. },{0, 201744 //it actually seeks it 6 characters after. there is absolutely no logical way I can think of
  130. },{0, 201744 //that causes this bug. 0x90 (144) is not a significant number. neither is 6.
  131. },{0, 201744 //so rather than spending 4532 hours debugging, the fix is simple:
  132. },{0, 201744 //just put 6 characters between 0x89 and 0x90.
  133. },{0, 201744
  134. },{0, 1588120 //è 0x90
  135. },{0, 1588056 //à 0x91
  136. },{0, 1596280 //ù 0x92
  137. },{0, 14622 //ç 0x93
  138. },{0, 1617408 //² 0x94
  139. },{0, 55501872 //€ 0x95
  140. },{0, 1048716256 //somme 0x96
  141. }},{ //lengths
  142. 3, //space
  143. 1, //!
  144. 3, //"
  145. 5, //#
  146. 5, //$
  147. 3, //%
  148. 4, //&
  149. 1, //'
  150. 2, //(
  151. 2, //)
  152. 3, //*
  153. 3, //+
  154. 1, //,
  155. 3, //-
  156. 1, //.
  157. 3, ///
  158. 3, //0
  159. 3, //1
  160. 3, //2
  161. 3, //3
  162. 3, //4
  163. 3, //5
  164. 3, //6
  165. 3, //7
  166. 3, //8
  167. 3, //9
  168. 1, //:
  169. 1, //;
  170. 3, //<
  171. 3, //=
  172. 3, //>
  173. 3, //?
  174. 5, //@
  175. 4, //A
  176. 4, //B
  177. 4, //C
  178. 4, //D
  179. 4, //E
  180. 4, //F
  181. 4, //G
  182. 4, //H
  183. 3, //I
  184. 4, //J
  185. 4, //K
  186. 4, //L
  187. 5, //M
  188. 4, //N
  189. 4, //O
  190. 4, //P
  191. 4, //Q
  192. 4, //R
  193. 4, //S
  194. 3, //T
  195. 4, //U
  196. 5, //V
  197. 5, //W
  198. 3, //X
  199. 3, //Y
  200. 4, //Z
  201. 2, //[
  202. 3, //backslash
  203. 2, //]
  204. 3, //^
  205. 3, //_
  206. 2, //`
  207. 3, //a
  208. 3, //b
  209. 3, //c
  210. 3, //d
  211. 3, //e
  212. 3, //f
  213. 3, //g
  214. 3, //h
  215. 1, //i
  216. 2, //j
  217. 3, //k
  218. 1, //l
  219. 5, //m
  220. 3, //n
  221. 3, //o
  222. 3, //p
  223. 3, //q
  224. 3, //r
  225. 2, //s
  226. 2, //t
  227. 3, //u
  228. 3, //v
  229. 5, //w
  230. 3, //x
  231. 3, //y
  232. 3, //z
  233. 3, //{
  234. 1, //|
  235. 3, //}
  236. 5, //~
  237. 3, //<
  238. 3, //>
  239. 3, //"
  240. 5, //look of disapproval
  241. 5, //lenny face eye
  242. 5, //lenny face nose/mouth
  243. 3, //sunglasses
  244. 3, //*puts on sunglasses*
  245. 3, //overline
  246. 5, //shrug face
  247. 3, //é
  248. 3, //unused lengths, see letters comment
  249. 3,
  250. 3,
  251. 3,
  252. 3,
  253. 3,
  254. 3, //è
  255. 3, //à
  256. 3, //ù
  257. 3, //ç
  258. 3, //²
  259. 4, //€
  260. 5, //somme
  261. 3,
  262. 3,
  263. 3,
  264. 3,
  265. 3,
  266. 3,
  267. 3,
  268. 3,
  269. 3,
  270. 3,
  271. 3
  272. }
  273. };
  274. //displays a given string, using a given font, at the given coordinates
  275. //returns the height of the string
  276. int dispStr(unsigned char* str, int x2, int y) {
  277. int k = 0;
  278. int x = x2;
  279. int y2 = y;
  280. do { //browses through the given string
  281. //word wrap: if the current character isn't a space, simply display it
  282. if (str[k] != ' ' && str[k] != '\0' && str[k] != '\n') {
  283. if (y >= -6 && y < 68) {
  284. int charlength = normfont.length[str[k]-32];
  285. unsigned long j = 1 << ((7*charlength)%32)-1; //initializes a long for bit checking. The long is equal to 0b10000.. with number of zeroes being the maximum length of the character, minus 1 because there's already a 1.
  286. char i;
  287. for (i = 0; i < 7*charlength; i++) { //browses through the pixels of the character specified, shifting the 1 of j to the right each time, so that it makes 0b01000.., 0b001000... etc
  288. if (normfont.ltr[str[k]-32][1-(7*charlength-i)/33] & j) { //checks if the bit that is a 1 in the j is also a 1 in the character
  289. ML_pixel(x+i%(charlength), y+i/charlength, 1); //if so, locates the pixel at the coordinates, using modulo and division to calculate the coordinates relative to the top left of the character
  290. }
  291. if (j != 1)
  292. j >>= 1;
  293. else
  294. j = 2147483648;
  295. }
  296. }
  297. x += normfont.length[str[k]-32] + 1; //now that the character has been fully displayed, shifts the cursor right by the length of character + 1
  298. } else if (str[k] == '\n') {
  299. y += 8;
  300. x = x2;
  301. } else if (str[k] == ' ') { //the current character is a space, so see if it manages to display the word without going over x=128
  302. int i = x+4; //initializes an int to count the number of total pixels the next word takes
  303. int j = k+1; //initializes the char to the current char+1 (which is always another character)
  304. while (str[j] != 32 && str[j] != '\0' && str[j] != '\n') { //as long as it doesn't encounter another space or end of string
  305. i += normfont.length[str[j]-32]+1; //it increments i by the length of the character + 1
  306. j++;
  307. }
  308. if (i > 128) { //the word can't be displayed, note that it is STRICTLY superior because we added an unnecessary pixel at the end
  309. y += 8; //goes on next line which is 8 pixels down
  310. x = x2; //puts cursor on beginning of line
  311. } else {
  312. x += 4;
  313. }
  314. }
  315. k++;
  316. } while (str[k] != '\0');
  317. return y+8-y2;
  318. }