The SZ / WakeupLight

Dependencies:   BSP_DISCO_F746NG_patch_fixed LCD_DISCO_F746NG TS_DISCO_F746NG FATFileSystem TinyJpgDec_interwork mbed-src

Committer:
the_sz
Date:
Sun Jan 31 17:45:50 2016 +0000
Revision:
13:811a5c5b3fd6
Child:
14:2044ad5cd3fe
pre-font-alias

Who changed what in which revision?

UserRevisionLine numberNew contents of line
the_sz 13:811a5c5b3fd6 1 //
the_sz 13:811a5c5b3fd6 2 // use http://www.eran.io/the-dot-factory-an-lcd-font-and-image-generator/ to create the font definitions
the_sz 13:811a5c5b3fd6 3 // plus modify output:
the_sz 13:811a5c5b3fd6 4 // - char height: in bits
the_sz 13:811a5c5b3fd6 5 // - font height: don't display
the_sz 13:811a5c5b3fd6 6 // - generate space bitmap
the_sz 13:811a5c5b3fd6 7 //
the_sz 13:811a5c5b3fd6 8 // - remove \ comment from const FONT_CHAR_INFO xxxDescriptors[]
the_sz 13:811a5c5b3fd6 9 // - rename fontxxx.c to fontxxx.cpp file
the_sz 13:811a5c5b3fd6 10 //
the_sz 13:811a5c5b3fd6 11
the_sz 13:811a5c5b3fd6 12 #include "FontX.h"
the_sz 13:811a5c5b3fd6 13
the_sz 13:811a5c5b3fd6 14 #include "stm32746g_discovery_lcd.h"
the_sz 13:811a5c5b3fd6 15
the_sz 13:811a5c5b3fd6 16 #define CHAR_SPACE 2
the_sz 13:811a5c5b3fd6 17
the_sz 13:811a5c5b3fd6 18 static bool useAlias=true;
the_sz 13:811a5c5b3fd6 19
the_sz 13:811a5c5b3fd6 20 uint32_t FontX_GetLength(char *Text,const FONT_INFO *pFont)
the_sz 13:811a5c5b3fd6 21 {
the_sz 13:811a5c5b3fd6 22 uint32_t length;
the_sz 13:811a5c5b3fd6 23 uint32_t index;
the_sz 13:811a5c5b3fd6 24
the_sz 13:811a5c5b3fd6 25 length=0;
the_sz 13:811a5c5b3fd6 26
the_sz 13:811a5c5b3fd6 27 while ((*Text)!='\0')
the_sz 13:811a5c5b3fd6 28 {
the_sz 13:811a5c5b3fd6 29 if (((*Text)>=pFont->StartCharacter) && ((*Text)<=pFont->EndCharacter))
the_sz 13:811a5c5b3fd6 30 {
the_sz 13:811a5c5b3fd6 31 index=(*Text)-pFont->StartCharacter;
the_sz 13:811a5c5b3fd6 32 length+=pFont->Descriptors[index].Charwidth;
the_sz 13:811a5c5b3fd6 33 }
the_sz 13:811a5c5b3fd6 34
the_sz 13:811a5c5b3fd6 35 length+=CHAR_SPACE;
the_sz 13:811a5c5b3fd6 36
the_sz 13:811a5c5b3fd6 37 Text++;
the_sz 13:811a5c5b3fd6 38 }
the_sz 13:811a5c5b3fd6 39
the_sz 13:811a5c5b3fd6 40 return length;
the_sz 13:811a5c5b3fd6 41 }
the_sz 13:811a5c5b3fd6 42
the_sz 13:811a5c5b3fd6 43 uint32_t FontX_GetHeight(const FONT_INFO *pFont)
the_sz 13:811a5c5b3fd6 44 {
the_sz 13:811a5c5b3fd6 45 return pFont->Descriptors[0].Charheight;
the_sz 13:811a5c5b3fd6 46 }
the_sz 13:811a5c5b3fd6 47
the_sz 13:811a5c5b3fd6 48 void FontX_DisplayStringAt(uint16_t Xpos,uint16_t Ypos,uint16_t width,char *Text,FONTX_ALIGNMENT_ENUM Alignment,const FONT_INFO *pFont,uint32_t colorText,uint32_t colorBack)
the_sz 13:811a5c5b3fd6 49 {
the_sz 13:811a5c5b3fd6 50 uint32_t xsize = 0;
the_sz 13:811a5c5b3fd6 51
the_sz 13:811a5c5b3fd6 52 /* get pixel length */
the_sz 13:811a5c5b3fd6 53 xsize = FontX_GetLength(Text,pFont);
the_sz 13:811a5c5b3fd6 54
the_sz 13:811a5c5b3fd6 55 switch (Alignment)
the_sz 13:811a5c5b3fd6 56 {
the_sz 13:811a5c5b3fd6 57 case ALIGN_CENTER:
the_sz 13:811a5c5b3fd6 58 Xpos+=(width-xsize)/2;
the_sz 13:811a5c5b3fd6 59 break;
the_sz 13:811a5c5b3fd6 60
the_sz 13:811a5c5b3fd6 61 case ALIGN_RIGHT:
the_sz 13:811a5c5b3fd6 62 Xpos=width-xsize-Xpos;
the_sz 13:811a5c5b3fd6 63 break;
the_sz 13:811a5c5b3fd6 64
the_sz 13:811a5c5b3fd6 65 case ALIGN_LEFT:
the_sz 13:811a5c5b3fd6 66 default:
the_sz 13:811a5c5b3fd6 67 break;
the_sz 13:811a5c5b3fd6 68 }
the_sz 13:811a5c5b3fd6 69
the_sz 13:811a5c5b3fd6 70 /* send the string character by character on LCD */
the_sz 13:811a5c5b3fd6 71 while ((*Text)!='\0')
the_sz 13:811a5c5b3fd6 72 {
the_sz 13:811a5c5b3fd6 73 /* display one character on LCD */
the_sz 13:811a5c5b3fd6 74 Xpos+=FontX_DisplayChar(Xpos,Ypos,*Text,pFont,colorText,colorBack);
the_sz 13:811a5c5b3fd6 75
the_sz 13:811a5c5b3fd6 76 /* point on the next character */
the_sz 13:811a5c5b3fd6 77 Text++;
the_sz 13:811a5c5b3fd6 78 }
the_sz 13:811a5c5b3fd6 79 }
the_sz 13:811a5c5b3fd6 80
the_sz 13:811a5c5b3fd6 81 uint32_t FontX_DisplayChar(uint16_t Xpos,uint16_t Ypos,char Ascii,const FONT_INFO *pFont,uint32_t colorText,uint32_t colorBack)
the_sz 13:811a5c5b3fd6 82 {
the_sz 13:811a5c5b3fd6 83 uint32_t line;
the_sz 13:811a5c5b3fd6 84 uint32_t index;
the_sz 13:811a5c5b3fd6 85 uint32_t offset;
the_sz 13:811a5c5b3fd6 86 uint32_t lineOffset;
the_sz 13:811a5c5b3fd6 87 uint32_t i;
the_sz 13:811a5c5b3fd6 88 uint32_t j;
the_sz 13:811a5c5b3fd6 89
the_sz 13:811a5c5b3fd6 90 if (Ascii<pFont->StartCharacter)
the_sz 13:811a5c5b3fd6 91 return 0;
the_sz 13:811a5c5b3fd6 92 if (Ascii>pFont->EndCharacter)
the_sz 13:811a5c5b3fd6 93 return 0;
the_sz 13:811a5c5b3fd6 94
the_sz 13:811a5c5b3fd6 95 index=Ascii-pFont->StartCharacter;
the_sz 13:811a5c5b3fd6 96
the_sz 13:811a5c5b3fd6 97 lineOffset=8 * ((pFont->Descriptors[index].Charwidth + 7) / 8) - pFont->Descriptors[index].Charwidth;
the_sz 13:811a5c5b3fd6 98
the_sz 13:811a5c5b3fd6 99 offset=pFont->Descriptors[index].Offset;
the_sz 13:811a5c5b3fd6 100 for (i=0;i<pFont->Descriptors[index].Charheight;i++)
the_sz 13:811a5c5b3fd6 101 {
the_sz 13:811a5c5b3fd6 102 switch(((pFont->Descriptors[index].Charwidth + 7)/8))
the_sz 13:811a5c5b3fd6 103 {
the_sz 13:811a5c5b3fd6 104 case 1:
the_sz 13:811a5c5b3fd6 105 line=pFont->Bitmaps[offset];
the_sz 13:811a5c5b3fd6 106 offset++;
the_sz 13:811a5c5b3fd6 107 break;
the_sz 13:811a5c5b3fd6 108
the_sz 13:811a5c5b3fd6 109 case 2:
the_sz 13:811a5c5b3fd6 110 line=(pFont->Bitmaps[offset]<<8) | pFont->Bitmaps[offset+1];
the_sz 13:811a5c5b3fd6 111 offset+=2;
the_sz 13:811a5c5b3fd6 112 break;
the_sz 13:811a5c5b3fd6 113
the_sz 13:811a5c5b3fd6 114 case 3:
the_sz 13:811a5c5b3fd6 115 default:
the_sz 13:811a5c5b3fd6 116 line=(pFont->Bitmaps[offset]<<16) | (pFont->Bitmaps[offset+1]<<8) | pFont->Bitmaps[offset+2];
the_sz 13:811a5c5b3fd6 117 offset+=3;
the_sz 13:811a5c5b3fd6 118 break;
the_sz 13:811a5c5b3fd6 119 }
the_sz 13:811a5c5b3fd6 120
the_sz 13:811a5c5b3fd6 121 if (useAlias==true)
the_sz 13:811a5c5b3fd6 122 {
the_sz 13:811a5c5b3fd6 123 xxxx
the_sz 13:811a5c5b3fd6 124 // get average of 2x2 pixel array
the_sz 13:811a5c5b3fd6 125 for (j=0;j<pFont->Descriptors[index].Charwidth;j++)
the_sz 13:811a5c5b3fd6 126 {
the_sz 13:811a5c5b3fd6 127 if (line & (1 << (pFont->Descriptors[index].Charwidth - j + lineOffset - 1)))
the_sz 13:811a5c5b3fd6 128 {
the_sz 13:811a5c5b3fd6 129 BSP_LCD_DrawPixel((Xpos+j),Ypos,colorText);
the_sz 13:811a5c5b3fd6 130 }
the_sz 13:811a5c5b3fd6 131 else
the_sz 13:811a5c5b3fd6 132 {
the_sz 13:811a5c5b3fd6 133 if (colorBack!=0x00000000)
the_sz 13:811a5c5b3fd6 134 BSP_LCD_DrawPixel((Xpos+j),Ypos,colorBack);
the_sz 13:811a5c5b3fd6 135 }
the_sz 13:811a5c5b3fd6 136 }
the_sz 13:811a5c5b3fd6 137
the_sz 13:811a5c5b3fd6 138 // alpha blend it to the current screen
the_sz 13:811a5c5b3fd6 139 if (colorBack!=0x00000000)
the_sz 13:811a5c5b3fd6 140
the_sz 13:811a5c5b3fd6 141 // write pixel
the_sz 13:811a5c5b3fd6 142 uint32_t BSP_LCD_ReadPixel(uint16_t Xpos, uint16_t Ypos);
the_sz 13:811a5c5b3fd6 143 xxxxx
the_sz 13:811a5c5b3fd6 144 }
the_sz 13:811a5c5b3fd6 145 else
the_sz 13:811a5c5b3fd6 146 {
the_sz 13:811a5c5b3fd6 147 for (j=0;j<pFont->Descriptors[index].Charwidth;j++)
the_sz 13:811a5c5b3fd6 148 {
the_sz 13:811a5c5b3fd6 149 if (line & (1 << (pFont->Descriptors[index].Charwidth - j + lineOffset - 1)))
the_sz 13:811a5c5b3fd6 150 {
the_sz 13:811a5c5b3fd6 151 BSP_LCD_DrawPixel((Xpos+j),Ypos,colorText);
the_sz 13:811a5c5b3fd6 152 }
the_sz 13:811a5c5b3fd6 153 else
the_sz 13:811a5c5b3fd6 154 {
the_sz 13:811a5c5b3fd6 155 if (colorBack!=0x00000000)
the_sz 13:811a5c5b3fd6 156 BSP_LCD_DrawPixel((Xpos+j),Ypos,colorBack);
the_sz 13:811a5c5b3fd6 157 }
the_sz 13:811a5c5b3fd6 158 }
the_sz 13:811a5c5b3fd6 159 }
the_sz 13:811a5c5b3fd6 160
the_sz 13:811a5c5b3fd6 161 // fill char space area
the_sz 13:811a5c5b3fd6 162 if (colorBack!=0x00000000)
the_sz 13:811a5c5b3fd6 163 {
the_sz 13:811a5c5b3fd6 164 for (j=0;j<CHAR_SPACE;j++)
the_sz 13:811a5c5b3fd6 165 BSP_LCD_DrawPixel((Xpos+pFont->Descriptors[index].Charwidth+j),Ypos,colorBack);
the_sz 13:811a5c5b3fd6 166 }
the_sz 13:811a5c5b3fd6 167
the_sz 13:811a5c5b3fd6 168 Ypos++;
the_sz 13:811a5c5b3fd6 169 }
the_sz 13:811a5c5b3fd6 170
the_sz 13:811a5c5b3fd6 171 return pFont->Descriptors[index].Charwidth+CHAR_SPACE;
the_sz 13:811a5c5b3fd6 172 }