]> git.saurik.com Git - wxWidgets.git/blob - utils/tex2rtf/src/table.cpp
2.4 -> 2.5; build in another directory than source one; mention --disable-shared
[wxWidgets.git] / utils / tex2rtf / src / table.cpp
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
24 #include "wx/wx.h"
25 #endif
26
27 #include "wx/hash.h"
28
29 #ifdef new
30 #undef new
31 #endif
32
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];
46 bool inTabular = FALSE;
47
48 bool startRows = FALSE;
49 bool tableVerticalLineLeft = FALSE;
50 bool tableVerticalLineRight = FALSE;
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
61 bool ParseTableArgument(char *value)
62 {
63 noColumns = 0;
64 int i = 0;
65 int len = strlen(value);
66 bool isBorder = FALSE;
67 while (i < len)
68 {
69 int ch = value[i];
70 if (ch == '|')
71 {
72 i ++;
73 isBorder = TRUE;
74 }
75 else if (ch == 'l')
76 {
77 TableData[noColumns].leftBorder = isBorder;
78 TableData[noColumns].rightBorder = FALSE;
79 TableData[noColumns].justification = 'l';
80 TableData[noColumns].width = 2000; // Estimate
81 TableData[noColumns].absWidth = FALSE;
82 // TableData[noColumns].spacing = ??
83 noColumns ++;
84 i ++;
85 isBorder = FALSE;
86 }
87 else if (ch == 'c')
88 {
89 TableData[noColumns].leftBorder = isBorder;
90 TableData[noColumns].rightBorder = FALSE;
91 TableData[noColumns].justification = 'c';
92 TableData[noColumns].width = defaultTableColumnWidth; // Estimate
93 TableData[noColumns].absWidth = FALSE;
94 // TableData[noColumns].spacing = ??
95 noColumns ++;
96 i ++;
97 isBorder = FALSE;
98 }
99 else if (ch == 'r')
100 {
101 TableData[noColumns].leftBorder = isBorder;
102 TableData[noColumns].rightBorder = FALSE;
103 TableData[noColumns].justification = 'r';
104 TableData[noColumns].width = 2000; // Estimate
105 TableData[noColumns].absWidth = FALSE;
106 // TableData[noColumns].spacing = ??
107 noColumns ++;
108 i ++;
109 isBorder = FALSE;
110 }
111 else if (ch == 'p')
112 {
113 i ++;
114 int j = 0;
115 char numberBuf[50];
116 ch = value[i];
117 if (ch == '{')
118 {
119 i++;
120 ch = value[i];
121 }
122
123 while ((i < len) && (isdigit(ch) || ch == '.'))
124 {
125 numberBuf[j] = ch;
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++;
137
138 TableData[noColumns].leftBorder = isBorder;
139 TableData[noColumns].rightBorder = FALSE;
140 TableData[noColumns].justification = 'l';
141 TableData[noColumns].width = 20*ParseUnitArgument(numberBuf);
142 TableData[noColumns].absWidth = TRUE;
143 // TableData[noColumns].spacing = ??
144 noColumns ++;
145 isBorder = FALSE;
146 }
147 else
148 {
149 char *buf = new char[strlen(value) + 80];
150 sprintf(buf, "Tabular first argument \"%s\" too complex!", value);
151 OnError(buf);
152 delete[] buf;
153 return FALSE;
154 }
155 }
156 if (isBorder)
157 TableData[noColumns-1].rightBorder = TRUE;
158 return TRUE;
159 }