sc/inc/orcusfilters.hxx | 6 + sc/inc/stlpool.hxx | 3 sc/source/core/data/stlpool.cxx | 2 sc/source/filter/inc/orcusfiltersimpl.hxx | 2 sc/source/filter/inc/orcusinterface.hxx | 16 +++ sc/source/filter/orcus/interface.cxx | 128 +++++++++++++++++++++++----- sc/source/filter/orcus/orcusfiltersimpl.cxx | 40 ++++++++ sc/source/ui/docshell/docsh.cxx | 10 ++ sc/source/ui/docshell/docsh2.cxx | 11 ++ 9 files changed, 196 insertions(+), 22 deletions(-)
New commits: commit 5d20d942c9a045279537d99fbdb495d5617c68ec Author: Jaskaran Singh <[email protected]> Date: Wed Jul 13 12:22:49 2016 +0530 Add call to import ODF styles when spreadsheet is created or loaded Change-Id: If2f6843337f554829a321cfbe0b7dfdba90dca48 diff --git a/sc/source/ui/docshell/docsh.cxx b/sc/source/ui/docshell/docsh.cxx index 79cb8c8..c2367ef 100644 --- a/sc/source/ui/docshell/docsh.cxx +++ b/sc/source/ui/docshell/docsh.cxx @@ -109,6 +109,8 @@ #include "docshimp.hxx" #include "sizedev.hxx" #include "refreshtimerprotector.hxx" +#include <orcus/orcus_import_ods.hpp> +#include <orcusfiltersimpl.hxx> #include <officecfg/Office/Calc.hxx> #include <comphelper/processfactory.hxx> @@ -575,6 +577,14 @@ bool ScDocShell::Load( SfxMedium& rMedium ) aDocument.GetStyleSheetPool()->CreateStandardStyles(); aDocument.UpdStlShtPtrsFrmNms(); + /* Create styles that are imported through Orcus */ + + OUString aFileName = "styles.xml"; + ScOrcusFilters* pOrcus = ScFormatFilter::Get().GetOrcusFilters(); + if (!pOrcus) + return false; + pOrcus->importODS_Styles(aDocument, aFileName); + bRet = LoadXML( &rMedium, nullptr ); } } diff --git a/sc/source/ui/docshell/docsh2.cxx b/sc/source/ui/docshell/docsh2.cxx index 429a3f5..376b508 100644 --- a/sc/source/ui/docshell/docsh2.cxx +++ b/sc/source/ui/docshell/docsh2.cxx @@ -22,6 +22,8 @@ #include <svl/asiancfg.hxx> #include <editeng/forbiddencharacterstable.hxx> #include <editeng/unolingu.hxx> +#include <orcus/orcus_import_ods.hpp> +#include <orcusfiltersimpl.hxx> #include "drwlayer.hxx" #include "stlpool.hxx" @@ -29,6 +31,7 @@ #include "docshimp.hxx" #include "docfunc.hxx" #include "sc.hrc" +#include "filter.hxx" using namespace com::sun::star; @@ -53,6 +56,14 @@ bool ScDocShell::InitNew( const uno::Reference < embed::XStorage >& xStor ) aDocument.GetStyleSheetPool()->CreateStandardStyles(); aDocument.UpdStlShtPtrsFrmNms(); + /* Create styles that are imported through Orcus */ + + OUString aFileName = "styles.xml"; + ScOrcusFilters* pOrcus = ScFormatFilter::Get().GetOrcusFilters(); + if (!pOrcus) + return false; + pOrcus->importODS_Styles(aDocument, aFileName); + // SetDocumentModified is not allowed anymore in Load/InitNew! InitItems(); CalcOutputFactor(); commit 63729672032f6772f62cdfaeaf78392208612831 Author: Jaskaran Singh <[email protected]> Date: Tue Jul 12 17:37:59 2016 +0530 Implement Interface for Importing Styles via Orcus Change-Id: I2ec4cb1ad358e2e4a49e82e916a54fae81558937 diff --git a/sc/source/filter/inc/orcusinterface.hxx b/sc/source/filter/inc/orcusinterface.hxx index 8457eb2..b6b7c676 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<orcus::spreadsheet::border_direction_t, border_line> 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 db0c439..86e04f0 100644 --- a/sc/source/filter/orcus/interface.cxx +++ b/sc/source/filter/orcus/interface.cxx @@ -34,13 +34,21 @@ #include <editeng/charhiddenitem.hxx> #include <editeng/protitem.hxx> #include <editeng/prntitem.hxx> +#include <editeng/fontitem.hxx> +#include <editeng/fhgtitem.hxx> #include <formula/token.hxx> #include <tools/datetime.hxx> #include <svl/sharedstringpool.hxx> #include <o3tl/make_unique.hxx> - +#include <svl/zforlist.hxx> +#include <svl/intitem.hxx> #include <com/sun/star/task/XStatusIndicator.hpp> +#include <comphelper/processfactory.hxx> +#include <i18nlangtag/lang.h> +#include <vcl/outdev.hxx> +#include <tools/colordata.hxx> +#include <tools/fontenum.hxx> 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) @@ -989,11 +1056,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) { @@ -1023,6 +1091,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 */) @@ -1047,6 +1116,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, @@ -1083,16 +1153,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() @@ -1158,6 +1231,7 @@ void ScOrcusStyles::set_border_style( default: ; } + maCurrentBorder.mbHasBorderAttr = true; } void ScOrcusStyles::set_border_color(orcus::spreadsheet::border_direction_t dir, @@ -1188,21 +1262,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() @@ -1225,6 +1303,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() @@ -1356,6 +1435,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); @@ -1364,6 +1447,9 @@ size_t ScOrcusStyles::commit_cell_style() xf& rXf = maCellStyleXfs[maCurrentCellStyle.mnXFId]; applyXfToItemSet(rSet, rXf); + maCurrentXF = ScOrcusStyles::xf(); + maCurrentCellStyle = ScOrcusStyles::cell_style(); + return 0; } commit f5f22d7cc872f744798d0d9536563bbd77ecc923 Author: Jaskaran Singh <[email protected]> Date: Tue Jul 12 17:32:19 2016 +0530 Add a method to import ODF styles via orcus Change-Id: Id76593bbb9982ec6745737ade800ae669e8e4471 diff --git a/sc/inc/orcusfilters.hxx b/sc/inc/orcusfilters.hxx index 58e6fcb..e96facb 100644 --- a/sc/inc/orcusfilters.hxx +++ b/sc/inc/orcusfilters.hxx @@ -36,6 +36,12 @@ public: virtual bool importODS(ScDocument& rDoc, SfxMedium& rMedium) const = 0; /** + * Used to import just the styles from an xml file. + */ + + virtual bool importODS_Styles(ScDocument& rDoc, OUString& aFileName) const = 0; + + /** * Create a context for XML file. The context object stores session * information for each unique XML file. You must create a new context * for each XML file, and never to re-use the same context for multiple diff --git a/sc/source/filter/inc/orcusfiltersimpl.hxx b/sc/source/filter/inc/orcusfiltersimpl.hxx index 042fad2..1b95f84 100644 --- a/sc/source/filter/inc/orcusfiltersimpl.hxx +++ b/sc/source/filter/inc/orcusfiltersimpl.hxx @@ -25,6 +25,8 @@ public: virtual bool importXLSX(ScDocument& rDoc, SfxMedium& rMedium) const override; virtual bool importODS(ScDocument& rDoc, SfxMedium& rMedium) const override; + virtual bool importODS_Styles(ScDocument& rDoc, OUString& aFileName) const override; + virtual ScOrcusXMLContext* createXMLContext(ScDocument& rDoc, const OUString& rPath) const override; }; diff --git a/sc/source/filter/orcus/orcusfiltersimpl.cxx b/sc/source/filter/orcus/orcusfiltersimpl.cxx index c86ca3b..e16cc7f 100644 --- a/sc/source/filter/orcus/orcusfiltersimpl.cxx +++ b/sc/source/filter/orcus/orcusfiltersimpl.cxx @@ -17,14 +17,19 @@ #include <sfx2/frame.hxx> #include <sfx2/sfxsids.hrc> #include <svl/itemset.hxx> +#include <rtl/bootstrap.hxx> +#include <rtl/ustring.hxx> +#include <comphelper/string.hxx> #include <orcus/spreadsheet/import_interface.hpp> #include <orcus/orcus_csv.hpp> #include <orcus/orcus_gnumeric.hpp> #include <orcus/orcus_xlsx.hpp> #include <orcus/orcus_ods.hpp> +#include <orcus/orcus_import_ods.hpp> #include <orcus/global.hpp> - +#include <orcus/stream.hpp> +#include <orcus/orcus_import_ods.hpp> #include <com/sun/star/task/XStatusIndicator.hpp> #ifdef _WIN32 @@ -142,6 +147,39 @@ bool ScOrcusFiltersImpl::importODS(ScDocument& rDoc, SfxMedium& rMedium) const return true; } +bool ScOrcusFiltersImpl::importODS_Styles(ScDocument& rDoc, OUString& aFileName) const +{ + OUString aPath("$BRAND_BASE_DIR/"); /* Read the comment below before changing this */ + rtl::Bootstrap::expandMacros(aPath); + OUString aValidPath; + + /* The Following loop trims 'file://' from start of string and + * '../' from the end of string. If you ever happen to change the above macro + * please consider changing the following range too, otherwise app would + * crash!! + */ + for (sal_Int32 i = 7; i < aPath.getLength() - 3; ++i) + aValidPath += OUString(aPath[i]); + + aValidPath += aFileName; + OString aUrl = OUStringToOString(aValidPath, RTL_TEXTENCODING_UTF8); + const char* path = aUrl.getStr(); + + try + { + std::string content = orcus::load_file_content(path); + ScOrcusStyles styles(rDoc); + orcus::import_ods::read_styles(content.c_str(), content.size(), &styles); + } + catch (const std::exception& e) + { + SAL_WARN("sc", "Unable to load styles from xml file! " << e.what()); + return false; + } + + return true; +} + ScOrcusXMLContext* ScOrcusFiltersImpl::createXMLContext(ScDocument& rDoc, const OUString& rPath) const { return new ScOrcusXMLContextImpl(rDoc, rPath); commit f2a8dc2630f9f789adc554788864a15cd60ef18c Author: Jaskaran Singh <[email protected]> Date: Tue Jul 12 17:08:33 2016 +0530 Add to a method to check if stlpool already has standard styles Change-Id: I9173b0232d466a27cf8a7b35e0a9f0567b398115 diff --git a/sc/inc/stlpool.hxx b/sc/inc/stlpool.hxx index 74d815f..af98861 100644 --- a/sc/inc/stlpool.hxx +++ b/sc/inc/stlpool.hxx @@ -49,6 +49,8 @@ public: void CopyStyleFrom( ScStyleSheetPool* pSrcPool, const OUString& rName, SfxStyleFamily eFamily ); + bool HasStandardStyles() { return bHasStandardStyles; } + ScStyleSheet* FindCaseIns( const OUString& rName, SfxStyleFamily eFam ); const OUString* GetForceStdName() const { return pForceStdName; } @@ -70,6 +72,7 @@ private: SfxStyleSheetBase* pActualStyleSheet; ScDocument* pDoc; const OUString* pForceStdName; + bool bHasStandardStyles; }; #endif // INCLUDED_SC_INC_STLPOOL_HXX diff --git a/sc/source/core/data/stlpool.cxx b/sc/source/core/data/stlpool.cxx index 9b2a5ce..e89cbfc 100644 --- a/sc/source/core/data/stlpool.cxx +++ b/sc/source/core/data/stlpool.cxx @@ -434,6 +434,8 @@ void ScStyleSheetPool::CreateStandardStyles() delete pTxtObj; delete pEmptyTxtObj; + + bHasStandardStyles = true; } namespace { _______________________________________________ Libreoffice-commits mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
