Bug 107956 - Column/Row Style's "default-cell-style-name" interpretation
Summary: Column/Row Style's "default-cell-style-name" interpretation
Status: RESOLVED FIXED
Alias: None
Product: calligrasheets
Classification: Applications
Component: opendocument (show other bugs)
Version: unspecified
Platform: unspecified Linux
: NOR major
Target Milestone: ---
Assignee: Laurent Montel
URL:
Keywords:
: 128043 130923 (view as bug list)
Depends on:
Blocks:
 
Reported: 2005-06-23 01:15 UTC by Jure Repinc
Modified: 2006-12-28 14:44 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments
Tirst test file (6.03 KB, application/vnd.oasis.opendocument.spreadsheet)
2005-06-23 01:18 UTC, Jure Repinc
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jure Repinc 2005-06-23 01:15:21 UTC
Version:           1.4 (using KDE 3.4.1, Gentoo)
Compiler:          gcc version 3.4.4 (Gentoo 3.4.4, ssp-3.4.4-1.0, pie-8.7.8)
OS:                Linux (x86_64) release 2.6.12-gentoo

I just tried the new support for OpenDocument Spreadsheet standard in KOffice and I noticed that files created with OpenOffice.org don't show exactly right. I'll attach files and add comments with each. I appologise in advance for wasting your time if this is not a problem in KOffice but I decided to post it here first since it looks right in OOo.
Comment 1 Jure Repinc 2005-06-23 01:18:25 UTC
Created attachment 11552 [details]
Tirst test file

This file was created using OOo 1.9.109 on Windows XP. I just created a new
blank document and set A1 cell background to black and text color to white.
When I open the file in KOffice the entire A column has black background and
the text is also blank.
Comment 2 Jure Repinc 2005-06-26 20:38:23 UTC
Since I don't know where the bug is I also filed a bug report with OpenOffice.org:
http://qa.openoffice.org/issues/show_bug.cgi?id=51235
Comment 3 Jure Repinc 2005-08-16 17:39:23 UTC
OpenOffice.org developer added this comment:

Hi,

the column and row default styles are only defined for the used area. If the table 
has only one row, the column default style is only used in this one cell in this 
column. So we will not change anything.

Sascha
Comment 4 Ariya Hidayat 2006-01-20 00:35:16 UTC
SVN commit 500323 by ariya:

fix vertical alignment
fix loading of default style
(initial step for proper OpenDocument style handling)

CCBUG: 109633
CCBUG: 107956


 M  +11 -3     kspread_format.cc  
 M  +40 -6     kspread_style.cc  
 M  +6 -5      kspread_style_manager.cc  


--- trunk/koffice/kspread/kspread_format.cc #500322:500323
@@ -249,11 +249,19 @@
         currentCellStyle.addProperty( "fo:text-align", value );
     }
 
-    if ( hasProperty( Format::PAlignY ) || !hasNoFallBackProperties( Format::PAlignY ) )
+    if ( hasProperty( Format::PAlignY,true ) || hasNoFallBackProperties( Format::PAlignY ) )
     {
         Format::AlignY align = m_pStyle->alignY(  );
-        if ( align != Format::Bottom ) // default in OpenCalc
-            currentCellStyle.addProperty( "style:vertical-align", ( align == Format::Middle ? "middle" : "top" ) );
+        QString value;
+        if( align == Format::Top )
+            value = "top";
+        else if( align == Format::Middle )
+            value = "middle";
+        else if( align == Format::Bottom )
+            value = "bottom";
+            
+        if( !value.isEmpty() )
+            currentCellStyle.addProperty( "style:vertical-align", value );
     }
 
     if ( hasProperty( Format::PIndent,true ) || hasNoFallBackProperties( Format::PIndent ) )
--- trunk/koffice/kspread/kspread_style.cc #500322:500323
@@ -1010,10 +1010,30 @@
         style.addProperty( "fo:text-align", value, KoGenStyle::ParagraphType );
     }
 
