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