]>
Commit | Line | Data |
---|---|---|
9a29912f JS |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: table.cpp | |
3 | // Purpose: Utilities for manipulating tables | |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 01/01/99 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Julian Smart | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifdef __GNUG__ | |
13 | #pragma implementation | |
14 | #endif | |
15 | ||
16 | // For compilers that support precompilation, includes "wx.h". | |
17 | #include "wx/wxprec.h" | |
18 | ||
19 | #ifdef __BORLANDC__ | |
20 | #pragma hdrstop | |
21 | #endif | |
22 | ||
23 | #ifndef WX_PRECOMP | |
9a29912f JS |
24 | #endif |
25 | ||
5aa5c1e4 | 26 | #include "wx/hash.h" |
9a29912f | 27 | |
1a464ed9 JS |
28 | #ifdef new |
29 | #undef new | |
30 | #endif | |
31 | ||
9a29912f JS |
32 | #if wxUSE_IOSTREAMH |
33 | #include <iostream.h> | |
34 | #include <fstream.h> | |
35 | #else | |
36 | #include <iostream> | |
37 | #include <fstream> | |
38 | #endif | |
39 | ||
40 | #include <ctype.h> | |
41 | #include "tex2any.h" | |
42 | #include "table.h" | |
43 | ||
44 | ColumnData TableData[40]; | |
45 | bool inTabular = FALSE; | |
46 | ||
47 | bool startRows = FALSE; | |
48 | bool tableVerticalLineLeft = FALSE; | |
49 | bool tableVerticalLineRight = FALSE; | |
50 | int noColumns = 0; // Current number of columns in table | |
51 | int ruleTop = 0; | |
52 | int ruleBottom = 0; | |
53 | int currentRowNumber = 0; | |
54 | ||
55 | /* | |
56 | * Parse table argument | |
57 | * | |
58 | */ | |
59 | ||
6c155d33 | 60 | bool ParseTableArgument(wxChar *value) |
9a29912f JS |
61 | { |
62 | noColumns = 0; | |
63 | int i = 0; | |
6c155d33 | 64 | int len = wxStrlen(value); |
9a29912f JS |
65 | bool isBorder = FALSE; |
66 | while (i < len) | |
67 | { | |
68 | int ch = value[i]; | |
69 | if (ch == '|') | |
70 | { | |
71 | i ++; | |
72 | isBorder = TRUE; | |
73 | } | |
74 | else if (ch == 'l') | |
75 | { | |
76 | TableData[noColumns].leftBorder = isBorder; | |
77 | TableData[noColumns].rightBorder = FALSE; | |
78 | TableData[noColumns].justification = 'l'; | |
79 | TableData[noColumns].width = 2000; // Estimate | |
80 | TableData[noColumns].absWidth = FALSE; | |
81 | // TableData[noColumns].spacing = ?? | |
82 | noColumns ++; | |
83 | i ++; | |
84 | isBorder = FALSE; | |
85 | } | |
86 | else if (ch == 'c') | |
87 | { | |
88 | TableData[noColumns].leftBorder = isBorder; | |
89 | TableData[noColumns].rightBorder = FALSE; | |
90 | TableData[noColumns].justification = 'c'; | |
91 | TableData[noColumns].width = defaultTableColumnWidth; // Estimate | |
92 | TableData[noColumns].absWidth = FALSE; | |
93 | // TableData[noColumns].spacing = ?? | |
94 | noColumns ++; | |
95 | i ++; | |
96 | isBorder = FALSE; | |
97 | } | |
98 | else if (ch == 'r') | |
99 | { | |
100 | TableData[noColumns].leftBorder = isBorder; | |
101 | TableData[noColumns].rightBorder = FALSE; | |
102 | TableData[noColumns].justification = 'r'; | |
103 | TableData[noColumns].width = 2000; // Estimate | |
104 | TableData[noColumns].absWidth = FALSE; | |
105 | // TableData[noColumns].spacing = ?? | |
106 | noColumns ++; | |
107 | i ++; | |
108 | isBorder = FALSE; | |
109 | } | |
110 | else if (ch == 'p') | |
111 | { | |
112 | i ++; | |
113 | int j = 0; | |
6c155d33 | 114 | wxChar numberBuf[50]; |
9a29912f JS |
115 | ch = value[i]; |
116 | if (ch == '{') | |
117 | { | |
118 | i++; | |
119 | ch = value[i]; | |
120 | } | |
121 | ||
122 | while ((i < len) && (isdigit(ch) || ch == '.')) | |
123 | { | |
124 | numberBuf[j] = ch; | |
125 | j ++; | |
126 | i ++; | |
127 | ch = value[i]; | |
128 | } | |
129 | // Assume we have 2 characters for units | |
130 | numberBuf[j] = value[i]; | |
131 | j ++; i++; | |
132 | numberBuf[j] = value[i]; | |
133 | j ++; i++; | |
134 | numberBuf[j] = 0; | |
135 | if (value[i] == '}') i++; | |
136 | ||
137 | TableData[noColumns].leftBorder = isBorder; | |
138 | TableData[noColumns].rightBorder = FALSE; | |
139 | TableData[noColumns].justification = 'l'; | |
140 | TableData[noColumns].width = 20*ParseUnitArgument(numberBuf); | |
141 | TableData[noColumns].absWidth = TRUE; | |
142 | // TableData[noColumns].spacing = ?? | |
143 | noColumns ++; | |
144 | isBorder = FALSE; | |
145 | } | |
146 | else | |
147 | { | |
6c155d33 JS |
148 | wxChar *buf = new wxChar[wxStrlen(value) + 80]; |
149 | wxSprintf(buf, _T("Tabular first argument \"%s\" too complex!"), value); | |
9a29912f JS |
150 | OnError(buf); |
151 | delete[] buf; | |
152 | return FALSE; | |
153 | } | |
154 | } | |
155 | if (isBorder) | |
156 | TableData[noColumns-1].rightBorder = TRUE; | |
157 | return TRUE; | |
158 | } |