From 15222c789ab5f5ee93eed1a3a3b8a44e362bae2c Mon Sep 17 00:00:00 2001 From: Jaskaran Singh Date: Tue, 12 Jul 2016 17:37:59 +0530 Subject: Implement Interface for Importing Styles via Orcus Change-Id: I2ec4cb1ad358e2e4a49e82e916a54fae81558937 --- sc/source/filter/inc/orcusinterface.hxx | 16 ++++ sc/source/filter/orcus/interface.cxx | 128 ++++++++++++++++++++++++++------ 2 files changed, 123 insertions(+), 21 deletions(-) diff --git a/sc/source/filter/inc/orcusinterface.hxx b/sc/source/filter/inc/orcusinterface.hxx index dfecde4aa08e..c33151ee97d7 100644 --- a/sc/source/filter/inc/orcusinterface.hxx +++ b/sc/source/filter/inc/orcusinterface.hxx @@ -258,7 +258,12 @@ private: double mnSize; Color maColor; + bool mbHasFontAttr; + bool mbHasUnderlineAttr; + FontLineStyle meUnderline; + FontLineStyle meUnderlineType; + FontLineStyle meUnderlineWidth; Color maUnderlineColor; font(); @@ -275,6 +280,10 @@ private: Color maFgColor; Color maBgColor; + bool mbHasFillAttr; + + fill(); + void applyToItemSet(SfxItemSet& rSet) const; }; @@ -291,6 +300,8 @@ private: }; std::map border_lines; + bool mbHasBorderAttr; + border(); void applyToItemSet(SfxItemSet& rSet) const; @@ -306,6 +317,8 @@ private: bool mbPrintContent; bool mbFormulaHidden; + bool mbHasProtectionAttr; + protection(); void applyToItemSet(SfxItemSet& rSet) const; }; @@ -317,6 +330,9 @@ private: { OUString maCode; + bool mbHasNumberFormatAttr; + + number_format(); void applyToItemSet(SfxItemSet& rSet) const; }; diff --git a/sc/source/filter/orcus/interface.cxx b/sc/source/filter/orcus/interface.cxx index c10a4e6e4c2e..846ef078d3ac 100644 --- a/sc/source/filter/orcus/interface.cxx +++ b/sc/source/filter/orcus/interface.cxx @@ -34,13 +34,21 @@ #include #include #include +#include +#include #include #include #include #include - +#include +#include #include +#include +#include +#include +#include +#include using namespace com::sun::star; @@ -736,14 +744,32 @@ size_t ScOrcusSharedStrings::commit_segments() ScOrcusStyles::ScOrcusStyles(ScDocument& rDoc): mrDoc(rDoc) { - mrDoc.GetStyleSheetPool()->CreateStandardStyles(); + if (!mrDoc.GetStyleSheetPool()->HasStandardStyles()) + mrDoc.GetStyleSheetPool()->CreateStandardStyles(); } ScOrcusStyles::font::font(): mbBold(false), mbItalic(false), + mbHasFontAttr(false), + mbHasUnderlineAttr(false), mnSize(10), - meUnderline(LINESTYLE_NONE) + meUnderline(LINESTYLE_NONE), + maColor(COL_WHITE, COL_WHITE, COL_WHITE, COL_WHITE) +{ +} + +ScOrcusStyles::fill::fill(): + maPattern(""), + maFgColor(Color(COL_WHITE, COL_WHITE, COL_WHITE)), + maBgColor(Color(COL_WHITE, COL_WHITE, COL_WHITE)), + mbHasFillAttr(false) +{ +} + +ScOrcusStyles::number_format::number_format(): + maCode(""), + mbHasNumberFormatAttr(false) { } @@ -767,9 +793,15 @@ void ScOrcusStyles::font::applyToItemSet(SfxItemSet& rSet) const FontWeight eWeight = mbBold ? WEIGHT_BOLD : WEIGHT_NORMAL; rSet.Put(SvxWeightItem(eWeight, ATTR_FONT_WEIGHT)); - rSet.Put(SvxColorItem(maColor, ATTR_FONT_COLOR)); - rSet.Put(SvxUnderlineItem(meUnderline, ATTR_FONT_UNDERLINE)); - rSet.Put(SvxColorItem(maUnderlineColor, ATTR_FONT_UNDERLINE)); + if (mbHasUnderlineAttr) + { + rSet.Put(SvxUnderlineItem(meUnderline, ATTR_FONT_UNDERLINE)); + rSet.Put(SvxColorItem(maUnderlineColor, ATTR_FONT_UNDERLINE)); + } + + rSet.Put( SvxColorItem(maColor, ATTR_FONT_COLOR)); + rSet.Put( SvxFontItem( FAMILY_DONTKNOW, maName, maName, PITCH_DONTKNOW, RTL_TEXTENCODING_DONTKNOW, ATTR_FONT )); + rSet.Put( SvxFontHeightItem (translateToInternal(mnSize, orcus::length_unit_t::point), 100, ATTR_FONT_HEIGHT)); } void ScOrcusStyles::fill::applyToItemSet(SfxItemSet& rSet) const @@ -785,20 +817,35 @@ void ScOrcusStyles::fill::applyToItemSet(SfxItemSet& rSet) const ScOrcusStyles::protection::protection(): mbHidden(false), - mbLocked(false) + mbLocked(true), + mbPrintContent(false), + mbFormulaHidden(false), + mbHasProtectionAttr(true) { } void ScOrcusStyles::protection::applyToItemSet(SfxItemSet& rSet) const { - rSet.Put(SvxCharHiddenItem(mbHidden, ATTR_PROTECTION)); + if (mbHidden) + rSet.Put(SvxCharHiddenItem(mbHidden, ATTR_PROTECTION)); + + if (!mbLocked) + { + SvxProtectItem aItem(ATTR_PROTECTION); - if (mbLocked) - rSet.Put(SvxProtectItem(ATTR_PROTECTION)); - rSet.Put(SvxPrintItem(ATTR_PROTECTION, mbPrintContent)); + aItem.SetContentProtect (false); + aItem.SetSizeProtect (false); + aItem.SetPosProtect (false); + + rSet.Put(aItem); + } + + if (!mbPrintContent) + rSet.Put(SvxPrintItem(ATTR_PROTECTION, mbPrintContent)); } -ScOrcusStyles::border::border() +ScOrcusStyles::border::border(): + mbHasBorderAttr(false) { } @@ -835,16 +882,30 @@ void ScOrcusStyles::border::applyToItemSet(SfxItemSet& rSet) const for (auto& current_border_line : border_lines) { SvxBoxItemLine eDir = getDirection(current_border_line.first); - editeng::SvxBorderLine aLine(¤t_border_line.second.maColor, 1); + editeng::SvxBorderLine aLine(¤t_border_line.second.maColor, current_border_line.second.mnWidth, current_border_line.second.mestyle); aItem.SetLine(&aLine, eDir); } rSet.Put(aItem); } -void ScOrcusStyles::number_format::applyToItemSet(SfxItemSet& /*rSet*/) const +void ScOrcusStyles::number_format::applyToItemSet(SfxItemSet& rSet) const { - (void)this; // loplugin:staticmethods + sal_uInt32 nKey; + sal_Int32 nCheckPos; + SvNumberFormatter NumberFormatter(comphelper::getProcessComponentContext(), LANGUAGE_ENGLISH_US); + OUString Code = maCode; /* <-- Done because the SvNumberFormatter::PutEntry demands a non const NumFormat Code*/ + sal_Int16 type = css::util::NumberFormat::ALL; + + if (NumberFormatter.PutEntry(Code, nCheckPos, type, nKey, LANGUAGE_ENGLISH_US)) + { + if (nCheckPos == 0) + { + rSet.Put(SfxUInt32Item(nKey, ATTR_VALUE_FORMAT)); + } + } + else + SAL_WARN("sc.orcus.style", "Cannot set Number Format"); } ScOrcusStyles::xf::xf(): @@ -873,7 +934,8 @@ void ScOrcusStyles::applyXfToItemSet(SfxItemSet& rSet, const xf& rXf) } const font& rFont = maFonts[nFontId]; - rFont.applyToItemSet(rSet); + if (rFont.mbHasFontAttr) + rFont.applyToItemSet(rSet); size_t nFillId = rXf.mnFillId; if (nFillId >= maFills.size()) @@ -883,7 +945,8 @@ void ScOrcusStyles::applyXfToItemSet(SfxItemSet& rSet, const xf& rXf) } const fill& rFill = maFills[nFillId]; - rFill.applyToItemSet(rSet); + if (rFill.mbHasFillAttr) + rFill.applyToItemSet(rSet); size_t nBorderId = rXf.mnBorderId; if (nBorderId >= maBorders.size()) @@ -892,7 +955,8 @@ void ScOrcusStyles::applyXfToItemSet(SfxItemSet& rSet, const xf& rXf) return; } const border& rBorder = maBorders[nBorderId]; - rBorder.applyToItemSet(rSet); + if (rBorder.mbHasBorderAttr) + rBorder.applyToItemSet(rSet); size_t nProtectionId = rXf.mnProtectionId; if (nProtectionId >= maProtections.size()) @@ -901,7 +965,8 @@ void ScOrcusStyles::applyXfToItemSet(SfxItemSet& rSet, const xf& rXf) return; } const protection& rProtection = maProtections[nProtectionId]; - rProtection.applyToItemSet(rSet); + if (rProtection.mbHasProtectionAttr) + rProtection.applyToItemSet(rSet); size_t nNumberFormatId = rXf.mnNumberFormatId; if (nNumberFormatId >= maNumberFormats.size()) @@ -910,7 +975,8 @@ void ScOrcusStyles::applyXfToItemSet(SfxItemSet& rSet, const xf& rXf) return; } const number_format& rFormat = maNumberFormats[nNumberFormatId]; - rFormat.applyToItemSet(rSet); + if (rFormat.mbHasNumberFormatAttr) + rFormat.applyToItemSet(rSet); } void ScOrcusStyles::applyXfToItemSet(SfxItemSet& rSet, size_t xfId) @@ -945,6 +1011,7 @@ void ScOrcusStyles::set_font_name(const char* s, size_t n) { OUString aName(s, n, RTL_TEXTENCODING_UTF8); maCurrentFont.maName = aName; + maCurrentFont.mbHasFontAttr = true; } void ScOrcusStyles::set_font_size(double point) @@ -988,11 +1055,12 @@ void ScOrcusStyles::set_font_underline(orcus::spreadsheet::underline_t e) default: ; } + maCurrentFont.mbHasUnderlineAttr = true; } void ScOrcusStyles::set_font_underline_width(orcus::spreadsheet::underline_width_t e ) { - if (e == orcus::spreadsheet::underline_width_t::bold) + if (e == orcus::spreadsheet::underline_width_t::bold || e == orcus::spreadsheet::underline_width_t::thick) { switch(maCurrentFont.meUnderline) { @@ -1022,6 +1090,7 @@ void ScOrcusStyles::set_font_underline_width(orcus::spreadsheet::underline_width ; } } + maCurrentFont.mbHasUnderlineAttr = true; } void ScOrcusStyles::set_font_underline_mode(orcus::spreadsheet::underline_mode_t /* e */) @@ -1046,6 +1115,7 @@ void ScOrcusStyles::set_font_underline_type(orcus::spreadsheet::underline_type_t ; } } + maCurrentFont.mbHasUnderlineAttr = true; } void ScOrcusStyles::set_font_underline_color(orcus::spreadsheet::color_elem_t alpha, @@ -1082,16 +1152,19 @@ void ScOrcusStyles::set_fill_count(size_t /*n*/) void ScOrcusStyles::set_fill_pattern_type(const char* s, size_t n) { maCurrentFill.maPattern = OUString(s, n, RTL_TEXTENCODING_UTF8); + maCurrentFill.mbHasFillAttr = true; } 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) { maCurrentFill.maFgColor = Color(alpha, red, green, blue); + maCurrentFill.mbHasFillAttr = true; } 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) { maCurrentFill.maBgColor = Color(alpha, red, green, blue); + maCurrentFill.mbHasFillAttr = true; } size_t ScOrcusStyles::commit_fill() @@ -1157,6 +1230,7 @@ void ScOrcusStyles::set_border_style( default: ; } + maCurrentBorder.mbHasBorderAttr = true; } void ScOrcusStyles::set_border_color(orcus::spreadsheet::border_direction_t dir, @@ -1187,21 +1261,25 @@ size_t ScOrcusStyles::commit_border() void ScOrcusStyles::set_cell_hidden(bool b) { maCurrentProtection.mbHidden = b; + maCurrentProtection.mbHasProtectionAttr = true; } void ScOrcusStyles::set_cell_locked(bool b) { maCurrentProtection.mbLocked = b; + maCurrentProtection.mbHasProtectionAttr = true; } void ScOrcusStyles::set_cell_print_content(bool b ) { maCurrentProtection.mbPrintContent = b; + maCurrentProtection.mbHasProtectionAttr = true; } void ScOrcusStyles::set_cell_formula_hidden(bool b ) { maCurrentProtection.mbFormulaHidden = b; + maCurrentProtection.mbHasProtectionAttr = true; } size_t ScOrcusStyles::commit_cell_protection() @@ -1224,6 +1302,7 @@ void ScOrcusStyles::set_number_format_code(const char* s, size_t n) { OUString aCode(s, n, RTL_TEXTENCODING_UTF8); maCurrentNumberFormat.maCode = aCode; + maCurrentNumberFormat.mbHasNumberFormatAttr = true; } size_t ScOrcusStyles::commit_number_format() @@ -1355,6 +1434,10 @@ size_t ScOrcusStyles::commit_cell_style() SAL_WARN("sc.orcus.style", "invalid xf id for commit cell style"); return 0; } + if (maCurrentCellStyle.mnXFId == 0) + { + return 0; + } ScStyleSheetPool* pPool = mrDoc.GetStyleSheetPool(); SfxStyleSheetBase& rBase = pPool->Make(maCurrentCellStyle.maName, SfxStyleFamily::Para); @@ -1363,6 +1446,9 @@ size_t ScOrcusStyles::commit_cell_style() xf& rXf = maCellStyleXfs[maCurrentCellStyle.mnXFId]; applyXfToItemSet(rSet, rXf); + maCurrentXF = ScOrcusStyles::xf(); + maCurrentCellStyle = ScOrcusStyles::cell_style(); + return 0; } -- cgit