Chapter5.Tioga
Last edited by Rick Beach, May 4, 1985 10:32:20 am PDT
5
A New Framework for
Tabular Composition
5 A NEW FRAMEWORK FOR TABULAR COMPOSITION
====================
5.1 The Interactive Table Formatting Problem
This chapter presents a new framework for formatting tables that is suitable for use in interactive editors and formatters. The framework extends the object-oriented approach of the document structure model in Chapter 3 by providing for the arrangement of objects into two-dimensional tables. The framework incorporates a wide range of typographic requirements for typesetting tables through extensions to the document style mechanism. Table layout is specified through grid designs similar to page layout grids familiar in the graphic arts. A mathematical linear inequality constraint solver is used to determine the final placement of table entries. A central idea in this approach is the separation of specifying the arrangement of table entries from computing their positions. Several interesting research problems arise from this framework. Some of those are outlined for future work in Chapter 6.
5.1.1 What do we need to do?
To support interactive table formatting, one needs efficient algorithms for WYSIWYG table display and for direct manipulation of both the table content and structure by pointing at and selecting components of the table. In an electronic document, tables can be represented by extending the idea of separating form from content, in this case by specifying the arrangement of table entries separately from the content for each entry. Table entries can be arbitrary document objects such as text, illustrations, mathematical notations, or other tables. Typographic rules, decorations, and shaded backgrounds may be specified at the boundaries between table boxes. The data structure used here represents these boundaries explicitly, and thus supports all of these capabilities.
Abstractly, tables are two-dimensional rectangular arrangements of information that have both a row and column structure. Manipulating table content may require dealing with either a row or a column at different times. Thus the interactive operations should handle both row and column structures and should make it equally easy to select a row or a column and to perform a movement or editing operation on any selected table part. A selection hierarchy must permit identifying a distinguished table entry, a containing row or column of that table entry, a succession of enclosing rows or columns around the current selection, and ultimately the entire table. Operations on the selection hierarchy should work equally as well for groups of rows as for groups of columns. In particular, transposing the rows and columns of a table should be easy to accomplish with the table structure.
Style attributes for tables should be provided in a manner analogous to the way attributes were provided for illustrations in Chapter 3. The additional structure in tables poses some difficulties. Style attributes may be applied at several levels in a table. For instance, a typeface attribute might apply to the entire table, a single row within the table, a single column, a group of spanned rows or columns, or only to an individual table entry. A method is needed to determine the style attributes that apply to each table entry as it is formatted.
The table layout mechanism needs to handle not only general arrangements of rows and columns but also to specify the many alignments possible within a table design. Spanning a column heading across several columns is a special case of the general problem of aligning one set of entries with another set of entries. A robust framework for table formatting must be capable of expressing those arrangements and of determining the positions of the table boxes in such an arrangement.
A generalization of the table formatting problem permits overlapping layers of information. Background tints, such as the colored tints used in tables published in recent issues of the Communications of the ACM, form one class of overlapped information. This class of 2-1/2 dimensional overlapping can be handled without adding another dimension to the table arrangement algorithms.
5.1.2 How are we going to do it?
The framework for formatting tables that is proposed here has three parts: extensions to the document structure model, two-dimensional grid layout specifications (topology), and a layout constraint satisfaction algorithm (geometry).
The document structure and style machinery for tables is an extension of the model used in Chapter 3. Each table entry is a document object. Recall that a document object formats itself and is represented by a set of dimensions and two procedures, one for laying out the object and one for rendering the object. For tables, additional style attributes must be created for the new typographic features that appear only in tables, such as rule thicknesses and colors, alignments, and bearoff distances (the whitespace between table entries and grid lines). The tabular style attributes for a particular table entry may be collected into formatting style rules which are then attached as properties to the table entries. Since a table does not have the same simple hierarchy as the current tree-structured document model used in Tioga and extended for illustrations in Chapter 3, a more elaborate binding algorithm is needed to associate tabular style attributes with each entry.
The table arrangement, or table topology, is expressed using a grid design. The table layout, or table geometry, is computed from both the table topology and the dimensions of the table entries. A linear inequality constraint solver is used as a general mechanism for computing the table geometry.
Before discussing the table formatting system that has been implemented, it is appropriate to digress and look at some general strategies for two-dimensional layout problems. We would like to know how hard the problem of laying out tables is before tackling the solution. The general problem will be seen to be too difficult to solve in an interactive environment. Simplifying and restricting these problems leads to more realistic table formatting problems that can be handled interactively.
5.2 The Complexity of Table Formatting
Before discussing a framework for formatting tables, we examine some theoretical aspects of the problem to gain a perspective on its complexity. The problem of producing an optimal table layout seems intractable in its most general setting. The problem becomes tractable when sufficient structure is added to the table arrangement. If a set of unordered table entries is to be arranged into minimum space, the problem is NP-complete. When only an approximation to the optimal size is needed (and the table can be formatted in horizontal slices) the problem is O(nlogn) where n is the number of table entries. When a total grid structure is imposed (entirely constraining the order in which entries are arranged into rows and columns) the table formatting problem becomes linear in the number of entries.
The general table formatting problem belongs to a class of two-dimensional packing problems first analyzed by Baker et al. [Baker, Packings]. The next subsection analyzes two versions of the table formatting problem that are NP-complete. We then look at restricted forms of the general problem which have simpler solutions. The simplest of these, GRID PACK, is then used as the basis for table formatting by grid structures, the main topic of this chapter.
5.2.1 RANDOM PACK
One type of table that occurs in practice is a completely unstructured collection of entries. A table containing a collection of photographs illustrating several aspects of a topic, in which the precise order of the photographs is unspecified, might require a formatting system to arrange the pictures to occupy the minimal space on a page. This can be formalized as RANDOM PACK, the problem of laying out an unordered set of rectangular table entries T = {ti} with entry ti having height hý(ti) and width wý(ti), so that the resulting table is bounded by the page width and has a minimum depth (to be more precise, the RANDOM PACK problem asks whether the table can be laid out to fit on a page of depth k). In laying out the table, whitespace may be left within the table boundary where entries do not abut exactly.
THEOREM 1. RANDOM PACK is NP-complete.
Proof. The proof follows from a reduction of the PARTITION problem, known to be NP-complete [Garey&Johnson, NP], to RANDOM PACK. Consider a table of rectangular entries, each with widths exactly one-half the page width but with arbitrary heights that sum to 2k. The best possible table arrangement would be two columns of exactly the same height (in this case k). This arrangement requires partitioning the entries into two subsets whose total height (the sum of the heights of its entries) is k. Thus, we are given a set of entries, T = {ti} with heights hý(ti) such that S hý(ti) = 2k, and we wish to find two subsets of T, S and S` = TS, such that S hý(si) = S hý(s`j) = k. This is precisely the PARTITION problem. There, we are given a set of integers and are asked to partition them into two disjoint sets whose sum is the same. Given any instance of the PARTITION problem, we construct an instance of RANDOM PACK by specifying a set of rectangular table entries of width one-half the page and heights equal to the integers in the set to be partitioned. The original PARTITION problem has a solution if and only if the constructed RANDOM PACK table entries can be laid out with equally balanced column depths. This completes the reduction and the proof. ®
In fact, we can say more than this. Theorem 1 shows only that RANDOM PACK (and thus the general table layout problem) is NP-complete and hence almost certainly intractable. The PARTITION problem is known to have a dynamic programming algorithm that is polynomial time in the size of the set if there is a bound on the magnitude of the integers (the coefficients in the polynomial may be exponential in this magnitude) [Garey&Johnson, NP, page 90]. In formatting tables, the table entries are bounded by the page size, and thus the PARTITION problems that would be produced by the reduction in Theorem 1 would all have polynomial time algorithms. If the BIN PACKING problem is used instead of PARTITION we can in fact show that the table formatting problem is even more difficult than indicated by the the result of Theorem 1. BIN PACKING [Garey&Johnson, NP] is a problem which has no polynomial time algorithm unless P=NP, regardless of the magnitude of the numbers used in describing the problem (it is in the class of strongly NP-complete problems).
THEOREM 2. RANDOM PACK is strongly NP-complete.
Proof. We again perform a reduction from a problem known to be difficult. Consider a table of rectangular entries with integer widths less than the page width but with uniform heights. The table layout algorithm must minimize the number of rows required for the table in order to optimize space. This requires partitioning a set of table entries T={ti} having widths wý(ti) into k rows R1, R2, ..., Rk. This partitioning is an instance of the BIN PACKING problem, known to be strongly NP-complete. The proof follows that for Theorem 1. ®
We realize that RANDOM PACK does not produce very interesting or aesthetically pleasing tables. Few tables contain unordered entries (although the example given before, a collection of related but unordered photographs, is such a table). Even when a table is an unordered set of entries, the mix and match jumble produced by RANDOM PACK is not typical of the row and column structure usually employed for such tables. The juxtaposition of different sizes and shapes for the various entries does not lend itself to a readable table. An aesthetically pleasing table exhibits a design discipline for organizing the table entries that avoids unexpected relationships due to the random positioning of table entries. We are thus led from this general problem to introduce restrictions that make the problem more realistic and also more tractable for formatting, especially for interactive work.
5.2.2 STUB PACK
There are two approaches to dealing with the general table formatting problem: accept an approximate solution to the optimal table layout or restrict the table formatting problem so that efficient optimal algorithms exist. Approximation algorithms for the TWO-DIMENSIONAL BIN PACKING problem, and hence for the RANDOM PACK problem, are known [Coffman, 2D Packing]. These approximations use polynomial time algorithms to produce layouts within 5/4 of the optimal space [Baker, 5/4 Algorithm]. The Up-Down (UD) algorithm presented by Baker et al. is known to have a bound UD(L) on the packing height for any list L of rectangles with height at most H as follows:
UD(L) d 5/4ýOPT(L) + 53/8ýH,
where OPT(L) is the height of the optimal packing of the list L of rectangles (as would be produced by RANDOM PACK).
However, the table layouts produced by these algorithms are still unaesthetic, with a chaotic arrangement of small entries among the crevices between larger ones, as shown in the example layout of Figure 5-1 adapted from Figure 2 in Baker et al. [Baker, Packings].
====================
///Beach/Thesis/Figure5-1-OptimalLayout.Press
leftMargin: 173 pt, topMargin: 147 pt, width: 153 pt, height: 188 pt
Figure 5-1. AN APPROXIMATELY OPTIMAL LAYOUT produced by the Up-Down packing algorithm due to Baker et al. [Baker, Packings]. The example is similar to Figure 2 in their paper. The light grey, medium grey, and dark grey boxes were packed with three different strategies.
====================
Restricting the table arrangement leads to more aesthetic table layouts and to algorithms with polynomial running time. Introducing a row structure to the table by placing horizontal rules between the rows is the first restriction we consider. Once a rule is introduced into the table, it must extend all the way to the right of the table. These rules form the stub of the table (typical of financial tables) and hence this restricted table formatting problem will be called STUB PACK. Figure 5-2 contains an example of a STUB PACK table layout.
====================
///Beach/Thesis/Figure5-2-StubPackLayout.Press
leftMargin: 151 pt, topMargin: 141 pt, width: 153 pt, height: 194 pt
Figure 5-2. A HYPOTHETICAL STUB PACK table layout with the largest elements at the bottom left and the smaller elements packed from left to right.
====================
STUB PACK can be formalized as a set of unordered table entries T = {ti} with height hý(ti) and width wý(ti) that are to be placed into an arrangement bounded by the page width and having minimum depth. Each entry in the final layout is separated from the entry below it by a line (typographic rule) that defines a row of the table.
A polynomial time algorithm exists to solve the STUB PACK problem within 1.7 of the optimal space [Coffman, 2D Packing, Theorem 2]. The First-Fit Decreasing-Height (FFDH) algorithm described by Coffman et al. is shown to have a bound on the packing height of
FFDH(L) d 1.7ýOPT(L) + 1.
The FFDH algorithm takes a list L of rectangles with arbitrary widths ordered by nonincreasing height and places each rectangle left-justified on the first level in which it will fit, or if none of the levels will accommodate the rectangle, a new level is begun. The FFDH algorithm requires O(n2) time for n rectangles in the list. A linear post-processing pass may be added to improve the aesthetics of the table by distributing the excess whitespace within a row and around each entry.
While STUB PACK has a polynomial time algorithm, it still does not lay out the ordered tables normally encountered in practice. The row and column grid structure that occurs in tables imposes an ordering of table entries specified by the table designer, who has taken into account a number of aesthetic considerations. Restricting tables to be ordered in advance by the designer reduces the complexity of the table formatting problem (at the expense of possibly requiring greater space). An algorithm which performs table layout given the arrangement is what we need to achieve the aesthetics we desire.
5.2.3 GRID PACK
The GRID PACK problem is to lay out a given set of table entries, each with a width and a height, where all of the entries are assigned to lie between particular row and column grid coordinates within the table. The layout is entirely determined once the physical (page) coordinates of the grid lines are known. These are determined by the width and height of the entries.
THEOREM 3: GRID PACK requires linear time.
Proof: The requirement is to determine the position of the grid lines. This can be done by a two pass algorithm that examines all of the table entries in turn. The first pass determines the relative width and depth of each row and column (horizontal and vertical pairs of grid lines) by ensuring that the relative width of the column is greater than the width of any entry in that column and that the relative depth of the row is greater than the height of any entry in that row. The absolute page coordinates of the row and column grid lines are then determined by accumulating relative widths and depths for consecutive grid lines. The second pass over the entries determines the page coordinates of each entry from the row and column grid coordinates. ®
The GRID PACK algorithm is similar to the one used by the tbl table formatter. Additional alignment possibilities may be incorporated into the GRID PACK problem through suitable extensions. As stated here, it does not handle spanned column headings or aligning table entries on decimal points. The remainder of this chapter will discuss the practical issues of table formatting, including a document structure and grid system for representing table layouts and an interactive algorithm for formatting these tables.
5.3 Table Document Structure
The document structure outlined in Chapter 3 for including graphical illustrations in documents is a tree-structured hierarchy of document objects. The same object-oriented strategy can be used to extend the document structure to represent tables by adding another class of document content objects. The recursive document structure still pertains, and text documents may contain tables that in turn contain text, illustrations, other tables, or any other document object that has been defined. Unlike the pipelined structure of troff preprocessors, this recursive structure implies no ordering or ranking among the document object classes, and the recursion can start with any object. This permits a general and extensible treatment of information presented within documents, illustrations, and tables. An example of a table with varied content is shown in Figure 5-3.
5.3.1 Table Entry Representation
For formatting purposes, a table object in the extensible document structure can be thought of as a box and two procedures for laying out and rendering its content. The box concept is similar to the boxes used in eqn and TEX but with additional information required for alignment of table entries. The procedure concept is similar to the artist procedures used to render data structures graphically [Myers, Incense] or animate graphical objects [Kahn&Hewitt, Actors].
A table entry is abstractly represented by a box with four offsets (left, right, up, and down) from an origin implied by the content. This origin is the starting point for the rendering procedure that displays the content of the table entry. Four offsets, rather than simply a width and a height, permit alignment in both the horizontal and vertical directions simultaneously. Other schemes like eqn and TEX that represent boxes with fewer parameters provide less-functional alignment primitives. To align the table entry with other entries an alignment point is computed within the box depending on the typographic alignment style, as shown in Figure 5-4.
====================
Grid 5 Rows 3 Columns ByRowThenColumn RowConstraints
RowConstraint 2*gy1 - 1*gy2 - 1*gy0 = 0
RowConstraint 2*gy2 - 1*gy3 - 1*gy1 = 0
RowConstraint 2*gy3 - 1*gy4 - 1*gy2 = 0
RowConstraint 2*gy4 - 1*gy5 - 1*gy3 = 0
Rule (0,0) (0,2) 2 bp
Rule (0,0) (2,0) 2 bp
Rule (0,2) (1,2) 2 bp
Rule (1,1) (1,3) 2 bp
Rule (1,1) (2,1) 2 bp
Rule (1,3) (3,3) 2 bp
Rule (2,0) (2,2) 2 bp
Rule (2,0) (4,0) 2 bp
Rule (2,2) (3,2) 2 bp
Rule (3,1) (3,3) 2 bp
Rule (3,1) (4,1) 2 bp
Rule (3,3) (5,3) 2 bp
Rule (4,0) (4,1) 2 bp
Rule (4,1) (5,1) 2 bp
Rule (5,1) (5,3) 2 bp
Box (0,0) (2,1) FlushTop Center 12.0 bp 12.0 bp 12.0 bp 12.0 bp
///Beach/Thesis/Figure5-3-ChesterRotated.AIS
width: 2 in
Box (1,2) (3,3) FlushTop Center 12.0 bp 12.0 bp 12.0 bp 12.0 bp
///Beach/Thesis/Figure5-3-PressFile.Press
leftMargin: 228 pt, topMargin: 172 pt, width: 123 pt, height: 145 pt
Box (2,0) (4,1) FlushTop Center 12.0 bp 12.0 bp 12.0 bp 12.0 bp
///Beach/Thesis/Figure5-3-GriffinRose.Press
leftMargin: 195 pt, topMargin: 143 pt, width: 102 pt, height: 130 pt
Box (3,2) (5,3) FlushTop Center 12.0 bp 12.0 bp 12.0 bp 12.0 bp
///Beach/Thesis/Figure5-3-RecursiveTable.Press
leftMargin: 121 pt, topMargin: 94 pt, width: 157 pt, height: 46 pt
Box (0,1) (1,2) FlushTop FlushRight 12.0 bp 12.0 bp 12.0 bp 12.0 bp
Chester
Carlson
Box (1,1) (2,2) FlushTop FlushLeft 12.0 bp 12.0 bp 12.0 bp 12.0 bp
Formatted
Document
Box (2,1) (3,2) FlushTop FlushRight 12.0 bp 12.0 bp 12.0 bp 12.0 bp
Griffin
Rose
Box (3,1) (4,2) FlushTop FlushLeft 12.0 bp 12.0 bp 12.0 bp 12.0 bp
Table
Figure 5-3. A WIDE RANGE OF CONTENT can be incorporated within tables using an object-oriented document structure. This table includes five different kinds of content: text, a scanned illustration, a synthetic computer generated drawing, composed pages, and another table. The text captions in the center column are positioned flush at the top of each row and alternate flush right and left. The picture of Chester Carlson, the inventor of xerography, was scanned from an original photograph and is 367 scan lines by 474 pixels with each pixel containing an 8-bit grey value. The formatted document is the output of other software that produces a compatible printer format used at Xerox PARC. The synthetic graphic image was created by Maureen Stone with the Griffin illustrator. Both the table and the subtable were composed using the table formatting prototype described in this chapter.
====================
====================
///Beach/Thesis/Figure5-4-TableBox.Press
leftMargin: 139 pt, topMargin: 127 pt, width: 279 pt, height: 67 pt
Figure 5-4. A TABLE ENTRY BOX is represented by four offsets that are the left, right, up, and down distances from an alignment point. These offsets are computed from the dimensions of the box and the typographic alignment attributes, in this example, centered both horizontally and vertically.
====================
The layout procedure is given the arrangement and content of the table entries and determines their sizes and positions. A table's arrangement is explicitly determined by its creator when the table entries are collected in the document. This is analogous to the ordering of paragraphs in a document as it is created by an author.
The rendering procedure is given the positions of the table entries, as computed by the layout procedure, and produces the human-readable form of the table by recursively rendering the content of the table entries at each position. The rendering procedure relies on a device-independent graphics package that can produce a screen display or a file-based printer description of the table. This device-independent capability permits WYSIWYG interaction with table objects in their actual positions, subject to differences in device resolution. The separation of the layout and rendering steps permits the rapid redisplay of the table without recomputing the layout when the view of a table is moved or scrolled.
5.3.2 Table Arrangement
The document structure extensions for tables must capture the arrangement of the table entries as well as their content. Tables are two-dimensional, and in this respect are similar to mathematical notation in the microscopic sense, and to page layout in the macroscopic sense. However, tables are significantly unlike paragraphs of text, wherein text flows from one line to the next and there are few positioning relationships between text elements. It is precisely the positioning and alignment relationships between table entries that must be included in the table document model.
One might begin with the obvious row and column structure of the table. Many document formatting systems have chosen one of these as the dominant structure and expressed the table arrangement in terms of it, leaving the other structure implicit. For example, rows are the dominant structural element for tables in tbl. This choice appears natural since all the column entries of a row can be entered on the same input line, and the UNIX philosophy treats streams of characters as the unifying data structure.
This row dominance makes column operations more difficult. Adding a new row is simple; one adds a new input line to the source file. Adding a new column is tedious; each input line must have a new column entry inserted in the appropriate place, although special editors could help here. Another asymmetry between rows and columns in tbl concerns how one specifies spanned headings. A spanned column heading must be specified as a sequence of s layout codes for each column spanned, whereas a spanned row heading may be specified either by a ^ layout code for each row spanned or by a special formatting code \^ as the table entry content for each spanned row entry. The treatment of rows and columns in interactive table formatting should be symmetric to reduce the cognitive burden and to avoid errors.
A hierarchical structure suggests itself from the subdivision of rows and columns in tables. Figure 5-5 illustrates a table with its row and column subdivisions and the hierarchical data structure based on the columns. A column heading that spans several entries becomes a subtree root for those columns. Multiway branches are for spanned headings, single branches are for table entries. A dual hierarchy would be expected for the row structure. Such a dual hierarchical scheme was unsuccessfully attempted in a previous table formatting prototype [Beach, CS740 project]. The implementation was complex and the data structures were difficult to coordinate. Many of the algorithms had to be duplicated for the row and column cases. The crucial realization was that not all table designs can be represented as hierarchical tree structures. In particular, the table in Figure 5-5 does not have a hierarchical row structure because heading D has two row parents, C and G. A more general underlying structure is required. This is the topic of the next subsection.
When they exist, the dual row and column hierarchies do provide powerful interactive selections of parts of tables. This selection hierarchy notion is similar to a text selection hierarchy which enables one to select a character and extend the selection through various levels of structure from a character to a word, sentence, paragraph, section, and ultimately the entire document. Starting from a selected table entry, one can extend the selection to include all entries in the containing row or column by traversing either the row or column hierarchy. Successive extensions of the selection would include containing rows or columns until the entire table is selected. While a hierarchical table representation was
====================
Grid 1 Rows 2 Columns ByRowThenColumn
Box (0,0) (1,1) Center Center 0.0 bp 6.0 bp 0.0 bp 0.0 bp
///Beach/Thesis/Figure5-5-HierarchicalTable.Press
leftMargin: 102 pt, topMargin: 95 pt, width: 217 pt, height: 54 pt
Box (0,1) (1,2) Center Center 6.0 bp 0.0 bp 0.0 bp 0.0 bp
///Beach/Thesis/Figure5-5-TableHierarchy.Press
leftMargin: 208 pt, topMargin: 156 pt, width: 102 pt, height: 82 pt
Figure 5-5. HIERARCHICAL TABLES contain rows and columns that subdivide into other rows and columns like parent and children nodes in a tree. The column structure of the table on the left is shown in the graph on the right. All the table entries are labelled to show the correspondence. Note that this particular table does not have a row hierarchy because entry D has two row parents, C and G.
====================
not used in table formatting prototype, the selection hierarchy serves as a good model for manipulating tables and was implemented for the grid representation described next.
5.3.3 Grid Structure
A more general representation of table arrangements must simultaneously satisfy several goals: it must exist within a hierarchical document model, it must embed arbitrary table entry objects, and it must describe the arrangement and positioning relationships of the table entries. The hierarchical document model cannot be used directly because tables are not always hierarchical, for example, the box head in Figure 5-5 is nonhierarchical. The insight applied here is that one need provide the data structure for tables explicitly in the document model. Instead, the table arrangement can be described indirectly in terms of a grid coordinate system with table entries having associated grid coordinates. This permits a table object to be represented by a collection of arbitrary table entry objects and the table arrangement to be specified by the grid labelling. The entries may be listed in any order since the labelling will determine the table layout.
The proposed grid coordinate scheme expresses the table topology. This in turn determines the arrangement of table entries between the grid lines, and thus determines which table entries are neighbors and which entries share the same boundaries. Grid modules between grid lines may be nonuniformly spaced to permit both narrow and wide entries. Each table entry is surrounded by four grid lines, one each on its left, right, top and bottom sides. A row is bounded by two horizontal grid lines, and a column by two vertical grid lines in a symmetric fashion. Entries in the same row will share the same pair of horizontal grid lines, similarly for entries in the same column. A spanned column heading will cross several grid lines and is bounded by the left grid line of the leftmost spanned entry and by the right grid line of the rightmost spanned entry. An arbitrarily complex arrangement of table entries can be specified by listing the four grid lines for each table entry. Figure 5-6 contains a table with the grid coordinate system overlaid as light grey lines.
====================
Grid 5 Rows 5 Columns ByRowThenColumn GridOverlay 3 bp 0 0 0.7 ColConstraints
ColConstraint 2*gx2 - 1*gx1 - 1*gx3 = 0
ColConstraint 2*gx1 - 1*gx0 - 1*gx3 = 0
Rule (0,1) (5,1) 1 bp
Box (0,1) (1,5) TopBaseline Center 3.0 bp 3.0 bp 6.0 bp 6.0 bp
Spanned over Four Columns
Box (1,1) (2,3) TopBaseline Center 3.0 bp 3.0 bp 6.0 bp 6.0 bp
Equal Width
Box (1,3) (2,5) TopBaseline Center 3.0 bp 3.0 bp 6.0 bp 6.0 bp
Unequal Width
Box (2,1) (3,2) TopBaseline Center 3.0 bp 3.0 bp 6.0 bp 6.0 bp
Very Wide
Box (2,2) (3,3) TopBaseline Center 3.0 bp 3.0 bp 6.0 bp 6.0 bp
Thin
Box (2,3) (3,4) TopBaseline Center 3.0 bp 3.0 bp 6.0 bp 6.0 bp
Very Wide
Box (2,4) (3,5) TopBaseline Center 3.0 bp 3.0 bp 6.0 bp 6.0 bp
Thin
Rule (3,0) (3,5) 1 bp
Box (3,0) (4,1) TopBaseline FlushLeft 3.0 bp 3.0 bp 6.0 bp 6.0 bp
First Row
Box (3,1) (4,2) TopBaseline Center 3.0 bp 3.0 bp 6.0 bp 6.0 bp
xxxxxxxxx
Box (3,2) (4,3) TopBaseline Center 3.0 bp 3.0 bp 6.0 bp 6.0 bp
xxx
Box (3,3) (4,4) TopBaseline Center 3.0 bp 3.0 bp 6.0 bp 6.0 bp
xxxxxxxxx
Box (3,4) (4,5) TopBaseline Center 3.0 bp 3.0 bp 6.0 bp 6.0 bp
xxx
Box (4,0) (5,1) TopBaseline FlushLeft 3.0 bp 3.0 bp 6.0 bp 6.0 bp
Second Row
Box (4,1) (5,2) TopBaseline Center 3.0 bp 3.0 bp 6.0 bp 6.0 bp
xxxxxxxxx
Box (4,2) (5,3) TopBaseline Center 3.0 bp 3.0 bp 6.0 bp 6.0 bp
xxx
Box (4,3) (5,4) TopBaseline Center 3.0 bp 3.0 bp 6.0 bp 6.0 bp
xxxxxxxxx
Box (4,4) (5,5) TopBaseline Center 3.0 bp 3.0 bp 6.0 bp 6.0 bp
xxx
Figure 5-6. TABLE WITH GRID COORDINATE SYSTEM in which the grid lines are overlaid in light grey. Some table entries are contained within a single grid module while others span across several grid modules. The two black typographic rules, one horizontal below the column headings and one vertical after the row stub, run along the grid boundaries.
====================
Typographic rules and decorations can be superimposed on the grid boundaries. In this case, the grid boundary has a nonzero width equal to the thickest rule that runs along that grid line. Note that both horizontal and vertical rules are treated symmetrically.
The table layout geometry, that is, the actual position of each grid boundary and each table entry, is computed from both the table topology and the dimensions of the table entry contents. A mathematical linear inequality constraint solver permits general alignment relationships to be expressed, such as the equal column widths shown in Figure 5-6. The independent variables in the inequality constraints are the positions of the grid lines and the alignment points of table entries. An incremental constraint solver that can accept new or changed constraints permits interactive modification of the table arrangement.
5.3.4 Graphic Arts References to Grid Systems
Similar grids have been used in the graphic arts since grid systems were first developed by designers in Switzerland shortly after World War II. The principle behind a grid system is an objective attitude to the presentation of the subject material and to the uniformity in the layout of all pages. Grids institute a disciplined approach to design and layout, limiting the number of choices to provide regularity and order in potentially chaotic situations.
``The fewer the differences in the size of the illustrations, the quieter the impression created by the design.'' [Muller-Brockman, Grid Systems, p11]
Several graphic designers have written about grid systems in books including Muller-Brockman's Grid Systems in Graphic Design [Muller-Brockman, Grid Systems], Hurlburt's The Grid [Hurlburt, The Grid], and Williamson's Methods of Book Design [Williamson, Book Design]. Some computer composition systems have incorporated grid systems. One early example was Tilbrook's NEWSWHOLE [Tilbrook], a prototype system for interactive newspaper page layout. Hurlburt [Hurlburt, The Grid] describes the modular design and sense of proportion induced by a grid design. Several proportions, such as the Golden Ratio, square, and 2 rectangle, are commonly used as the basis for grid designs. Letter form design is also often constructed to conform to a grid design [Goines, Constructed Alphabet].
Unlike the orthodox grid formed by uniformly spaced horizontal and vertical lines to produce square modules, the typographic grid is more casual with lines introduced to specify margins on the page, column measures, and alignment guides. Common grid lines are the headline, the first line of text on a page, the first line of a chapter title, the first line of text within a chapter, the last text line on a page, and the footline. Figure 5-7 shows the grid design for the pages of this thesis.
====================
///Beach/Thesis/Figure5-7-GridDesign.Press
leftMargin: 214 pt, topMargin: 142 pt, width: 126 pt, height: 200 pt
Figure 5-7. GRID DESIGN for the pages of this thesis illustrates the traditional use of grid boundary lines to determine margins, column measures, gutter widths, alignment points, etc. The grid combines both a single column format (the large grey rectangle) for text pages and a double column format (the two dark grey rectangles) for glossary and index pages.
====================
The interactive newspaper pagination system NEWSWHOLE [Tilbrook] is an example of the application of grid systems for layout and formatting. The grid lines in that system were active; they could be stretched and moved across the page at the user's command. There was a simple constraint satisfaction to ensure that there were always an integral number of grids across the section of the page and that the grids were equal width. The NEWSWHOLE prototype had only limited text composition capabilities, and it did not attempt a WYSIWYG presentation of the entire page (mainly due to display resolution, which will always be a problem). The same idea can be used here to do interactive tabular composition and is discussed in Chapter 6.
5.3.5 Style Attributes for Tables
The document style mechanism must also be extended to incorporate additional table formatting attributes and to apply those attributes to table entries. The additional tabular style attributes include various alignment specifications (decimal or character alignment, top or bottom baseline alignment, centered top or bottom baseline alignment), various rule parameters (rule thickness and color), and various bearoff distances (the whitespace between table entries and the grid lines).
Applying style attributes to table entries is harder than for text or illustrations because the attributes may come from several nonhierarchical sources. Figure 5-8 illustrates some of the possible interactions among style attributes applied to parts of a table. The whole table may have a general formatting style. Rows or columns may have particular style rules for the entries within those rows or columns. Each table entry may have additional local formatting attributes applied that override the other specifications.
Because tables have both a row and a column structure that in turn has nested subrows and subcolumns, there may be several row or column style rules applicable for a given table entry. The nested containment of a table entry within a row and/or a column can determine an appropriate search path for applying style rules. The rendering algorithm first applies the style attributes specified in the style rule for the entire table. It then applies attributes for each containing row or column that successively contains the table entry, down to the attributes for the given table entry. When style rules do not specify values for all the possible style attributes, values are inherited from previous style rules along the search path. Style rules may be specified for both a row and a column containing the given table entry, in which case it is necessary to disambiguate the row or column preference. The solution taken here is to provide a Boolean
====================
Grid 6 Rows 6 Columns ByRowThenColumn
Rule (0,0) (0,6) 1 bp
Rule (0,0) (6,0) 1 bp
Rule (0,1) (6,1) 1 bp
Rule (0,6) (6,6) 1 bp
Rule (1,1) (1,6) 1 bp
Rule (1,2) (6,2) 1 bp
Rule (1,5) (6,5) 1 bp
Rule (2,2) (2,5) 1 bp
Rule (2,3) (6,3) 1 bp
Rule (2,4) (6,4) 1 bp
Rule (3,0) (3,6) 1 bp
Rule (4,0) (4,6) 1 bp
Rule (5,0) (5,6) 1 bp
Rule (6,0) (6,6) 1 bp
Box (0,0) (3,1) Center Center 3.0 bp 6.0 bp 3.0 bp 3.0 bp
Stub Head
Box (0,1) (1,6) Center Center 3.0 bp 6.0 bp 3.0 bp 3.0 bp
Spanning Column Head
Box (1,2) (2,5) Center Center 3.0 bp 6.0 bp 3.0 bp 3.0 bp
Col Head
Box (1,1) (3,2) Center Center 3.0 bp 6.0 bp 3.0 bp 3.0 bp
Col Head
Box (1,5) (3,6) Center Center 3.0 bp 6.0 bp 3.0 bp 3.0 bp
Col Head
Box (2,2) (3,3) Center Center 3.0 bp 6.0 bp 3.0 bp 3.0 bp
Col
Box (2,3) (3,4) Center Center 3.0 bp 6.0 bp 3.0 bp 3.0 bp
Col
Box (2,4) (3,5) Center Center 3.0 bp 6.0 bp 3.0 bp 3.0 bp
Col
Box (3,0) (4,1) Center FlushLeft 3.0 bp 6.0 bp 3.0 bp 3.0 bp
Row
Box (3,1) (4,2) Center Center 3.0 bp 6.0 bp 3.0 bp 3.0 bp
value
Box (3,2) (4,3) Center Center 3.0 bp 6.0 bp 3.0 bp 3.0 bp
value
Box (3,3) (4,4) Center Center 3.0 bp 6.0 bp 3.0 bp 3.0 bp
value
Box (3,4) (4,5) Center Center 3.0 bp 6.0 bp 3.0 bp 3.0 bp
value
Box (3,5) (4,6) Center Center 3.0 bp 6.0 bp 3.0 bp 3.0 bp
value
Box (4,0) (5,1) Center FlushLeft 3.0 bp 6.0 bp 3.0 bp 3.0 bp
Row
Box (4,1) (5,2) Center Center 3.0 bp 6.0 bp 3.0 bp 3.0 bp
value
Box (4,2) (5,3) Center Center 3.0 bp 6.0 bp 3.0 bp 3.0 bp
value
Box (4,3) (5,4) Center Center 3.0 bp 6.0 bp 3.0 bp 3.0 bp
value
Box (4,4) (5,5) Center Center 3.0 bp 6.0 bp 3.0 bp 3.0 bp
value
Box (4,5) (5,6) Center Center 3.0 bp 6.0 bp 3.0 bp 3.0 bp
value
Box (5,0) (6,1) Center FlushLeft 3.0 bp 6.0 bp 3.0 bp 3.0 bp
Row
Box (5,1) (6,2) Center Center 3.0 bp 6.0 bp 3.0 bp 3.0 bp
value
Box (5,2) (6,3) Center Center 3.0 bp 6.0 bp 3.0 bp 3.0 bp
value
Box (5,3) (6,4) Center Center 3.0 bp 6.0 bp 3.0 bp 3.0 bp
value
Box (5,4) (6,5) Center Center 3.0 bp 6.0 bp 3.0 bp 3.0 bp
value
Box (5,5) (6,6) Center Center 3.0 bp 6.0 bp 3.0 bp 3.0 bp
value
Figure 5-8. STYLE ATTRIBUTES for a table entry are determined by several style rules specified for the entire table, a row, a column or an individual table entry. This table style rule specifies a Helvetica type family. One row has a style attribute for bold face. The spanned column has a style attribute for italic face. One of the three table entries in the intersection of the bold row and italic column has a Times Roman type family attribute, which overrides the global specification. The style attributes for a particular entry are determined by accumulating all the style attributes according to a natural search order: table, row or column (according to a preference choice), then table entry.
====================
selector as a property of the table to choose between row-before-column or column-before-row preferences.
Alignment relationships between table entries are controlled by the alignment points of the table entry objects. These relationships are generalizations of the mark and lineup alignment specifications for equations in eqn. Formatting style attributes determine the alignment point based on the typographic treatment of the table entry. Centered alignment places the alignment point in the middle of the object box by dividing the sum of the appropriate pair of dimensions by two. Flush left, right, top or bottom alignment places the alignment point at the appropriate edge of the box. Aligning on a character within the table entry sets the alignment point to be the origin (which may be chosen from one of several alignment options) of that particular character. Figure 5-9 illustrates two columns of character-aligned table entries, the first aligned on decimal points (including the implied decimal point at the end of a numerical string), and the second aligned on a multiplication sign.
====================
Grid 3 Rows 2 Columns ByRowThenColumn
Rule (0,0) (0,2) 1 bp
Rule (1,0) (1,2) 1 bp
Rule (2,0) (2,2) 1 bp
Rule (3,0) (3,2) 1 bp
Rule (0,0) (3,0) 1 bp
Rule (0,1) (3,1) 1 bp
Rule (0,2) (3,2) 1 bp
Box (0,0) (1,1) Center FlushRight CharAlign '. 3.0 bp 6.0 bp 3.0 bp 3.0 bp
0
Box (1,0) (2,1) Center FlushRight CharAlign '. 3.0 bp 6.0 bp 3.0 bp 3.0 bp
.625
Box (2,0) (3,1) Center FlushRight CharAlign '. 3.0 bp 6.0 bp 3.0 bp 3.0 bp
1023.5
Box (0,1) (1,2) Center FlushRight CharAlign 'X 3.0 bp 6.0 bp 3.0 bp 3.0 bp
speed time
Box (1,1) (2,2) Center FlushRight CharAlign 'X 3.0 bp 6.0 bp 3.0 bp 3.0 bp
acceleration time
Box (2,1) (3,2) Center FlushRight CharAlign 'X 3.0 bp 6.0 bp 3.0 bp 3.0 bp
force distance
Figure 5-9. ALIGNMENT ON A CHARACTER within a table entry may be based on specific characters within lines of text, such as decimal points (actual or implied) in the first column, and multiplication signs in the second column.
====================
The positioning of odd-sized table entries requires additional information, especially for text entries that are folded into multiple lines or for entries with varying heights like mathematical expressions. The top row in Figure 5-10, which has been horizontally aligned on the center of each table entry, demonstrates the disjointed result when baselines of folded entries do not align across the column. Simple horizontal alignment attributes such as flush top, flush bottom, or center do not take into consideration the internal structure of a table entry. Additional alignment choices are needed to align on the baselines within a text table entry, such as align on the top or bottom baseline. Text entries with an even number of baselines have two middle baselines for centering, thus requiring two choices to center on either the top-middle or bottom-middle baseline. The bottom row of Figure 5-10 demonstrates the range of alignment choices available for aligning baselines within table entries.
====================
Grid 2 Rows 5 Columns ByRowThenColumn
Rule (0,0) (0,5) 1 bp
Rule (0,0) (2,0) 1 bp
Rule (0,1) (2,1) 1 bp
Rule (0,2) (2,2) 1 bp
Rule (0,3) (2,3) 1 bp
Rule (0,4) (2,4) 1 bp
Rule (0,5) (2,5) 1 bp
Rule (1,0) (1,5) 1 bp
Rule (2,0) (2,5) 1 bp
Box (0,0) (1,1) Center Center 3.0 bp 6.0 bp 12.0 bp 0.0 bp
Horizontally
Centered,
Ignore
Baseline
Box (0,1) (1,2) Center Center 3.0 bp 6.0 bp 12.0 bp 0.0 bp
Baseline
Baseline
Box (0,2) (1,3) Center Center 3.0 bp 6.0 bp 12.0 bp 0.0 bp
Baseline
Baseline
Baseline
Box (0,3) (1,4) Center Center 3.0 bp 6.0 bp 12.0 bp 0.0 bp
Baseline
Baseline
Baseline
Baseline
Box (0,4) (1,5) Center Center 3.0 bp 6.0 bp 12.0 bp 0.0 bp
Baseline
Baseline
Baseline
Baseline
Baseline
Box (1,0) (2,1) Center Center 3.0 bp 6.0 bp 12.0 bp 0.0 bp
Horizontally
Centered,
Ignore
Baseline
Box (1,1) (2,2) TopBaseline Center 3.0 bp 6.0 bp 12.0 bp 0.0 bp
Baseline
at Top
Box (1,2) (2,3) BottomBaseline Center 3.0 bp 6.0 bp 12.0 bp 0.0 bp
Bottom
Baseline
Box (1,3) (2,4) CenterOnTopBaseline Center 3.0 bp 6.0 bp 12.0 bp 0.0 bp
Center
Baseline
at Top
of Many
Box (1,4) (2,5) CenterOnBottomBaseline Center 3.0 bp 6.0 bp 12.0 bp 0.0 bp
Center
on Bottom
Baseline
of Many
Figure 5-10. HORIZONTAL ALIGNMENT OF FOLDED TABLE ENTRIES may not produce aesthetic results when the entry has several lines of text. All of the entries in the top row are horizontally aligned without regard to their internal structure and the baselines do not align; all of the entries in the bottom row have been centered on a baseline indicated by the text of the entry.
====================
Establishing the alignment point on baselines within a table entry implies that the document object must understand all these alignment choices. The simpler alignment attributes, such as flush top or bottom, could be computed from the representation of an object and its four offsets (except for decimal or character alignment). Some table entry objects have little similarity to text objects, yet the alignment attributes must apply to all objects in a uniform way. The technique used in the prototype is to extend the representation of a table entry to include an optional list of baseline origins. Should the list be absent, the default baseline is chosen to pass through the origin of the object. Alignment attributes that concern themselves with content, such as decimal alignment, are left as the responsibility of the table entry object. Some objects may choose to ignore text alignment attributes. For example, a scanned illustration object contains no characters, so it could safely ignore those attributes.
Another alignment attribute deals with the excess whitespace in the wide columns in Figure 5-11. In this example, the table entries in each column are aligned on decimal points. The last two columns need further specification: how should the excess whitespace induced by the very long column heading be treated? This additional specification determines how the vertically aligned set of column entries are positioned within the column. The choices are centered, flush left, or flush right. Currently, the table formatting prototype does not support this positioning specification, but a more complete implementation is planned and described in Chapter 6. In tbl, numeric entries that are aligned on decimal points are centered within the column after they are aligned on decimal points; there is no control provided over the distribution of the excess whitespace.
====================
Grid 4 Rows 5 Columns ByRowThenColumn ColConstraints
ColConstraint 2.0*gx4 - 1.0*gx3 - 1.0*gx5 = 0
Rule (0,0) (0,5) 1 bp
Rule (1,0) (1,5) 1 bp
Rule (4,0) (4,5) 1 bp
Rule (0,0) (4,0) 1 bp
Rule (1,1) (4,1) 1 bp
Rule (1,2) (4,2) 1 bp
Rule (0,3) (4,3) 1 bp
Rule (1,4) (4,4) 1 bp
Rule (0,5) (4,5) 1 bp
Box (0,0) (1,3) TopBaseline Center 3.0 bp 6.0 bp 3.0 bp 3.0 bp
Short Head
Box (0,3) (1,5) TopBaseline Center 3.0 bp 6.0 bp 3.0 bp 3.0 bp
Very Long Column Head Over Narrow Entries
Box (1,0) (2,1) TopBaseline Center CharAlign '. 3.0 bp 6.0 bp 3.0 bp 3.0 bp
54.321
Box (1,1) (2,2) TopBaseline Center CharAlign '. 3.0 bp 6.0 bp 3.0 bp 3.0 bp
54.321
Box (1,2) (2,3) TopBaseline Center CharAlign '. 3.0 bp 6.0 bp 3.0 bp 3.0 bp
54.321
Box (1,3) (2,4) TopBaseline Center CharAlign '. 3.0 bp 6.0 bp 3.0 bp 3.0 bp
54.321
Box (1,4) (2,5) TopBaseline Center CharAlign '. 3.0 bp 6.0 bp 3.0 bp 3.0 bp
54.321
Box (2,0) (3,1) TopBaseline Center CharAlign '. 3.0 bp 6.0 bp 3.0 bp 3.0 bp
654.32
Box (2,1) (3,2) TopBaseline Center CharAlign '. 3.0 bp 6.0 bp 3.0 bp 3.0 bp
654.32
Box (2,2) (3,3) TopBaseline Center CharAlign '. 3.0 bp 6.0 bp 3.0 bp 3.0 bp
654.32
Box (2,3) (3,4) TopBaseline Center CharAlign '. 3.0 bp 6.0 bp 3.0 bp 3.0 bp
654.32
Box (2,4) (3,5) TopBaseline Center CharAlign '. 3.0 bp 6.0 bp 3.0 bp 3.0 bp
654.32
Box (3,0) (4,1) TopBaseline Center CharAlign '. 3.0 bp 6.0 bp 3.0 bp 3.0 bp
54.321
Box (3,1) (4,2) TopBaseline Center CharAlign '. 3.0 bp 6.0 bp 3.0 bp 3.0 bp
54.321
Box (3,2) (4,3) TopBaseline Center CharAlign '. 3.0 bp 6.0 bp 3.0 bp 3.0 bp
54.321
Box (3,3) (4,4) TopBaseline Center CharAlign '. 3.0 bp 6.0 bp 3.0 bp 3.0 bp
54.321
Box (3,4) (4,5) TopBaseline Center CharAlign '. 3.0 bp 6.0 bp 3.0 bp 3.0 bp
54.321
Figure 5-11. SPECIFYING POSITION WITHIN A COLUMN as well as aligning table entries may be necessary when there is excess whitespace to disperse among the row or column entries. All the numeric table entries are aligned on decimal points. The last two columns have excess whitespace due to the very long column head; the first set of aligned column entries is positioned flush right within the column and the second is flush left. Similar specifications are necessary for rows also.
====================
5.3.6 Text within Table Entries
Textual table entries may be more complex than just simple phrases or numbers. Some entries may be paragraphs with long lines of text broken into pieces short enough to fit within the column boundaries. Yet the layout algorithm attempts to determine the width of the column boundaries from the widest line in the broken paragraph. Thus the line-breaking algorithm depends on the column width and the column width depends on the width of lines folded by the line-breaking algorithm. How does one exit from this circular dependency?
In existing table formatters, such as tbl, the only technique for dealing with this problem is to require the table designer to supply an explicit column width attribute. In fact, this is an easy way to specify equal-width columns, since no matter what the content of the entry, all such designated column entries are forced to be the specified width. Unfortunately, fixing the column width often results in an unaesthetic table. Short justified lines induce more hyphenation and larger spaces between words, making the entries more difficult to read. Unjustified lines are easier to read but extra whitespace accumulates at the end of lines creating the illusion of unevenly spaced columns.
A better strategy would be for the formatter to accept the line length as only a `hint' for folding the text to approximately that length. The actual bounding box of the composed text could be returned by the object layout procedure or determined by a scan of the formatted object. With the bounding box, a folded table entry can be treated uniformly as any other entry. A feature of this strategy is that a column of folded entries is only as wide as necessary without excess whitespace.
The problem of determining an aesthetically pleasing column width for a column of entries with widely varying widths or for a table that exceeds the page measure is a very hard problem and is not solved here. Some directions for determining optimum column widths for folded table entries and for balancing whitespace are outlined in Chapter 6.
5.4 Implementation of the Tabular Grid Structure
We will need two table representations, one for capturing a table in an external representation of a document and another internal data structure for interactive manipulation. This section describes both representations used in the prototype table formatter that has been implemented in the Cedar programming environment.
5.4.1 External Representation of a Table in a Tioga Document
An external storage representation is normally concerned with compactness and ease of conversion between external and internal representations. However, because the prototype relies on the Tioga document structure, the external representation of a table must be a textual description of the table. This representation is editable by the Tioga text editor. While this is an advantage for testing the prototype, it is expected that an interactive user interface will be built to permit most editing actions without resorting to editing the textual representation directly. We believe, however, that the textual description is useful for debugging, for document interchange, and for possibly fine tuning table structures.
A table is represented as a subtree of nodes in a Tioga document hierarchy. The root node of the table subtree has an ArtworkClass property (described in Chapter 3) of Table to distinguish the subtree as being a table object (as distinct from text or illustrations). This Table property is recognized by the table formatting prototype which interprets the contents of the subtree as a collection of table entries. The table entries themselves may contain an object of any document object class since the object layout and rendering procedures understand the content of the object. This object-oriented design permits arbitrary recursion within document content at any time.
The table representation is converted into the internal data structure whenever a table is edited in a WYSIWYG fashion or formatted. After manipulating the internal data structure (perhaps changing the table topology or the content of some table entries) the internal data structure is converted back into a Tioga document subtree. The new subtree is spliced into the original document to replace the previous table representation.
Only topological information is represented in the table description. Table entries are described by the grid coordinates that they occupy. Typographic rules are described by the grid lines along which they run. The table previously shown as Figure 5-6 has been annotated with grid coordinate values in Figure 5-12. Horizontal and vertical grid lines are each numbered beginning at 0 and incrementing for each successive grid line. A column or row is contained within two grid lines (not necessarily two consecutive grid lines). Thus the column containing the heading ``Spanned over Four Columns'' is contained within vertical grid lines 1 and 5. Two typographic rules are shown along vertical grid line 1 and along horizontal grid line 3. The table in Figure 5-12 will be used both to illustrate the external table representation (in Figure 5-13) and the internal data structure (in Figure 5-15).
====================
///Beach/Thesis/Figure5-12-GridOverlay.Press
leftMargin: 106 pt, topMargin: 151 pt, width: 365 pt, height: 121 pt
Figure 5-12. A TABLE WITH A GRID COORDINATE SYSTEM superimposed. The table is a duplicate of Figure 5-6 that will be used to illustrate the external Tioga document structure in Figure 5-13, and the internal corner stitched data structure in Figure 5-15.
====================
A table is described in general terms by the contents of the root node of its table subtree. In Figure 5-13, the table is formatted on a 6 by 6 grid (for 5 rows and 5 columns). A grid overlay 3-points thick in a light gray color (hue 0, saturation 0, brightness 0.7) is superimposed on the table to make the grid coordinate system visible. (This grid overlay would not appear on printed tables, except for expository purposes, although the grid overlay serves as a useful target for interactively manipulating the grid topology.) The direct descendants of the table root node within the document describe the table structure and table entries in more detail. There are four things to describe: constraints on the grid coordinate layout, boxes containing table entries, typographic rules, and background shaded areas.
Constraints
Constraints are linear inequalities or equalities generated automatically by the table layout procedure. The table in Figure 5-12 has two auxiliary constraints supplied by the table designer to force equal column widths. The first constrains the column between grid lines 1 and 2 to have the same width as the column between 2 and 3. The second constraint forces the column between grid line 0 and 1 to have the same width as the column between 1 and 3 (a column which spans two grid lines). The complete details of the constraint mechanism are deferred until Section 5.5.
====================
Grid 5 Rows 5 Columns GridOverlay 3 pt 0 0 0.7
Constraint 2*C2 - 1*C1 - 1*C3 = 0
Constraint 2*C1 - 1*C0 - 1*C3 = 0
Box (0,1) (1,5) TopBaseline Center
Spanned over Four Columns
Box (1,1) (2,3) TopBaseline Center
Equal Width
Box (1,3) (2,5) TopBaseline Center
Unequal Width
Box (2,1) (3,2) TopBaseline Center
Very Wide
Box (2,2) (3,3) TopBaseline Center
Thin
Box (2,3) (3,4) TopBaseline Center
Very Wide
Box (2,4) (3,5) TopBaseline Center
Thin
Box (3,0) (4,1) TopBaseline FlushLeft
First Row
Box (3,1) (4,2) TopBaseline Center
xxxxxxxxx
Box (3,2) (4,3) TopBaseline Center
xxx
Box (3,3) (4,4) TopBaseline Center
xxxxxxxxx
Box (3,4) (4,5) TopBaseline Center
xxx
Box (4,0) (5,1) TopBaseline FlushLeft
Second Row
Box (4,1) (5,2) TopBaseline Center
xxxxxxxxx
Box (4,2) (5,3) TopBaseline Center
xxx
Box (4,3) (5,4) TopBaseline Center
xxxxxxxxx
Box (4,4) (5,5) TopBaseline Center
xxx
Rule (0,1) (5,1) 1 bp
Rule (3,0) (3,5) 1 bp
Figure 5-13. A TABLE OBJECT IN THE EXTERNAL REPRESENTATION of Figure 5-6. Each line corresponds to a document node with indentation depicting the nesting relationship of content nodes within table entry nodes. The first node is the table subtree root and describes the table in general. Children of the table root describe constraints on table alignment, table entries, typographic rules, and backgrounds. Children of table entries are the content of the table entry.
====================
Table Boxes
Table entry boxes are specified by their top-left and bottom-right grid coordinate pairs. The content of the table entry is specified as the descendant of the table entry node. This descendant node may be any document object.
The first table entry in Figure 5-13 describes the spanned heading. Its coordinates are from (0,1) to (1,5), spanning four grid modules. The alignment attributes are TopBaseline (horizontal alignment) and Center (vertical alignment). The object within this table entry is the text object, descended from the first table entry and shown indented in the figure, containing the phrase ``Spanned over Four Columns''. The next table entry also spans column entries, has the same alignment attributes, and contains the text object ``Equal Width''.
Table entries may appear in the document representation in any order because the coordinate specifications determine where in the table they will appear. The nesting of objects as descendents of their corresponding table entry description is the only requirement for including content within a table representation.
Typographic Rules
Typographic rules run along grid lines and have a certain specified thickness. The two rules in Figure 5-12 are both 1-point thick. One rule runs along vertical grid line 1, through the entire table, and the other rule runs along horizontal grid line 3. Rules may run along portions of a grid line. Thus, a vertical rule under the spanning head to separate the equal and unequal pairs of columns might run from grid coordinate (1,3) to (5,3).
Backgrounds
Background areas are specified by the rectangle they shade and the color of the shading. The rectangle is specified by two pairs of coordinate values just as for table boxes. The color specification could be any recognized color naming scheme, and in the prototype, color is given as hue, saturation, and brightness.
5.4.2 Corner Stitching Data Structure
The internal data structure for representing tables must meet several criteria. It must represent the arrangement of table entries in both the horizontal and vertical directions. It must support row and column selections and a selection hierarchy within containing rows and columns. It must also permit fast algorithms suitable for interactive table editing operations and for conversion to/from an external form.
The data structure chosen for the table formatting prototype was the corner stitching data structure employed by Ousterhout [Ousterhout, Corner Stitching] for his VLSI layout tools. An implementation by Shand [Shand, CornerStitching] which runs in the Cedar environment was modified and extended for the prototype.
The corner stitching data structure tesselates the plane with rectangular tiles. Each tile is connected to its neighbors by four compass-point links and each tile references its associated data. The corner stitching implementation uses special border tiles surrounding the tesselation to simplify the algorithms. Figure 5-14 illustrates a prototypical tile and a fragment of the tesselation showing how several tiles are connected together.
====================
///Beach/Thesis/Figure5-14-CornerStitching.Press
leftMargin: 134 pt, topMargin: 142 pt, width: 328 pt, height: 145 pt
Figure 5-14. CORNER STITCHED DATA STRUCTURE uses tiles that are joined together by four pointers, two at the NorthEast corner going North and East, and two at the SouthWest corner going South and West. The example on the right shows three tiles stitched together surrounded by special border tiles, shown in light grey, that are used to simplify the algorithms.
====================
To use the corner stitching data structure there must be a geometric coordinate system. The table topology specified by the grid structure has no geometric information, only the presence or absence of table entries and their relative positioning. Grid boundaries between table entries must have nonzero width, even in the table topology, since provision must be made for typographic rules. Therefore the corner stitching coordinate system has distinct coordinate values for table entries within the grid lines and for typographic rules along the grid lines. The topology is highlighted in the table prototype by representing table entries as unit squares and grid lines as lines with unit widths. (Some additional separation between grid lines and table entries is provided in the prototype to help distinguish between adjacent tiles. Thus the table grid coordinates are in fact multiplied by four to create corner stitching coordinate values.) The coordinate mapping is indicated in Figure 5-15, which presents the corner stitched data structure for the table in Figure 5-6.
====================
///Beach/Thesis/Figure5-15-TableGrid.Press
leftMargin: 103 pt, topMargin: 115 pt, width: 374 pt, height: 361 pt
Figure 5-15. TABLE MAPPED ONTO A GRID DATA STRUCTURE for the table in Figure 5-6. The medium grey tiles correspond to table boxes and the dark grey tiles to typographic rules. Because of the way corner stitching coordinates are determined, grid modules are unit squares and grid boundaries are lines of unit width or height. The light grey shading represents the border tiles that hold the table entries together in the corner stitched data structure. The two rules intersect and are represented by several fragments, one of which is the intersection of the rules.
====================
The external description of the table is parsed to create the internal data structure. The internal table description is held in a table object record, which remembers the table document subtree. Later, an updated external table description is spliced into the subtree after edits. The table object record also points to the grid tesselation of table entries and there are fields for the grid positions and table origin that will be computed later by the table layout algorithm. The auxiliary constraints provided by the table designer are contained in a linked list.
TableRec: TYPE = RECORD[
branchInDocument: REF DocumentObject, -- document subtree
gridTesselation: REF Tesselation, -- area structure for tiles
numberOfRows, numberOfColumns, INTEGER,
rowGridPositions: ARRAY [0..numberOfRows) OF Dimension,
columnGridPositions: ARRAY [0..numberOfColumns) OF Dimension,
backgrounds: LIST OF REF TableEntryRec,
origin: Position,
constraints: LIST OF Constraint];
Dimension: TYPE = RECORD[value: REAL, units: Units];
Position: TYPE = RECORD[x,y: Dimension];
Units: TYPE = {in, cm, mm, pt, pc, ...};
DocumentObject: TYPE; -- representation of a document object
Tesselation: TYPE; -- representation of the grid data structure that contains TileRecs
Constraint: TYPE; -- representation of a linear inequality
The corner stitching data structure tesselates the plane with tiles. An initial tesselation contains a single tile that serves as a universe. A tile object contains four pointers for the major compass-points, a tesselation coordinate value, and a generic pointer to its associated data. (In Cedar, a generic pointer permits a data structure to be used in several different applications without the algorithm knowing the type of the data. The application is responsible for providing the pointer value and for later asserting the type of the pointer whenever the pointer is dereferenced to access the data fields.) New tiles are added by splitting the universal tile to maintain a ``maximal East-West strip'' property, which can be seen in Figures 5-14 and 5-15.
TileRec: TYPE = RECORD[
north, south, east, west: REF TileRec,
x, y: Coordinate, -- NE corner in the tesselation coordinate system
data: REF ANY]; -- a REF TableEntryRec when used for table formatting
Coordinate: TYPE = INTEGER;
The table formatting prototype creates a table entry record for each corner stitched tile. The table entry contains the grid coordinates and the kind of table object. A box table entry points to the document object that will appear in the table, and retains the box dimensions, origin, and alignment point computed by the layout algorithms. Typographic rules and background table entries have no content. The style attributes are remembered as a list of attribute-value pairs.
TableEntryRec: TYPE = RECORD[
top, left: GridCoordinate, -- in the table grid coordinate system
bottom, right: GridCoordinate,
object: SELECT boxType: {box, rule, background} FROM
box => [
contents: REF DocumentObject,
extents: BoxDimensions, -- computed later
alignmentPoint: Position,
origin: Position],
rule => [],
background => [],
ENDCASE,
styleAttributes: LIST OF Attributes
];
GridCoordinate: TYPE = INTEGER;
BoxDimensions: TYPE = RECORD[left, right, top, bottom: Dimension];
Attributes: TYPE; -- formatting attribute, value pair
5.4.3 Overlapping Planes
The corner stitching data structure is inherently planar, whereas some tables may involve overlapping table entries or rules. There are three things that may overlap: table entries that are ``pasted over'' other entries, rules that intersect with other rules, and backgrounds that underlay part or all of the table. The positions of all these overlapping elements can be expressed in terms of grid boundaries, so no additional layout information is necessary or generated by overlapped entries.
Backgrounds can be easily handled because there are generally few of them (often only one per table) and their size depends on and does not influence the table layout. It is sufficient to maintain a list of background rectangles to be shaded in the table object, so the rendering algorithm can traverse the list and paint the shaded background before rendering the rules and table entries.
Overlapping rules within tables are more interesting and more common. Rules intersect when a horizontal rule and a vertical rule meet. Even if the rules are of equal thicknesses, the end points of the rules must be adjusted to ensure that they avoid a notched corner, such as the leftmost examples in Figure 5-16. Additional complications arise when two rules of different colors or textures intersect. Then one of the rules dominates and the other rule should have its endpoint adjusted to avoid penetrating the first, as shown by the middle examples in Figure 5-16. The prototype implementation only handles rules with square ends but an extension capability is available to add other intersection types.
====================
///Beach/Thesis/Figure5-16-Intersections.Press
leftMargin: 129 pt, topMargin: 147 pt, width: 331 pt, height: 186 pt
Figure 5-16. INTERSECTING RULES in a table may require one of several special treatments. Lines of different thicknesses; lines of different color; lines with repeating patterns (dashes, borders); lines with ornaments at the end; rounded corners where lines intersect with sufficient clearance are all examples of the treatments possible with this technique.
====================
The fragmentation of corner stitched tiles, when a tile is about to penetrate an existing tile, provides the opportunity to capture the notion of intersecting rules explicitly. For example, the capability for rounded corners (as shown at the bottom right in Figure 5-16), or for placing special ornaments at the intersection of two rules can be specified at the intersection tile. The intersections between double or multiple rules can be treated in various ways. This technique for capturing the intersections between rules permits a general mechanism for specifying style attributes that apply to typographic rules and border patterns.
Overlapping table entries might be handled by maintaining an overlap order when they intersect. Table entry tiles in the grid data structure presently reference a single table entry. For overlapping entries, the tiles would have to maintain the list of overlapped table entries in overlap priority order. The rendering algorithm could then be modified to render the list of overlapped entries from back to front using the Painter's algorithm. These extensions for overlapping table entries have not been implemented in the prototype.
5.4.4 Grid Algorithms
The main algorithms presented in this section are the table layout and table rendering algorithms. The table layout algorithm takes a table arrangement and produces the positions of the grid lines and table entries. The table rendering algorithm is responsible for creating a printable or displayable version of the table given the positions and content of the table. These two algorithms require an enumeration algorithm to act on all of the table entries in the internal table data structure. Interactive manipulation of tables requires a hit-testing algorithm, which resolves the table entry that is being pointed at on the screen, and dynamic restructuring algorithms to insert and delete parts of a table.
Table Layout Algorithm
The table layout algorithm determines the coordinates (relative to a table origin) of the grid lines given the grid data structure representing the table arrangement. The layout algorithm also needs the bounding box dimensions and alignment point of each table entry, which are obtained through the object layout procedure associated with the class of document content in that table entry. Typographic rules also have widths which are obtained through the style machinery. Linear inequality constraints describe the positioning relationships between table entries and grid lines. A mathematical constraint solver is described later in Section 5.5, where the complete table layout algorithm is presented. The time complexity of the layout algorithm is dominated by the algorithm for satisfying the linear inequality constraints.
Table Rendering Algorithm
The table must be rendered in a form suitable for display or printing. The table rendering algorithm takes the grid positions determined by the table layout algorithm along with the collection of table entries in the grid data structure and instantiates each table entry at its appropriate position. The content of each table entry is rendered via the rendering procedure associated with that document object class.
To handle the possible overlap of data, the table content is rendered in back to front order: shaded backgrounds first, then rules, then table entries.
The table rendering algorithm uses a device independent imaging model [Warnock&Wyatt, CedarGraphics] for raster devices to produce formatted output for both displays and printing devices. Device independence provides a WYSIWYG capability for interactive editing of tables because the display screen presents the same fonts and graphics as the printed form of the table, subject to differences in device resolution. The implementation of a table editor shares the table rendering algorithm with the document formatter.
Algorithm R (Table Rendering)
R1 [Output Backgrounds] Traverse the list of shaded backgrounds in the table and for each one, output a shaded rectangle with corners determined by the coordinates of the table entry's four grid line positions, and with the color specified by the area color style attribute.
R2 [Enumerate Rule Tiles] Traverse the table grid structure and render each table rule:
R2.1 [Draw Rule] Determine the rule shape from the grid line position, the rule thickness specified by a style attribute, and any intersections with other rules. Draw the rule in the color specified by the rule color style attribute.
R3 [Enumerate Table Entries] Traverse the table grid structure and render each table entry:
R3.1 [Output Table Content] Invoke the rendering procedure for this table object at its origin (x,y).
One might extend the rendering algorithm for interactive use so that it performs only minimal repainting. The technique is similar to that used by WYSIWYG text editors. By keeping state information about table entries that change, only those entries need be repainted. By keeping track of grid positions that change, a block-move instruction on portions of the bit-mapped screen permits opening up (or closing up) grid lines to update the table without having to rerender the entire table. The table editor would have to cooperate with the table rendering algorithm to maintain these state variables.
Enumerate Area Algorithm
Both the table layout and the table rendering algorithm must enumerate all of the table entries and rules in the grid data structure. The corner stitching data structure has a directed area enumeration algorithm [Ousterhout, Corner Stitching] that takes linear time in the number of tiles enumerated. The algorithm is given the corner stitching data structure and a rectangular search area.
Algorithm EA (Enumerate Area Algorithm)
EA1 [Locate Lower Left Tile] Use the corner-stitching point-finding algorithm to locate the tile at the lower left corner of the search area.
EA2 [Walk Left Edge] Walk the tiles along the left edge and for each tile encountered invoke the following steps recursively:
EA2.1 [Enumerate This Tile] Perform some user-supplied action on this tile, or if no action was supplied, then append this tile to an enumeration list.
EA2.2 [Check Right Boundary] If the right edge of this tile is outside the search area, then return.
EA2.3 [Locate Right Neighbors] Use the corner-stitching neighbor-finding algorithm to enumerate neighbors along the right edge of this tile. For each neighbor that intersects the search area:
EA2.3.1 [Recurse on Neighbor] If the top-left corner of the neighbor touches the current tile, or if the top edge of the search area cuts both the current tile and its neighbor, then recurse at step EA2.1 on the neighbor.
The implementation of the enumeration algorithm used in the table formatting prototype uses a nonrecursive algorithm due to Shand [Shand, CornerStitching] that is based on traversing the tiles like a threaded tree. The implementation requires the caller to supply an action procedure to be performed for each tile. The enumeration algorithm is used in the table layout, table rendering, deletion, and insertion algorithms. For example, the table rendering algorithm supplies an action procedure that renders the content of a particular table entry.
Hit-testing Algorithm
A hit-testing algorithm is necessary for interactive manipulation of a table. The hit-testing algorithm determines the table entry corresponding to a position on the display screen pointed at by the user. The algorithm must be quite rapid if the table entry is to be continuously highlighted as the user moves the pointing device across the table on the screen. The algorithm depends on a corner stitching algorithm for locating a corner stitched tile given the tile coordinates. The corner stitching algorithm takes O(n) time on average when tiles have a relatively uniform size and O(n) time in the worst case when all the tiles are in a single column or row [Ousterhout, Corner Stitching].
Given the screen (x,y) coordinates of the pointing device, the hit-testing algorithm first converts the screen coordinates relative to the display window into table coordinates relative to the table origin. The appropriate row and column grids are found by searching the table grid position arrays. The grid coordinates are converted into corner stitched coordinates and the tile locating algorithm returns the table entry tile that contains the data pointer to the table entry object.
Algorithm H (Hit-testing Algorithm)
H1 [Convert Coordinates] Given (Sx,Sy), the screen coordinates, subtract the screen coordinates of the table origin, (Ox,Oy), relative to the display window, to produce the table coordinates (Tx,Ty) of the point. Report an error if (Tx,Ty) lies outside the table.
H2 [Find row and column grids] Search the two vectors of grid coordinates for row grid line Gr preceding Tx and the column grid line Gc preceding Ty. This can be done with a logarithmic search.
H3 [Find Table Entry] Locate the grid tile at the grid coordinates (Gr,Gc) using the corner stitching location algorithm and extract the reference pointer to the resulting table entry.
Delete Algorithm
Two algorithms for dynamically inserting and deleting table elements were incorporated into the table formatting prototype. The development of interactive tools for table editing was not central to the research in this thesis, but the tools were useful for constructing examples and gaining insight into the value of the grid structure for interactive editing. Chapter 6 contains plans to implement better algorithms based on better data structures.
There are two variations of the deletion algorithm. The first variant deletes table entries without changing the table topology, and the second deletes grid lines and hence changes the topology.
In the first variant that deletes only table entries, the deletion algorithm is given two pairs of grid lines that determine a rectangular region. By enumerating the area within that rectangular region all of the table entries intersecting that region are found. Some entries may be partially outside the region and therefore should not be deleted. This algorithm takes time linear in the number of entries enumerated in the rectangular region due to the behavior of the area enumeration algorithm.
Algorithm E (Table Entry Deletion Algorithm)
E1 [Enumerate Area to Delete] Enumerate all the table entries within the two pairs of grid lines, and for each table entry:
E1.1 [Delete Table Entry] If the table entry is completely within the two pairs of grid lines, then delete the table entry from the grid data structure.
The second variant of the deletion algorithm deletes grid lines and all table entries between them. The algorithm is given a pair of grid lines. All grid lines between the pair of grid lines (inclusive) are deleted and replaced by a single grid line. All table entries found entirely within the pair of grid lines are deleted. Any table entry that crosses outside the pair of grid lines is changed to reflect the new topology. This deletion algorithm is presented in its simplest form, which creates a new copy of the grid data structure.
Algorithm G (Table Grids Deletion Algorithm)
G1 [Prepare New Grid Structure] Prepare a second grid data structure to receive the modified table topology.
G2 [Enumerate the Old Grid] Use the area enumeration algorithm to find all the table entries that intersect the region defined by the pair of grid lines. For each table entry, perform one of the following actions:
G2.1 [Table Entry Within Grid Pair] Ignore this table entry; it will not appear in the new structure and is not copied.
G2.2 [Table Entry Precedes Grid Pair] Create a tile in the new grid structure and copy this table entry.
G2.3 [Table Entry Straddles Grid Pair] Adjust the farthest grid coordinate of this table entry by the number of grid lines deleted, and create a tile in the new grid structure for this changed table entry.
G2.4 [Table Entry Follows Grid Pair] Adjust both grid coordinates of this table entry by the number of grid lines deleted, and create a tile in the new grid structure for this changed table entry.
G3 [Install New Grid Structure] Update the table object to use this new grid structure.
The implementation of the deletion algorithm in the table prototype relies on the existing corner stitching implementation and avoids designing or implementing a more dynamic data structure suggested in Chapter 6. The deletion algorithm uses two copies of the table grid structure and ping pongs between them. The time to create the new grid structure is dominated by the time needed to refresh the display screen. A major performance benefit is avoiding automatic storage collection, since the corner stitching implementation caches deleted grid tiles and reuses them without allocating new ones.
Insert Algorithm
The insertion algorithm also comes in two variants, (a) one which inserts a table entry into an empty grid module without changing the topology, and (b) another which inserts a new grid line that changes the table topology. In the insert table entry variant (a), the new table entry is created and inserted into the grid structure at the grid coordinates corresponding to an empty tile. In the insert grid line variant (b), the dual grid structure technique shown above is used to create a new table topology.
5.5 Table Layout via Constraints
A linear constraint solver is employed to determine the table geometry from the table topology, the content of table entries, and explicit auxiliary constraints supplied by the table creator. The grid data structure represents the topology of all the table entries and contains pointers to their content. The layout algorithm enumerates all of the table entries and generates appropriate constraints on their positions. Additional constraints may be supplied with the table to impose special conditions such as forcing columns of equal width. Solving the resulting system of linear inequalities produces the computed positions of all the grid lines and table entries.
5.5.1 Constraint Systems
Examples of constraint systems in computer graphics provided the motivation for this technique. Sutherland's Sketchpad [Sutherland, Sketchpad] was a seminal interactive graphics system that relied on constraint satisfaction to position graphical elements. Borning's implementation of Thinglab [Borning, Thinglab] demonstrated the use of constraints in several problem domains. The document layout and document content examples in his report were of particular interest. The layout example [Borning, Thinglab, p29] showed a paragraph surrounded by a rectangle precisely large enough to hold the paragraph. When the width of the rectangle or content of the paragraph was changed, the rectangle's height was adjusted accordingly.
Several other graphics systems used constraints to position things. JUNO [Nelson, Juno] and ideal [van Wyk, ideal] both use nonlinear constraints to determine the position of graphical objects. pic [Kernighan, pic] labels the corners of boxes and position objects relative to those labellings. The graphical debugger Incense [Myers, Incense] contained a heuristic for positioning nested objects in a data structure by dividing the available space in two. The ability of these systems to position parts of an illustration relative to one another was very attractive and analogous to the layout of table entries relative to one another.
Linear inequalities are sufficient to describe the positioning relationships between table entries, such as making a column wide enough for an entry, or making a row heading tall enough to span several rows. Restricting the constraints to linear inequalities prevents expressing area relationships, but it is more common to express such relationships by establishing a ratio among the sides of the rectangle which can be described by linear inequalities. All the distances in a table can be expressed as rectilinear (horizontal or vertical) distances. Thus addition, subtraction and scalar multiplication are the only operations needed to express the table positioning relationships.
Using inequalities introduces the notion of slack variables that turn the inequality into an equality for the constraint solver. These slack variables capture the extra room left over for the table entry to fit the grid lines. Smaller table entries have greater slack than larger entries, and one or more table entries will have zero slack. The slack variables are helpful in determining whether the constraint system must be recomputed when editing a table. A table entry with slack may grow or shrink without requiring the constraint system to be recomputed, while a table entry with zero slack that changes size will always require recomputing the grid lines.
The linear inequality solver due to Nelson [Nelson, Program Verification] used in the table formatting prototype has an useful property for implementing an undo facility in an interactive table editor. The constraint tableau maintains a stack of `dead' tableau columns which permits a previous state of the tableau to be recomputed quickly. Changes to the table that modify table layout constraints may be quickly undone through this mechanism without recomputing the entire solution of the constraint system.
5.5.2 The Complexity of Linear Constraint Solvers
Solving a system of linear inequalities is equivalent to the LINEAR PROGRAMMING problem, which is known to be solvable in polynomial time [Khachiyan, LP]. A table arrangement without centered table entries can be described by a system of linear inequalities using only two variables per inequality, as described in the next section. This particular LINEAR INEQUALITY problem for two variables can be solved in O(n3) worst case time [Aspvall&Shiloach, Linear Inequalities], where n is the number of constraints. Algorithms for solving more general systems of linear inequalities based on the Simplex method have O(n3) expected time behavior [Dantzig, LP]. A version of the Simplex algorithm due to Nelson [Nelson, Program Verification] was implemented in the table formatting prototype.
5.5.3 The Constraint Table Layout Problem
The table layout algorithm introduced in Section 5.4.4 depends on a linear inequality constraint solver to compute the positions of the grid and table entries. This section discusses the linear inequalities actually used to describe the table arrangement.
Consider a particular table entry represented as a box k. This table entry is positioned within a pair of horizontal grid lines and a pair of vertical grid lines as shown in Figure 5-17. The alignment point of the box is to be aligned with other boxes that share the same pair of grid lines. Label the four grid lines surrounding the box as leftGridk, rightGridk, topGridk, bottomGridk. Label the offsets from the alignment point to the edge of the box as distances leftOffsetk, rightOffsetk, topOffsetk and bottomOffsetk (these offsets are fixed by the content and can be determined before table layout). The position of the alignment point within box k will be (Xk, Yk).
The vertical grid lines represent column boundaries and their positions are designated by the variables Ci. The horizontal grid lines represent row boundaries and their positions are designated by the variables Rj. Boxes within the pair of grid lines left and right that are vertically aligned will be positioned at the variable Vleft,right, while boxes horizontally aligned within the row between grid lines top and bottom will be positioned at Htop,bottom. All variables are restricted to positive values.
====================
///Beach/Thesis/Figure5-17-BoxConstraints.Press
leftMargin: 92 pt, topMargin: 136 pt, width: 338 pt, height: 112 pt
Figure 5-17. CONSTRAINT VARIABLES FOR A PARTICULAR TABLE ENTRY are shown in this diagram. The box representing the table entry is in dark grey and the grid module formed by two pairs of grid lines is shown in light grey, the column lines Cleft and Cright and the row lines Rtop and Rbottom. The alignment point of the table entry box goes through the two alignment lines, Vleft,right and Htop,bottom.
====================
The objective function for the constraint solver will be to minimize the width and depth of the table. For a table with m rows and n columns, the objective function would be
Min {(CnC0) + (RmR0)} .
The table layout the relationships among grid lines and alignment points can be described by inequality constraints. The first set of constraints (1) ensure that all of the grid lines are in the expected order and that the alignment line is within the column. One set of constraints is required for each pair of grid lines, left and right, that contain a table entry. (Column constraints are used in the examples that follow; row constraints are similar.)
CrightCleft e 0
Vleft,rightCleft e 0
(1)
CrightVleft,right e 0 .
A constraint to ensure that the grid lines are sufficiently far apart to contain the width of a table entry is generated for each table box k:
CrightGridkCleftGridk e leftOffsetk + rightOffsetk .
(2)
In practice, these two sets of constraints are not generated explicitly since they are subsumed by the alignment constraints below.
The alignment constraints vary with the type of alignment requested. Aligning a table box flush left in the column without regard to any other box in
the column generates these two constraints to position the box immediately adjacent to the column grid:
XkCleftGridk = leftOffsetk
(3L)
CrightGridkXk e rightOffsetk .
Similarly, aligning a table box flush right in the column without regard to any other box switches the equality and inequality constraints from those in (3L):
XkCleftGridk e leftOffsetk
(3R)
CrightGridkXk = rightOffsetk .
Centering a table box within the column may involve one of two centering concepts. The first forces the box alignment point to be equidistant between the column grid lines:
2ýXkCleftGridkCrightGridk = 0 .
(3C)
The second centering concept positions the box to balance the excess whitespace surrounding the box. The excess whitespace is the width of the column (CrightGridkCleftGridk) less the width of the box (leftOffsetk + rightOffsetk):
XkleftOffsetkCleftGridk =
1/2ý[(CrightGridkCleftGridk) — (leftOffsetk + rightOffsetk)]
which can be simplified to the form:
2ýXkCleftGridkCrightGridk = leftOffsetkrightOffsetk .
(3C`)
The two centering constraints (3C) and (3C`) are equivalent only if the two offsets are equal, which is when the alignment point is in the center of the box.
Note that up until now none of these alignment constraints involved aligning a set of boxes with each other, only positioning the box within the column. To align several boxes, we need to force the alignment point within a box to be equal to the position of the alignment line within that column. Thus, for each box k in the set, generate an equality constraint:
XkVleftGridk,rightGridk = 0
(4)
In fact, if the variable Xk does not appear in any other constraint, then it may be dispensed with and treated as an alias.
The positioning constraints for each box aligned within a set are simpler because they only require that the box fit within the column:
VleftGridk,rightGridkCleftGridk e leftOffsetk
(5)
CrightGridkVleftGridk,rightGridk e rightOffsetk .
However, these constraints are not sufficient to force the set of boxes to be flush left, flush right, or centered within the column. This must be accomplished by guiding the constraint solver to a particular desired solution. For example, to force the set of aligned boxes flush left, the objective function to be minimized by the constraint solver must be augmented with a term for the left distance:
Min {(VleftGridk,rightGridkCleftGridk)} .
(6)
A similar term is necessary to force the set of aligned boxes flush right.
Centering the alignment line for a set of boxes within a column may be accomplished in two ways. The first simply positions the alignment line equidistant between the column grid lines and does not involve an additional term in the objective function:
2ýVleftGridk,rightGridkCleftGridkCrightGridk = 0 .
(7)
The second centering technique is to balance the whitespace between the set of aligned boxes and the grid lines. The objective function requires a new variable equal to the maximum whitespace in the column. This was not done in the prototype but is considered later in section 5.5.4 when such `maximum' variables are introduced to handle large tables.
These linear constraints can be generated automatically for a table from the information kept in the grid data structure. A small expression language for constraint inequalities is provided in the prototype for the table designer to describe additional constraints for special effects. For instance, to create two columns of equal-width, say the column between grid lines left and right and the column between left` and right`, the following equality constraint is added to the table specification:
(Cleft`Cright`) — (CleftCright) = 0 .
(8)
The expression language accepts a standard form of the variable names. Two such constraints were included in the external representation shown in Figure 5-13. A variety of user interfaces to this constraint expression facility are possible. Only the simplest textual interface of typing the constraint equations is supported in the prototype.
====================
H4,5R4 e 6.225697
(flush left box 4,0)
R4H4,5 e 15.25376
H3,4R4 e 6.225697
(flush left box 3,0)
R3H3,4 e 14.97279
H4,5R5 e 6.0
(flush left box 4,4)
R4H4,5 e 12.22937
H4,5R5 e 6.0
(flush left box 4,3)
R4H4,5 e 12.22937
H4,5R5 e 6.0
(flush left box 4,2)
R4H4,5 e 12.22937
H4,5R5 e 6.0
(flush left box 4,1)
R4H4,5 e 12.22937
H3,4R4 e 6.0
(flush left box 3,4)
R3H3,4 e 12.22937
H3,4R4 e 6.0
(flush left box 3,3)
R3H3,4 e 12.22937
H3,4R4 e 6.0
(flush left box 3,2)
R3H3,4 e 12.22937
H3,4R4 e 6.0
(flush left box 3,1)
R3H3,4 e 12.22937
H2,3R3 e 6.0
(flush left box 2,4)
R2H2,3 e 15.25376
H2,3R3 e 8.257013
(flush left box 2,3)
R2H2,3 e 15.25376
H2,3R3 e 6.0
(flush left box 2,2)
R2H2,3 e 15.25376
H2,3R3 e 8.257013
(flush left box 2,1)
R2H2,3 e 15.25376
H1,2R2 e 8.482721
(flush left box 1,3)
R1H1,2 e 15.25376
H1,2R2 e 8.482721
(flush left box 1,1)
R1H1,2 e 15.25376
H0,1R1 e 8.482721
(flush left box 0,1)
R0H0,1 e 15.25376
Figure 5-18. THE ROW CONSTRAINTS GENERATED for the table in Figure 5-6. The variables for the row grid line positions are R0, R1, R2, R3, R4, R5 and the horizontal alignment line positions are H0,1, H1,2, H2,3, H3,4, H4,5.
====================
====================
2.0ýC1C0C3 = 0
2.0ýC2C1C3 = 0
C0V0,1 e 3.0
(flush left box 4,0)
C1V0,1 e 69.31976
C0V0,1 e 3.0
(flush left box 3,0)
C1V0,1 e 55.72097
C5C4 e 24.0675
(center box 4,4)
2.0ýV4,5C4C5 = 0
C4C3 e 60.2025
(center box 4,3)
2.0ýV3,4C3C4 = 0
C3C2 e 24.0675
(center box 4,2)
2.0ýV2,3C2C3 = 0
C2C1 e 60.2025
(center box 4,1)
2.0ýV1,2C1C2 = 0
C5C4 e 24.0675
(center box 3,4)
2.0ýV4,5C4C5 = 0
C4C3 e 60.2025
(center box 3,3)
2.0ýV3,4C3C4 = 0
C3C2 e 24.0675
(center box 3,2)
2.0ýV2,3C2C3 = 0
C2C1 e 60.2025
(center box 3,1)
2.0ýV1,2C1C2 = 0
C5C4 e 30.86088
(center box 2,4)
2.0ýV4,5C4C5 = 0
C4C3 e 63.23784
(center box 2,3)
2.0ýV3,4C3C4 = 0
C3C2 e 30.86088
(center box 2,2)
2.0ýV2,3C2C3 = 0
C2C1 e 63.23784
(center box 2,1)
2.0ýV1,2C1C2 = 0
C5C3 e 88.15895
(center box 1,3)
2.0ýV3,5C3C5 = 0
C3C1 e 73.83745
(center box 1,1)
2.0ýV1,3C1C3 = 0
C5C1 e 159.6822
(center box 0,1)
2.0ýV1,5C1C5 = 0
Figure 5-18 (continued). THE COLUMN CONSTRAINTS GENERATED for the table in Figure 5-6. The first two constraints are the auxiliary constraints to force the equal column widths; the rest are generated by the table layout algorithm. The variables for the column grid line positions are C0, C1, C2, C3, C4, C5 and the vertical alignment line positions are V0,1, V1,2, V1,3, V1,5, V2,3, V3,4, V3,5, V4,5.
====================
5.5.4 Handling Large Tables
The constraint scheme just outlined suffers from rapid growth in the problem size as the tables grow larger. Several strategies can greatly reduce the number of constraints generated.
The first strategy eliminates redundant variables whenever they appear as aliases of other variables. For example, the box position Xk is often an alias for VleftGridk,rightGridk when they are set equal and therefore Xk can be eliminated.
In many table layouts, a simplifying assumption may be made to solve the row and column constraints separately. Treating the two sets of constraints independently reduces the number of constraints and the size of the corresponding constraint tableau. It is worth assessing the necessity of this assumption and the situations in which it is violated.
The independence assumption does not hold when one wants to create grid designs with modules that are square or have specific aspect ratios. A square module results from constraining the row height to equal the column width. Obviously, in this situation the sets of row and column constraints are not independent. The assumption is also not true when trying to distribute whitespace within a table, for example, by folding wide horizontally-oriented table entries to trade off more vertical depth for less horizontal width. In this situation, decreasing the column width increases the row height and the constraints are again not independent.
The independence assumption can be tested automatically by examining the variables in each constraint. Constraints that mix row and column variables, such as one specifying that a row height equals a column width, are interdependent and must be solved simultaneously. Constraints that do not mix variables are independent and can be solved separately as smaller problems. The prototype currently assumes that the row and column constraints are independent, but one could easily check the explicitly supplied constraints for violations of this assumption and thus determine automatically whether to solve the table layout constraints independently or not.
What is the cost of solving interdependent row and column constraints? When the two sets are combined into a single constraint system the problem size is doubled. Since the constraint solver takes O(n3) time on average, the combined constraint layout would require about four times as much as the sum of the two smaller independent computations.
A reduction in the number of constraints can also be achieved by observing the structure of the constraint inequalities. The constraints that determine the grid positions surrounding a particular table entry are all similar:
VleftGridk,rightGridkCleftGridk e leftOffsetk
(5)
CrightGridkVleftGridk,rightGridk e rightOffsetk .
For the set of table entries within a particular column, these inequalities are dominated by a single maximum value of the right hand side. The maximum value could be determined by simpler means than expressing so many redundant constraints. We can discover the value by a linear preprocessing pass through all the table entries in that particular column to determine the maximum left and right offsets. The two maximum values are assigned to new variables used by the constraint solver:
maxLeftleft,right = max{leftOffsetk for all boxes k in column left,right}
maxRightleft,right = max{rightOffsetk for all boxes k in column left,right} .
With these maximum values known by these variable names, the set of inequalities per column (one or more constraint for each table entry) can be replaced by one inequality per column. This vastly reduces the number of constraints from the product of the number of entries per column times the number of columns to simply the number of columns:
Vleft,rightCleft e maxLeftleft,right
(5`)
CrightVleft,right e maxRightleft,right .
A further optimization in the linear constraint solver can be made based on the observation that most of the constraint inequalities have only two variable terms. Thus, sparse matrix techniques might reduce the space requirements of the solver at the expense of more overhead in the constraint solver. The prototype implementation uses a conventional matrix structure for the constraint tableau.
5.5.5 The Layout Algorithm
The complete table layout algorithm including the constraint solver can now be presented. The algorithm requires the grid data structure for the table arrangement and the contents of all of its table entries. The first step in the algorithm ensures that the dimensions of all of the table entries are known. These dimensions are provided by invoking the particular layout algorithm for each table entry object. In the event that a table entry contains another subtable, then the layout algorithm would be invoked on that subtable first. The dimension information for each table entry is cached in the table entry object since the box dimensions are used twice when the row and column constraints are independent.
Algorithm L (Table Layout)
L1 [Dimension the Boxes] Determine the dimensions of the table entries by invoking the layout procedure for that class of object. Remember the dimensions since they are used for both row and column layout.
L2 [Layout the Rows]
L2.1 [Establish Row Constraints] Enumerate the table grid structure and generate the appropriate constraints for each table entry.
L2.2 [Solve] Invoke the constraint solver on the row constraints, and record the row grid coordinates.
L2.3 [Position Table Entries] Enumerate the table grid structure and compute the layout coordinates of the origin for each table entry from the computed grid positions.
L3 [Layout the Columns]
L3.1 [Establish Column Constraints] Enumerate the table grid structure and generate the appropriate constraints for each table entry.
L3.2 [Solve] Invoke the constraint solver on the column constraints, and record the column grid coordinates.
L3.3 [Position Table Entries] Enumerate the table grid structure and compute the layout coordinates of the alignment position for the each table entry from the computed grid positions.
5.6 Conclusions
This chapter has introduced a new framework for interactive table formatting. The separation of table topology from table geometry has been incorporated into this framework. A grid structure describes the topological table arrangement and a mathematical constraint solver computes the table layout. A prototype table formatter was built using extensions to the Tioga document model and to the style machinery. Unlike many other document formatting systems, this approach allows more general table designs to be described and edited with interactive tools.
The grid structure provides an explicit representation of the table topology suitable for WYSIWYG interactive editing of tables. The grid structure represents areas directly, permitting symmetric treatment of rows and columns, and enabling typographic rules and background areas to be treated explicitly. An implementation of the grid structure exists with linear algorithms suitable for interactive manipulation which support selection hierarchies of table structures, table entries, row, columns, and the entire table. Support for overlapping table designs is possible; backgrounds are easy.
The mathematical constraint solver computes the table geometry from linear inequalities that express the table alignment possibilities. Most of the inequalities are generated automatically from alignment and positioning style attributes, while additional constraints may be specified by the table designer to enforce special layout requirements.
The table object class in the document model permits tables to exist within documents and be interactively edited by appropriate class editors. Tables may contain arbitrary content since a table entry is treated as an arbitrary document object. Style attributes for tables are managed by extensions to the style machinery. New attributes for table alignment and various typographic features unique to tables have been added to the style mechanism of Chapter 3. A search path appropriate to the row/column structure of tabular information determines the values of attributes in force at each table entry.
The prototype table formatter worked well for the tables in this thesis. All of the tables in Chapter 4, the complex table in Figure 5-3, and the remaining tables in Chapter 5 were formatted by the prototype. The grid system proved to be a simple concept to work with, and creating additional linear inequality constraints for special effects appears to have considerable promise for extending the kinds of achievable table designs. Several of the large tables became tedious to manipulate in their textual form, a complaint that will be remedied with the completion of an interactive table editor. An implementation of an interactive table editor within Tioga based on this prototype is underway. Goals of this further work are described in Chapter 6.