1 /* draw.c: main drawing routines. */
2
3 /* This file is part of asciiTeX.
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; see the file COPYING. If not, write to
16 The Free Software Foundation, Inc.
17 59 Temple Place, Suite 330
18 Boston, MA 02111 USA
19
20
21 Authors:
22 Original program (eqascii): Przemek Borys
23 Fork by: Bart Pieters
24
25 *************************************************************************/
26
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include "parsedef.h"
30 #include "asciiTeX_struct.h"
31 #include "utils.h"
32 #include "frac.h"
33 #include "sscript.h"
34 #include "sqrt.h"
35 #include "ouline.h"
36 #include "symbols.h"
37 #include "brace.h"
38 #include "array.h"
39 #include "limit.h"
40
41 void
drawInternal(char *** screen,struct Tgraph * graph,int x,int y)42 drawInternal(char ***screen, struct Tgraph *graph, int x, int y)
43 {
44 int kid = 0,
45 curx = x,
46 cury = y + (graph->dim.y - 1) - graph->dim.baseline;
47 char *txt = graph->txt;
48 while (*txt)
49 {
50 if (*txt == 1)
51 {
52 txt++;
53 switch ((PRSDEF) * txt)
54 {
55
56 case SUPER:
57 drawSuperscript(&kid, &curx, &cury, screen,
58 graph, txt);
59 break;
60 case SUB:
61 drawSubscript(&kid, &curx, &cury, screen,
62 graph, txt);
63 break;
64 case FRAC:
65 drawFrac(&kid, &curx, &cury, screen,
66 graph);
67 break;
68 case SQRT:
69 drawSqrt(&kid, &curx, &cury, screen,
70 graph);
71 break;
72 case OVERLINE:
73 drawOverl(&kid, &curx, &cury, screen,
74 graph);
75 break;
76 case UNDERLINE:
77 drawUnderl(&kid, &curx, &cury, screen,
78 graph);
79 break;
80 case LIMIT:
81 drawLimit(&kid, &curx, &cury, screen,
82 graph);
83 break;
84 case BRACES:
85 drawBrace(&kid, &curx, &cury, screen,
86 graph);
87 break;
88 case ARRAY:
89 drawArray(&kid, &curx, &cury, screen,
90 graph);
91 break;
92 case TO:
93 drawTo(&kid, &curx, &cury, screen, graph);
94 break;
95 case LEADSTO:
96 drawLeadsto(&kid, &curx, &cury, screen,
97 graph);
98 break;
99 case SUM:
100 drawSum(&kid, &curx, &cury, screen, graph);
101 break;
102 case PROD:
103 drawProd(&kid, &curx, &cury, screen,
104 graph);
105 break;
106 case INT:
107 drawInt(&kid, &curx, &cury, screen, graph);
108 break;
109 case LCEIL:
110 drawLceil(&kid, &curx, &cury, screen,
111 graph);
112 break;
113 case RCEIL:
114 drawRceil(&kid, &curx, &cury, screen,
115 graph);
116 break;
117 case LFLOOR:
118 drawLfloor(&kid, &curx, &cury, screen,
119 graph);
120 break;
121 case RFLOOR:
122 drawRfloor(&kid, &curx, &cury, screen,
123 graph);
124 break;
125 case OINT:
126 drawOint(&kid, &curx, &cury, screen,
127 graph);
128 break;
129 default:
130 fprintf(stderr,
131 "I screwed up in draw, this should never happen!\n");
132 exit(1);
133 break;
134 }
135 } else
136 (*screen)[cury][curx++] = *txt;
137 txt++;
138 }
139 }
140
141 char **
draw(struct Tgraph * graph)142 draw(struct Tgraph *graph)
143 {
144 char **screen = malloc(sizeof(char *) * (graph->dim.y + 1));
145 int i,
146 j;
147 for (i = 0; i < graph->dim.y; i++)
148 {
149 screen[i] = malloc((graph->dim.x + 2) * sizeof(char));
150 for (j = 0; j < graph->dim.x; j++)
151 screen[i][j] = ' ';
152 screen[i][graph->dim.x] = 0;
153 }
154 drawInternal(&screen, graph, 0, 0);
155 return screen;
156 }
157