-    if ( featureSet( SAlignY ) && alignY() != Format::Middle )
+    if ( featureSet( SAlignY ) && alignY() != Format::UndefinedY )
     {
-        style.addProperty( "style:vertical-align", ( alignY() == Format::Bottom ? "bottom" : "top" ) );
+        QString value = "bottom";  // OO.o Calc's default
+        switch( alignY()  )
+        {
+        case Format::Top:
+            value = "top";
+            break;
+        case Format::Middle:
+            value = "middle";
+            break;
+        case Format::Bottom:
+            value = "bottom";
+            break;
+        }
+            
+        style.addProperty( "style:vertical-align", value );
     }
+    
+    if ( !featureSet( SAlignY ) )
+    {
+        style.addProperty( "style:vertical-align", "middle" );
+    }
+    
     if ( featureSet( SBackgroundColor ) && m_bgColor != QColor() && m_bgColor.isValid() )
         style.addProperty( "fo:background-color", m_bgColor.name() );
 
@@ -2560,17 +2580,31 @@
     if ( m_name.isEmpty() )
         return;
     KoGenStyle gs;
+
+    if ( m_name == "Default" )
+        gs = KoGenStyle(Doc::STYLE_USERSTYLE, "table-cell");
+    else    
     if ( m_type == AUTO )
-        gs = KoGenStyle(Doc::STYLE_DEFAULTSTYLE );
+        gs = KoGenStyle(Doc::STYLE_DEFAULTSTYLE, "table-cell" );
     else
-        gs = KoGenStyle( Doc::STYLE_USERSTYLE ); //FIXME name of style
+        gs = KoGenStyle( Doc::STYLE_USERSTYLE, "table-cell" ); //FIXME name of style
+        
     if ( m_parent )
         gs.addAttribute( "style:parent-style-name", m_parent->name() );
-    gs.addAttribute( "style:display-name", m_name );
+
+    // default style does not need display name    
+    if( m_name != "Default" )
+        gs.addAttribute( "style:display-name", m_name );
+        
     QString numericStyle = saveOasisStyle( gs, mainStyles );
     if ( !numericStyle.isEmpty() )
         gs.addAttribute( "style:data-style-name", numericStyle );
-    mainStyles.lookup( gs, "custom-style" );
+        
+    if( ( m_type == BUILTIN ) && ( m_name == "Default" ) )
+        mainStyles.lookup( gs, "Default", KoGenStyles::DontForceNumbering );
+    else  
+        // this is auto or user style
+        mainStyles.lookup( gs, "custom-style" );
 }
 
 void CustomStyle::loadOasis( KoOasisStyles& oasisStyles, const QDomElement & style, const QString & name )
