Warning, /office/calligra/sheets/doc/StyleStorage.dox is written in an unsupported language. File is not indexed.

0001 /**
0002 \page styleStorage Style Storage
0003 \author Ariya Hidayat (<a href="mailto:ariya@kde.org">ariya@kde.org</a>)
0004 \date 2004
0005 
0006 \par Status:
0007     FINISHED; NEEDS UPDATE (R-Tree, RectStorage)
0008 
0009 <p>Formatting specifies how a cell should look like. It involves font
0010 attributes like bold or italics, vertical and horizontal alignment,
0011 rotation angle, shading, background color and so on. Each cell can have
0012 its own format, but bear also in mind that a whole row or column format
0013 should also apply.</p>
0014 
0015 <p>Current way of storing formatting information is rather inefficient:
0016 pack it together inside the cell. The reason is because most of cells
0017 are either very plain (no formatting) and/or only have partial attribute
0018 (e.g. only marked as bold, no font family or color is specified).
0019 Therefore the approximately 20 bytes used to hold formatting information
0020 are quite a waste of memory. Even worse, this requires that the cell
0021 must exist even if it is not in use. As illustration, imagine a worksheet
0022 where within range A1:B20 only 5 cells are not empty. When the user
0023 selects this range and changes the background color to yellow, then
0024 those 5 cells must store this information in their data structure but
0025 how about the other 35 cells? Since the formatting is attached to the cell,
0026 there is no choice but to create them. Doing this, just for the sake of
0027 storing format, is actually not really good.</p>
0028 
0029 <p>A new way to store formatting information is proposed below.</p>
0030 
0031 <p>For each type of format a user can use, we have the corresponding
0032 <i>formatting piece</i>, for example &quot;bold on&quot;, &quot;bold off&quot;,
0033 &quot;font Arial&quot, &quot;left-border 1 px&quot;, etc. Whenever the user
0034 applies formatting to a range (could also be a whole column, row, or worksheet),
0035 we save appropriate respective formatting piece in a stack. Say the user has
0036 marked column B as bold, row 2 as italics, and set range A1:C5 with
0037 yellow background color. Our formatting stack would look like:
0038 </p>
0039 
0040 <table cellspacing="0" cellpadding="3" border="1">
0041 <tr>
0042   <td><b>Range</b></td>
0043   <td><b>Formatting Piece</b></td>
0044 </tr>
0045 <tr>
0046   <td>Column B</td>
0047   <td>Bold on</td>
0048 </tr>
0049 <tr>
0050   <td>Row 2</td>
0051   <td>Italics on</td>
0052 </tr>
0053 <tr>
0054   <td>A1:C5</td>
0055   <td>Yellow background</td>
0056 </tr>
0057 </table>
0058 
0059 <p>Now let try to figure out the overall format of cell B2. From the first
0060 we know it should be bold, from the second it should be italics, and last
0061 it should have yellow background. This complete format is the one which
0062 we used to render cell B2 on screen. In similar fashion, we can know that
0063 cell A1 on the other only specifies the yellow background, because the first
0064 and second pieces do not apply there.</p>
0065 
0066 <p>Another possible way to see the format storage is by using 3-D perspective.
0067 For each formatting piece, imagine there is a surface which covers the
0068 formatted range (the xy-plane). The formatting information is simply attached
0069 to the surface (say, as surface attribute). Every surface is stacked together,
0070 its depth (the z-axis) denotes the sequence, i.e. the first surface is the
0071 deepest. For the example above, we can view the pieces as one surface specifies
0072 &quot;bold on&quot; which is a vertical of column B, one surface specifies
0073 &quot;italics on&quot; which is a horizontal band of row 2 and one last surface
0074 which specifies &quot;yellow background&quot; stretched in the range A1:C5.
0075 How to find complete format for A2? This is now a matter of surface
0076 determination. Traversing in the direction of z-axis from B2 reveals
0077 that we hit the last and second surfaces only; thereby we can know the complete
0078 format is &quot;italics, yellow background&quot;.</p>
0079 
0080 <p>It is clear that a format storage corresponds to one sheet only. For each
0081 sheet, there should be one format storage. Cells can still have accessors to
0082 its formatting information, these simply become wrapper for proper calls to the
0083 format storage. Since each formatting piece holds information about the applied
0084 range, we must take care that the formatting storage is correctly updated
0085 whenever cells, rows or columns are inserted and deleted.</p>
0086 
0087 <p>In order to avoid low performance, we must use a smart way to iterate over
0088 all formatting pieces whenever we want to find out complete format for given
0089 cell(s). When the sheet gets very complex, it is likely that we will have
0090 many many formatting pieces that are not even overlap. This means, when we
0091 need formatting of cell A1, it is no use to check formatting pieces of range
0092 Z1:Z10 or A100:B100 which do not include cell A1 and are even very far from A1.
0093 One possible solution is to arrange the formatting pieces in a quad-tree.
0094 Because one piece can cover a very large area, it is possible that it will
0095 be in more than one leaf in the quad-tree. <i>Details on the possible use of
0096 quad-tree or other methods should be explored further more</i>.</p>
0097 
0098 */