diff options
Diffstat (limited to 'svx/source/styles')
-rw-r--r-- | svx/source/styles/ColorSets.cxx | 107 | ||||
-rw-r--r-- | svx/source/styles/CommonStyleManager.cxx | 26 | ||||
-rw-r--r-- | svx/source/styles/CommonStylePreviewRenderer.cxx | 228 |
3 files changed, 361 insertions, 0 deletions
diff --git a/svx/source/styles/ColorSets.cxx b/svx/source/styles/ColorSets.cxx new file mode 100644 index 000000000..2e7771cae --- /dev/null +++ b/svx/source/styles/ColorSets.cxx @@ -0,0 +1,107 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + */ + +#include <svx/ColorSets.hxx> + +namespace svx +{ + +ColorSet::ColorSet(OUString const & aColorSetName) + : maColorSetName(aColorSetName) + , maColors(12) +{} + +ColorSets::ColorSets() +{} + +ColorSets::~ColorSets() +{} + +void ColorSets::init() +{ + { + ColorSet aColorSet("Breeze"); + aColorSet.add(0, 0x232629); + aColorSet.add(1, 0xFCFCFC); + aColorSet.add(2, 0x31363B); + aColorSet.add(3, 0xEFF0F1); + aColorSet.add(4, 0xDA4453); + aColorSet.add(5, 0xF47750); + aColorSet.add(6, 0xFDBC4B); + aColorSet.add(7, 0xC9CE3B); + aColorSet.add(8, 0x1CDC9A); + aColorSet.add(9, 0x2ECC71); + aColorSet.add(10, 0x1D99F3); + aColorSet.add(11, 0x3DAEE9); + maColorSets.push_back(aColorSet); + } + { + ColorSet aColorSet("Material Blue"); + aColorSet.add(0, 0x212121); + aColorSet.add(1, 0xFFFFFF); + aColorSet.add(2, 0x37474F); + aColorSet.add(3, 0xECEFF1); + aColorSet.add(4, 0x7986CB); + aColorSet.add(5, 0x303F9F); + aColorSet.add(6, 0x64B5F6); + aColorSet.add(7, 0x1976D2); + aColorSet.add(8, 0x4FC3F7); + aColorSet.add(9, 0x0277BD); + aColorSet.add(10, 0x4DD0E1); + aColorSet.add(11, 0x0097A7); + maColorSets.push_back(aColorSet); + } + { + ColorSet aColorSet("Material Red"); + aColorSet.add(0, 0x212121); + aColorSet.add(1, 0xFFFFFF); + aColorSet.add(2, 0x424242); + aColorSet.add(3, 0xF5F5F5); + aColorSet.add(4, 0xFF9800); + aColorSet.add(5, 0xFF6D00); + aColorSet.add(6, 0xFF5722); + aColorSet.add(7, 0xDD2C00); + aColorSet.add(8, 0xF44336); + aColorSet.add(9, 0xD50000); + aColorSet.add(10, 0xE91E63); + aColorSet.add(11, 0xC51162); + maColorSets.push_back(aColorSet); + } + { + ColorSet aColorSet("Material Green"); + aColorSet.add(0, 0x212121); + aColorSet.add(1, 0xFFFFFF); + aColorSet.add(2, 0x424242); + aColorSet.add(3, 0xF5F5F5); + aColorSet.add(4, 0x009688); + aColorSet.add(5, 0x00bfa5); + aColorSet.add(6, 0x4caf50); + aColorSet.add(7, 0x00c853); + aColorSet.add(8, 0x8bc34a); + aColorSet.add(9, 0x64dd17); + aColorSet.add(10, 0xcddc39); + aColorSet.add(11, 0xaeea00); + maColorSets.push_back(aColorSet); + } +} + +const ColorSet& ColorSets::getColorSet(const OUString& rName) +{ + for (const ColorSet & rColorSet : maColorSets) + { + if (rColorSet.getName() == rName) + return rColorSet; + } + return maColorSets[0]; +} + +} // end of namespace svx + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svx/source/styles/CommonStyleManager.cxx b/svx/source/styles/CommonStyleManager.cxx new file mode 100644 index 000000000..d1fc8dbf6 --- /dev/null +++ b/svx/source/styles/CommonStyleManager.cxx @@ -0,0 +1,26 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + */ + +#include <svx/CommonStyleManager.hxx> +#include <CommonStylePreviewRenderer.hxx> + +namespace svx +{ + +std::unique_ptr<sfx2::StylePreviewRenderer> CommonStyleManager::CreateStylePreviewRenderer( + OutputDevice& rOutputDev, SfxStyleSheetBase* pStyle, + long nMaxHeight) +{ + return std::unique_ptr<sfx2::StylePreviewRenderer>(new CommonStylePreviewRenderer(mrShell, rOutputDev, pStyle, nMaxHeight)); +} + +} // end svx namespace + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svx/source/styles/CommonStylePreviewRenderer.cxx b/svx/source/styles/CommonStylePreviewRenderer.cxx new file mode 100644 index 000000000..9920903df --- /dev/null +++ b/svx/source/styles/CommonStylePreviewRenderer.cxx @@ -0,0 +1,228 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + */ + +#include <memory> +#include <CommonStylePreviewRenderer.hxx> + +#include <sfx2/objsh.hxx> +#include <svl/style.hxx> +#include <svl/itemset.hxx> +#include <vcl/outdev.hxx> + +#include <com/sun/star/drawing/FillStyle.hpp> +#include <svx/xdef.hxx> +#include <svx/xfillit0.hxx> +#include <svx/xflclit.hxx> +#include <editeng/fontitem.hxx> +#include <editeng/fhgtitem.hxx> +#include <editeng/charreliefitem.hxx> +#include <editeng/contouritem.hxx> +#include <editeng/colritem.hxx> +#include <editeng/crossedoutitem.hxx> +#include <editeng/emphasismarkitem.hxx> +#include <editeng/postitem.hxx> +#include <editeng/shdditem.hxx> +#include <editeng/udlnitem.hxx> +#include <editeng/wghtitem.hxx> +#include <editeng/svxfont.hxx> +#include <editeng/cmapitem.hxx> + +#include <editeng/editids.hrc> + +using namespace css; + +namespace svx +{ + +CommonStylePreviewRenderer::CommonStylePreviewRenderer( + const SfxObjectShell& rShell, OutputDevice& rOutputDev, + SfxStyleSheetBase* pStyle, long nMaxHeight) + : StylePreviewRenderer(rShell, rOutputDev, pStyle, nMaxHeight) + , m_pFont() + , maFontColor(COL_AUTO) + , maBackgroundColor(COL_AUTO) + , maPixelSize() + , maStyleName(mpStyle->GetName()) +{ +} + +CommonStylePreviewRenderer::~CommonStylePreviewRenderer() +{} + +bool CommonStylePreviewRenderer::recalculate() +{ + m_pFont.reset(); + + std::unique_ptr<SfxItemSet> pItemSet(mpStyle->GetItemSetForPreview()); + + if (!pItemSet) return false; + + std::unique_ptr<SvxFont> pFont(new SvxFont); + + const SfxPoolItem* pItem; + + if ((pItem = pItemSet->GetItem(SID_ATTR_CHAR_WEIGHT)) != nullptr) + { + pFont->SetWeight(static_cast<const SvxWeightItem*>(pItem)->GetWeight()); + } + if ((pItem = pItemSet->GetItem(SID_ATTR_CHAR_POSTURE)) != nullptr) + { + pFont->SetItalic(static_cast<const SvxPostureItem*>(pItem)->GetPosture()); + } + if ((pItem = pItemSet->GetItem(SID_ATTR_CHAR_CONTOUR)) != nullptr) + { + pFont->SetOutline(static_cast< const SvxContourItem*>(pItem)->GetValue()); + } + if ((pItem = pItemSet->GetItem(SID_ATTR_CHAR_SHADOWED)) != nullptr) + { + pFont->SetShadow(static_cast<const SvxShadowedItem*>(pItem)->GetValue()); + } + if ((pItem = pItemSet->GetItem(SID_ATTR_CHAR_RELIEF)) != nullptr) + { + pFont->SetRelief(static_cast<const SvxCharReliefItem*>(pItem)->GetValue()); + } + if ((pItem = pItemSet->GetItem(SID_ATTR_CHAR_UNDERLINE)) != nullptr) + { + pFont->SetUnderline(static_cast< const SvxUnderlineItem*>(pItem)->GetLineStyle()); + } + if ((pItem = pItemSet->GetItem(SID_ATTR_CHAR_OVERLINE)) != nullptr) + { + pFont->SetOverline(static_cast<const SvxOverlineItem*>(pItem)->GetValue()); + } + if ((pItem = pItemSet->GetItem(SID_ATTR_CHAR_STRIKEOUT)) != nullptr) + { + pFont->SetStrikeout(static_cast<const SvxCrossedOutItem*>(pItem)->GetStrikeout()); + } + if ((pItem = pItemSet->GetItem(SID_ATTR_CHAR_CASEMAP)) != nullptr) + { + pFont->SetCaseMap(static_cast<const SvxCaseMapItem*>(pItem)->GetCaseMap()); + } + if ((pItem = pItemSet->GetItem(SID_ATTR_CHAR_EMPHASISMARK)) != nullptr) + { + pFont->SetEmphasisMark(static_cast<const SvxEmphasisMarkItem*>(pItem)->GetEmphasisMark()); + } + if ((pItem = pItemSet->GetItem(SID_ATTR_CHAR_COLOR)) != nullptr) + { + maFontColor = static_cast<const SvxColorItem*>(pItem)->GetValue(); + } + + if (mpStyle->GetFamily() == SfxStyleFamily::Para) + { + if ((pItem = pItemSet->GetItem(XATTR_FILLSTYLE)) != nullptr) + { + css::drawing::FillStyle aFillStyle = static_cast<const XFillStyleItem*>(pItem)->GetValue(); + if (aFillStyle == drawing::FillStyle_SOLID) + { + if ((pItem = pItemSet->GetItem(XATTR_FILLCOLOR)) != nullptr) + { + maBackgroundColor = static_cast<const XFillColorItem*>(pItem)->GetColorValue(); + } + } + } + } + + if ((pItem = pItemSet->GetItem(SID_ATTR_CHAR_FONT)) != nullptr) + { + const SvxFontItem* pFontItem = static_cast<const SvxFontItem*>(pItem); + if (IsStarSymbol(pFontItem->GetFamilyName())) + return false; + pFont->SetFamilyName(pFontItem->GetFamilyName()); + pFont->SetStyleName(pFontItem->GetStyleName()); + } + else + { + return false; + } + + if ((pItem = pItemSet->GetItem(SID_ATTR_CHAR_FONTHEIGHT)) != nullptr) + { + const SvxFontHeightItem* pFontHeightItem = static_cast<const SvxFontHeightItem*>(pItem); + Size aFontSize(0, pFontHeightItem->GetHeight()); + maPixelSize = mrOutputDev.LogicToPixel(aFontSize, MapMode(mrShell.GetMapUnit())); + pFont->SetFontSize(maPixelSize); + + vcl::Font aOldFont(mrOutputDev.GetFont()); + + mrOutputDev.SetFont(*pFont); + tools::Rectangle aTextRect; + mrOutputDev.GetTextBoundRect(aTextRect, mpStyle->GetName()); + if (aTextRect.Bottom() > mnMaxHeight) + { + double ratio = double(mnMaxHeight) / aTextRect.Bottom(); + maPixelSize.setWidth( maPixelSize.Width() * ratio ); + maPixelSize.setHeight( maPixelSize.Height() * ratio ); + pFont->SetFontSize(maPixelSize); + } + mrOutputDev.SetFont(aOldFont); + } + else + { + return false; + } + + m_pFont = std::move(pFont); + maPixelSize = getRenderSize(); + return true; +} + +Size CommonStylePreviewRenderer::getRenderSize() const +{ + assert(m_pFont); + Size aPixelSize = m_pFont->GetTextSize(&mrOutputDev, maStyleName); + + if (aPixelSize.Height() > mnMaxHeight) + aPixelSize.setHeight( mnMaxHeight ); + + return aPixelSize; +} + +bool CommonStylePreviewRenderer::render(const tools::Rectangle& aRectangle, RenderAlign eRenderAlign) +{ + const OUString& rText = maStyleName; + + // setup the device & draw + vcl::Font aOldFont(mrOutputDev.GetFont()); + Color aOldColor(mrOutputDev.GetTextColor()); + Color aOldFillColor(mrOutputDev.GetFillColor()); + + if (maBackgroundColor != COL_AUTO) + { + mrOutputDev.SetFillColor(maBackgroundColor); + mrOutputDev.DrawRect(aRectangle); + } + + if (m_pFont) + { + mrOutputDev.SetFont(*m_pFont); + } + if (maFontColor != COL_AUTO) + mrOutputDev.SetTextColor(maFontColor); + + Size aPixelSize(m_pFont ? maPixelSize : mrOutputDev.GetFont().GetFontSize()); + + Point aFontDrawPosition = aRectangle.TopLeft(); + if (eRenderAlign == RenderAlign::CENTER) + { + if (aRectangle.GetHeight() > aPixelSize.Height()) + aFontDrawPosition.AdjustY((aRectangle.GetHeight() - aPixelSize.Height()) / 2 ); + } + + mrOutputDev.DrawText(aFontDrawPosition, rText); + + mrOutputDev.SetFillColor(aOldFillColor); + mrOutputDev.SetTextColor(aOldColor); + mrOutputDev.SetFont(aOldFont); + + return true; +} + +} // end svx namespace + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |