Skip to content

Commit 20945a9

Browse files
kohei-usKohei Yoshida
authored andcommitted
Correctly import solid fill color.
In orcus, a solid fill type uses the foreground color only and ignores the background color. Also, let's not use the alpha component as it would cause the color to not get rendered at all. Some patches are applied against liborcus in order to adjust the ODF styles import code for this change. These changes will be incorporated in 0.13.3. Change-Id: I9e8c243cc6a7f366de2393e7b7ecf77366f5f9ea Reviewed-on: https://gerrit.libreoffice.org/49071 Reviewed-by: Kohei Yoshida <libreoffice@kohei.us> Tested-by: Kohei Yoshida <libreoffice@kohei.us>
1 parent 8cf603b commit 20945a9

File tree

4 files changed

+111
-5
lines changed

4 files changed

+111
-5
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
From 98d2b3377da71b713a37f9004acff3c02c22ce2b Mon Sep 17 00:00:00 2001
2+
From: Kohei Yoshida <kohei.yoshida@gmail.com>
3+
Date: Wed, 31 Jan 2018 22:11:25 -0500
4+
Subject: [PATCH 1/2] Alpha value of 0 means fully transparent. I'm sure 255
5+
was intended.
6+
7+
(cherry picked from commit f7953a814d6a43205791b6cc01c528ef5d4b1ce3)
8+
---
9+
src/liborcus/gnumeric_sheet_context.cpp | 4 ++--
10+
src/liborcus/odf_styles_context.cpp | 2 +-
11+
2 files changed, 3 insertions(+), 3 deletions(-)
12+
13+
diff --git a/src/liborcus/gnumeric_sheet_context.cpp b/src/liborcus/gnumeric_sheet_context.cpp
14+
index 8659cc3..6bd1471 100644
15+
--- a/src/liborcus/gnumeric_sheet_context.cpp
16+
+++ b/src/liborcus/gnumeric_sheet_context.cpp
17+
@@ -132,7 +132,7 @@ public:
18+
{
19+
spreadsheet::color_elem_t red, green, blue;
20+
gnumeric_helper::parse_RGB_color_attribute(red, green, blue, attr.value);
21+
- m_styles.set_fill_fg_color(0, red, green, blue);
22+
+ m_styles.set_fill_fg_color(255, red, green, blue);
23+
24+
m_fill = true;
25+
26+
@@ -145,7 +145,7 @@ public:
27+
{
28+
spreadsheet::color_elem_t red, green, blue;
29+
gnumeric_helper::parse_RGB_color_attribute(red, green, blue, attr.value);
30+
- m_styles.set_fill_bg_color(0, red, green, blue);
31+
+ m_styles.set_fill_bg_color(255, red, green, blue);
32+
33+
m_fill = true;
34+
}
35+
diff --git a/src/liborcus/odf_styles_context.cpp b/src/liborcus/odf_styles_context.cpp
36+
index d988f7d..f9c422a 100644
37+
--- a/src/liborcus/odf_styles_context.cpp
38+
+++ b/src/liborcus/odf_styles_context.cpp
39+
@@ -739,7 +739,7 @@ void styles_context::start_element(xmlns_id_t ns, xml_token_t name, const std::v
40+
{
41+
spreadsheet::color_elem_t red, green, blue;
42+
func.get_background_color(red, green, blue);
43+
- mp_styles->set_fill_bg_color(0, red, green, blue);
44+
+ mp_styles->set_fill_bg_color(255, red, green, blue);
45+
}
46+
47+
size_t fill_id = mp_styles->commit_fill();
48+
--
49+
2.7.4
50+
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
From 473526e1ca3a7117e2daf977e1b82a0a3977fc84 Mon Sep 17 00:00:00 2001
2+
From: Kohei Yoshida <kohei.yoshida@gmail.com>
3+
Date: Wed, 31 Jan 2018 22:24:45 -0500
4+
Subject: [PATCH 2/2] We are supposed to use the foreground color for solid
5+
fill.
6+
7+
(cherry picked from commit f821995022df8dd1e580dd22cf131584b2b1ac4f)
8+
---
9+
src/liborcus/odf_styles_context.cpp | 3 ++-
10+
src/liborcus/odf_styles_context_test.cpp | 9 +++++----
11+
2 files changed, 7 insertions(+), 5 deletions(-)
12+
13+
diff --git a/src/liborcus/odf_styles_context.cpp b/src/liborcus/odf_styles_context.cpp
14+
index f9c422a..e5f1cc6 100644
15+
--- a/src/liborcus/odf_styles_context.cpp
16+
+++ b/src/liborcus/odf_styles_context.cpp
17+
@@ -739,7 +739,8 @@ void styles_context::start_element(xmlns_id_t ns, xml_token_t name, const std::v
18+
{
19+
spreadsheet::color_elem_t red, green, blue;
20+
func.get_background_color(red, green, blue);
21+
- mp_styles->set_fill_bg_color(255, red, green, blue);
22+
+ mp_styles->set_fill_pattern_type(ORCUS_ASCII("solid"));
23+
+ mp_styles->set_fill_fg_color(255, red, green, blue);
24+
}
25+
26+
size_t fill_id = mp_styles->commit_fill();
27+
diff --git a/src/liborcus/odf_styles_context_test.cpp b/src/liborcus/odf_styles_context_test.cpp
28+
index 4c7eab5..7255a54 100644
29+
--- a/src/liborcus/odf_styles_context_test.cpp
30+
+++ b/src/liborcus/odf_styles_context_test.cpp
31+
@@ -48,10 +48,11 @@ void test_odf_fill(orcus::spreadsheet::import_styles &styles)
32+
std::cerr << std::hex << (int)fill;
33+
const orcus::spreadsheet::fill_t* cell_fill = styles.get_fill(fill);
34+
assert(cell_fill);
35+
- std::cerr << std::hex << (int)cell_fill->bg_color.red;
36+
- assert(cell_fill->bg_color.red == 0xfe);
37+
- assert(cell_fill->bg_color.green == 0xff);
38+
- assert(cell_fill->bg_color.blue == 0xcc);
39+
+ std::cerr << std::hex << (int)cell_fill->fg_color.red;
40+
+ assert(cell_fill->fg_color.red == 0xfe);
41+
+ assert(cell_fill->fg_color.green == 0xff);
42+
+ assert(cell_fill->fg_color.blue == 0xcc);
43+
+ assert(cell_fill->pattern_type == "solid");
44+
}
45+
46+
void test_odf_border(orcus::spreadsheet::import_styles &styles)
47+
--
48+
2.7.4
49+

external/liborcus/UnpackedTarball_liborcus.mk

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ $(eval $(call gb_UnpackedTarball_update_autoconf_configs,liborcus))
1818
$(eval $(call gb_UnpackedTarball_add_patches,liborcus,\
1919
external/liborcus/0001-workaround-a-linking-problem-on-windows.patch \
2020
external/liborcus/rpath.patch.0 \
21+
external/liborcus/0001-Alpha-value-of-0-means-fully-transparent.-I-m-sure-2.patch \
22+
external/liborcus/0002-We-are-supposed-to-use-the-foreground-color-for-soli.patch \
2123
))
2224

2325
ifeq ($(OS),WNT)

sc/source/filter/orcus/interface.cxx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1148,7 +1148,8 @@ void ScOrcusStyles::fill::applyToItemSet(SfxItemSet& rSet) const
11481148
return;
11491149
}
11501150

1151-
rSet.Put(SvxBrushItem(maBgColor, ATTR_BACKGROUND));
1151+
if (maPattern.equalsIgnoreAsciiCase("solid"))
1152+
rSet.Put(SvxBrushItem(maFgColor, ATTR_BACKGROUND));
11521153
}
11531154

