]> git.saurik.com Git - wxWidgets.git/blob - utils/tex2rtf/src/table.cpp
Removed rules for copying the Mac resource file since they are no
[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: Wlodzimiez ABX Skiba 2003/2004 Unicode support
6 // Ron Lee
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
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(wxChar *value)
62 {
63 noColumns = 0;
64 int i = 0;
65 int len = wxStrlen(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 wxChar 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] = (wxChar)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 wxChar *buf = new wxChar[wxStrlen(value) + 80];
150 wxSnprintf(buf, wxStrlen(value) + 80, _T("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 }