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