--- trunk/koffice/kspread/kspread_style_manager.cc #500322:500323
@@ -79,11 +79,12 @@
     kdDebug()<<" number of template style to load : "<<nStyles<<endl;
     for (unsigned int item = 0; item < nStyles; item++) {
         QDomElement styleElem = oasisStyles.userStyles()[item];
-        QString name;
-        if ( styleElem.hasAttributeNS( KoXmlNS::style, "display-name" ) )
-        {
-            name = styleElem.attributeNS( KoXmlNS::style, "display-name", QString::null );
-        }
+        
+        // assume the name assigned by the application
+        QString name = styleElem.attributeNS( KoXmlNS::style, "name", QString::null );
+        
+        // then replace by user-visible one (if any)
+        name = styleElem.attributeNS( KoXmlNS::style, "display-name", name );
 
         if ( name == "Default" )
         {
Comment 5 Stefan Nikolaus 2006-02-02 18:40:50 UTC
Sorry, won't fix!

Quoting from Open Document Format for Office Applications (OpenDocument) v1.0, http://docs.oasis-open.org/office/v1.0:
"8.2.1 Column Description
[...]
Default Cell Style
The table:default-cell-style-name attribute specifies the default cell style. Cells
without a style use this style when there is no default cell style specified for the cell's row as
well."


The relevant lines in content.xml in your test file:
[...]
		<style:style style:name="ce1" style:family="table-cell" style:parent-style-name="Default">
			<style:table-cell-properties fo:background-color="#000000"/>
			<style:text-properties fo:color="#ffffff"/>
		</style:style>
[...]
			<table:table table:name="Sheet1" table:style-name="ta1" table:print="false">
				<table:table-column table:style-name="co1" table:default-cell-style-name="ce1"/>
				<table:table-row table:style-name="ro1">
					<table:table-cell office:value-type="string"><text:p>Test</text:p></table:table-cell>
				</table:table-row>
			</table:table>
[...]

As you can see, the column has an attribute "table:default-cell-style-name" set to use style "ce1".
I.e. if a cell in this column, even an empty one, uses no explicit style
and the row does not define an attribute "table:default-cell-style-name"
this style is used. The style "ce1" defines the black background.

So, the behaviour of kspread, setting the column color to black, is correct.
Comment 6 Jure Repinc 2006-02-03 22:03:16 UTC
Peopple from OpenOffice.org have eplied like so:

Sheet1 in the example contains a table of one column, one row. It's really that,
not a table of 256 x 65536 with one cell filled. The cells in the file are what
default-cell-style-name refers to. If an application is capable of handling more
columns/rows, it is supposed to fill the rest with empty cells, see "Basic Table
Model" in the specification.

The reason for introducing default-cell-style-name was to avoid adding the same
style name to each cell element, just for brevity. Whole-column formats,
separate from individual cells, aren't in the specification (apart from what's
in the column style). If you need them, they have to be included in a future
version of the format.
Comment 7 Stefan Nikolaus 2006-02-19 00:41:33 UTC
On Friday 03 February 2006 22:03, Jure Repinc wrote:
> Sheet1 in the example contains a table of one column, one row.
> that, not a table of 256 x 65536 with one cell filled.


That's for sure.

> The cells in the file are what default-cell-style-name refers to.


No, the default cell style refers to all cells in this column (therefore it is 
called column style) which have:
1. no own cell style set
2. no default cell style in the respective row style set
(see below)

> If an application is capable of handling more columns/rows, it is supposed
> to fill the rest with empty cells, see "Basic Table Model" in the
> specification.  


Yes, that's right. But that does not imply, that these empty cells have no 
style. They have just no content, but they have an associated style.
Proof: Set the default cell style of an empty sheet to black background. Save 
it. Load it. What happens?
So, if we agree on empty cells have a style, KSpread's behaviour is right. It 
uses for the cells in the column, the cell style, which is set in the column 
style.
Because the filled-in empty cells do not specify an own style, we have to look 
in the row styles first. If there's no default cell style set, we look in the 
column style for a default cell style. If there would be no default cell 
style, then and only then we would fall back to the default cell style of the 
document. But in this case there's one, so we have to use it. Very easy, 
isn't it?!

> The reason for introducing default-cell-style-name was to avoid adding the
> same style name to each cell element, just for brevity.


Sure, this statement does not collide with anything explained above.
BTW: In KSpread we always have 32767x32767 tables and in OO.o Calc you have a 
similar table size, at least not a 1x1 table.

> Whole-column formats, separate from individual cells, aren't in the
> specification (apart from what's in the column style). If you need them,
> they have to be included in a future version of the format.


No, they are already in as described above.
Comment 8 Jure Repinc 2006-03-24 23:01:19 UTC
People from OpenOffice.org have closed their bug as WONTFIX saying this:

I'm closing this issue now. The intent behind the default-cell-style-name
attribute has been mentioned, and if the KOffice people don't want to believe
that and rather introduce artificial incompatibilities, it's their problem. At
least now they can't say they didn't know about it.
Comment 9 Stefan Nikolaus 2006-04-18 20:05:08 UTC
I don't consider this issue as artificial.

Let me try to explain my sight:
The "default-cell-style-name" is an attribute of the "table:column" element. Further attributes are the visibility and the column's style. The latter contains settings for the width and wether this should be optimized.

The visibility applies to the whole column, not only the used area saved in the file. Otherwise, you'll get an odd behaviour, if the adjacent column has a different width.

The column's style defining the width applies to the whole column. Otherwise, you'll also get an odd behaviour, if the width differs from default column's width.

The width optimization should also apply for newly added content in the column. So, it applies also to the whole column.

It would be inconsistent, if the "default-cell-style-name" attribute would be the only one, that applies not to the whole column.



The relevant section in the spec is the third paragraph in 8.1 Basic table model. Let's disassemble this and explain it on an example:

"Spreadsheet applications typically operate on large tables that have a fixed 
application dependent row and column number, but may have an unused area."
Spreadsheet application's sheet dimensions: 2x2 (a killer app!)

"Only the used area of the table is saved in files."
We occupy only the first cell and save our doc:
Document's table dimension: 1x1

"When loading a table with empty or incomplete rows into a spreadsheet 
application, empty rows typically introduce a default row (just as in an 
empty sheet),"
We speak of a spreadsheet application, so the default row has a 2x1 dimension.

"and incomplete rows are filled with empty cells (just like in an empty 
sheet)."
The first row becomes also a 2x1 row.

That we speak of incomplete and empty rows with respect to the spreadsheet 
application's dimension says the following sentence:
"All other applications typically have fixed size tables."

Now to the rendering:
"Incomplete rows are basically rendered as if they had the necessary number of 
empty cells,"
If we got
  <row>
  <cell>1</cell>
  </row>
or
  <row>
  <cell>1</cell>
  <cell/>
  </row>
, both have to be the same.

"and the same applies to empty rows."
  <row/>
becomes
  <row>
  <cell/>
  <cell/>
  </row>

As the spec refers to the application's dimension, the 
"default-cell-style-name" applies to all cells in a row (or column).


Hopefully, this explains my interpretation. At least, it should show that this is not artificial. For me, there's not even an ambiguity. But I'm only human. If you can show me where I'm wrong, I would be thankful.


@Jure: This time I cross-posted my comment, but the OOo report is closed. Hopefully, they recognize my comment.
Comment 10 Stefan Nikolaus 2006-07-19 17:50:52 UTC
Related bugs:
bug 124566
bug 130923
Comment 11 Stefan Nikolaus 2006-07-27 18:14:12 UTC
SVN commit 566941 by nikolaus:

OpenDocument	Default cell style name.
		Unless there's a clarification from the OpenDocument committee,
		we stay with the old (in my opinion the correct one) behaviour.
		At least it is better than losing styles assigned to cols/rows!
CCBUGS: 107956, 124566, 130923


 M  +62 -45    branches/koffice/1.6/koffice/kspread/kspread_sheet.cc  
 M  +57 -45    trunk/koffice/kspread/Sheet.cpp  
Comment 12 Stefan Nikolaus 2006-07-27 18:14:40 UTC
*** Bug 130923 has been marked as a duplicate of this bug. ***
Comment 13 Thorsten Staerk 2006-07-28 15:23:06 UTC
I had a diagramme of racks and the built-in servers. Each server was represented by a border around one or several cells. This bug caused data loss to me, I have to redraw the diagramme now.
Comment 14 Stefan Nikolaus 2006-08-03 09:45:57 UTC
*** Bug 128043 has been marked as a duplicate of this bug. ***
Comment 15 Stefan Nikolaus 2006-10-23 17:35:04 UTC
As with version 1.1 of the OpenDocument spec this is a valid KSpread bug.
Comment 16 Stefan Nikolaus 2006-12-27 19:39:25 UTC
SVN commit 617014 by nikolaus:

OpenDocument,	Restrict the region occupied by a column/row's default cell
Style,		style (given by default-cell-style-name) to the used area
StyleManager,	(107956, 134285).
StyleStorage
		Obey the order on loading cell styles. First, the columns'
		default cell styles, then, the rows' ones and then, the ordinary
		cell styles.

		Fix storing of the font color (was inserted with the 'bold' key;
		copy & paste error).

		Fix the loading of named styles (OO.o Calc's default style still
		causes problems).

BUGS: 107956, 134285


 M  +2 -2      Cell.cpp  
 M  +55 -24    Sheet.cpp  
 M  +15 -3     Sheet.h  
 M  +8 -3      Style.cpp  
 M  +60 -34    StyleManager.cpp  
 M  +7 -0      StyleManager.h  
 M  +9 -5      StyleStorage.cpp  
 M  +3 -1      TODO  
Comment 17 Thorsten Staerk 2006-12-28 14:31:44 UTC
Wonderful! Can we backport this to 1.6 ?
Comment 18 Stefan Nikolaus 2006-12-28 14:44:09 UTC
Everything's possible, but I won't. Sorry.

KSpread 2.0 got a new style storage, to which this bugfix is tightly coupled.