11541155
ScOrcusStyles::protection::protection():
@@ -1574,15 +1575,19 @@ void ScOrcusStyles::set_fill_pattern_type(const char* s, size_t n)
15741575
maCurrentFill.mbHasFillAttr = true;
15751576
}
15761577

1577-
void ScOrcusStyles::set_fill_fg_color(orcus::spreadsheet::color_elem_t alpha, orcus::spreadsheet::color_elem_t red, orcus::spreadsheet::color_elem_t green, orcus::spreadsheet::color_elem_t blue)
1578+
void ScOrcusStyles::set_fill_fg_color(
1579+
orcus::spreadsheet::color_elem_t /*alpha*/, orcus::spreadsheet::color_elem_t red, orcus::spreadsheet::color_elem_t green, orcus::spreadsheet::color_elem_t blue)
15781580
{
1579-
maCurrentFill.maFgColor = Color(alpha, red, green, blue);
1581+
// Ignore the alpha element for now.
1582+
maCurrentFill.maFgColor = Color(red, green, blue);
15801583
maCurrentFill.mbHasFillAttr = true;
15811584
}
15821585

1583-
void ScOrcusStyles::set_fill_bg_color(orcus::spreadsheet::color_elem_t alpha, orcus::spreadsheet::color_elem_t red, orcus::spreadsheet::color_elem_t green, orcus::spreadsheet::color_elem_t blue)
1586+
void ScOrcusStyles::set_fill_bg_color(
1587+
orcus::spreadsheet::color_elem_t /*alpha*/, orcus::spreadsheet::color_elem_t red, orcus::spreadsheet::color_elem_t green, orcus::spreadsheet::color_elem_t blue)
15841588
{
1585-
maCurrentFill.maBgColor = Color(alpha, red, green, blue);
1589+
// Ignore the alpha element for now.
1590+
maCurrentFill.maBgColor = Color(red, green, blue);
15861591
maCurrentFill.mbHasFillAttr = true;
15871592
}
15881593

0 commit comments

Comments
 (0)