ESP8266 ILI9341 display support code with printf sources, wire-frame viewer and custom fonts  1.0
ESP8266ILI9341DisplayProject
vfont.c
Go to the documentation of this file.
1 #ifdef VFONTS
2 
26 #include <stdint.h>
27 #include <stdarg.h>
28 #include <string.h>
29 #include <math.h>
30 
31 
32 #ifdef USER_CONFIG
33 #include "user_config.h"
34 #endif
35 
37 #ifndef MEMSPACE
38 #define MEMSPACE_FONT MEMSPACE
39 #endif
40 
41 #include "display/ili9341.h"
42 
43 #include "display/vfont.h"
44 #include "display/vfonts.h"
45 
46 #define BEZIER_STEPS 10
47 
48 void drawSVG(window *win, int16_t x, int16_t y, int16_t c, float scale, uint16_t color, int16_t fill)
49 {
50 
51  p2_int16_t Ctl,T;
52  p2_int16_t Cur;
53  p2_int16_t Move;
54  int16_t Xsize,Ysize;
55 
56  int state;
57  p2_int16_t p[3];
58  p2_int16_t B[BEZIER_STEPS];
59 
60  int ind;
61  int t;
62  int i,j,count;
63 
64  int16_t *v;
65 
66  if( c >= 32 && c <= 127)
67  {
68  c -= 32;
69  v = vfont[c]->v;
70  Xsize = (scale * vfont[c]->xinc);
71  Ysize = (scale * vfont[c]->yinc);
72  // CLear
73  tft_fillRectWH(win, x, y, Xsize, Ysize, win->bg);
74 
75  }
76  else
77  {
78  printf("DrawSVG: invalid character\n");
79  return;
80  }
81 
82 
83  printf("DrawSVG:(%d,%d) scale:%e)\n", x,y,(double)scale);
84 
85  ind = 0;
86  state = 0;
87  while(1)
88  {
89  char t = v[ind];
90  if (t == 'M')
91  {
92  // Move takes to move points
93  Move.X = x + (scale * v[ind + 1]);
94  Move.Y = y + (scale * v[ind + 2]);
95  //printf("M: Move.X:%d,Move.Y:%d\n", (int)Move.X,(int)Move.Y);
96  Cur.X = Move.X;
97  Cur.Y = Move.Y;
98  if(state < 3)
99  {
100  p[state].X = Cur.X;
101  p[state].Y = Cur.Y;
102  ++state;
103  }
104  ind += 3;
105  }
106  else if (t == 'L' )
107  {
108  // Line takes Cur.X,Cur.Y and to target points
109  T.X = x + (scale * v[ind + 1]);
110  T.Y = y + (scale * v[ind + 2]);
111  //printf("L: Curx:%d,Cury:%d,T.X:%d,T.Y:%d\n", (int)Cur.X,(int)Cur.Y,(int)T.X,(int)T.Y);
112  if(T.X != Cur.X || T.Y != Cur.Y)
113  {
114  tft_drawLine(win, Cur.X, Cur.Y, T.X, T.Y, color);
115  if(state < 3)
116  {
117  p[state].X = T.X;
118  p[state].Y = T.Y;
119  ++state;
120  }
121  }
122  Cur.X = T.X;
123  Cur.Y = T.Y;
124  ind += 3;
125 
126  }
127  else if (t == 'Q' )
128  {
129  // Q Bezier takes Cur.X,Cur.Y, two control points and to target points
130  Ctl.X = x + (scale * v[ind + 1]);
131  Ctl.Y = y + (scale * v[ind + 2]);
132  T.X = x + (scale * v[ind + 3]);
133  T.Y = y + (scale * v[ind + 4]);
134  //printf("Q: Cur.X:%d,Cury:%d,Ctl.X:%d,Ctl.Y:%d,T.X:%d,T.Y:%d\n", (int)Cur.X,(int)Cur.Y,(int)Ctl.X,(int)Ctl.Y,(int)T.X,(int)T.Y);
135  if(T.X != Cur.X || T.Y != Cur.Y)
136  {
137 #if 1
138  count = tft_Bezier2(win, Cur, Ctl, T, BEZIER_STEPS, color);
139 #else
140  if(T.X != Cur.X || T.Y != Cur.Y)
141  tft_drawLine(win, Cur.X, Cur.Y, T.X, T.Y, color);
142 #endif
143  if(state < 3)
144  {
145  p[state].X = T.X;
146  p[state].Y = T.Y;
147  ++state;
148  }
149  }
150  Cur.X = T.X;
151  Cur.Y = T.Y;
152  ind += 5;
153 
154  }
155  else if (t == 'Z')
156  {
157  // CLOSE takes no params
158  //printf("Z: Curx:%d,Cury:%d,Move.X:%d,Move.Y:%d\n", (int)Cur.X,(int)Cur.Y,(int)Move.X,(int)Move.Y);
159  if(Cur.X != Move.X || Cur.Y != Move.Y)
160  {
161  tft_drawLine(win, Cur.X, Cur.Y, Move.X, Move.Y, color);
162  if(state < 3)
163  {
164  p[state].X = T.X;
165  p[state].Y = T.Y;
166  ++state;
167  }
168  }
169  Cur.X = Move.X;
170  Cur.Y = Move.Y;
171  ind += 1;
172  }
173  else if (t == '.')
174  {
175  break;
176  }
177  else
178  {
179  printf("bad type:%c @ index:%d\n", (int)t, (int)ind);
180  break;
181  }
182  }
183 
184 #if 1
185 
186  if(state == 3)
187  {
188  int i;
189  printf("Fill\n");
190  for(i=0;i<3;++i)
191  {
192  printf("%d,%d\n", p[i].X, p[i].Y);
193  }
194 
195  }
196 
197 #else
198  if(fill)
199  {
200  for(i=0;i<Ysize;++i)
201  {
202  count = tft_FillPolyLine( win , x, y + i, Xsize, color );
203  // optimistic_yield(1000);
204 
205  }
206  }
207 #endif
208 }
209 
210 #endif //ifdef VFONTS
unsigned short uint16_t
Definition: send.c:18
Master include file for project Includes all project includes and defines here.
uint16_t bg
Definition: ili9341.h:45
void tft_fillRectWH(window *win, int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color)
Partial window Fill with color We clip the window to the current view.
Definition: ili9341.c:627
Cordic_T X
Main Cordic routine - used for basic trig and vector rotations We use fixed point numbers...
Definition: cordic.c:102
void drawSVG(window *win, int16_t x, int16_t y, int16_t c, float scale, uint16_t color, int16_t fill)
int16_t xinc
Definition: vfont.h:43
int16_t v[]
Definition: vfont.h:48
int16_t y[XYSTACK+2]
Definition: ili9341.c:372
path_t * vfont[]
Definition: vfonts.h:3808
Cordic_T Y
Definition: cordic.c:102
int tft_Bezier2(window *win, p2_int16_t S, p2_int16_t C, p2_int16_t T, int steps, uint16_t color)
Draw lines between points along Quadratic Bézier curve Quadratic Bézier with respect to t...
Definition: ili9341.c:1474
int16_t x[XYSTACK+2]
Definition: ili9341.c:371
int ind
Definition: ili9341.c:373
2D display point - display coordinates are int16
Definition: ili9341.h:51
void tft_drawLine(window *win, int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color)
Draw line From my blit test code testit.c 1984 - 1985 Mike Gore.
Definition: ili9341.c:1389
int16_t X
Definition: ili9341.h:52
int tft_FillPolyLine(window *win, int16_t x, int16_t y, int w, uint16_t color)
Definition: ili9341.c:510
int16_t yinc
Definition: vfont.h:44
MEMSPACE int printf(const char *format,...)
Definition: ili9341.h:34
int16_t Y
Definition: ili9341.h:53
ili9341 driver inspired by Adafruit ili9341 code All code in this file has been rewritten by Mike Gor...