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