diff options
Diffstat (limited to '')
-rw-r--r-- | include/docmodel/color/ComplexColor.hxx | 283 | ||||
-rw-r--r-- | include/docmodel/color/ComplexColorJSON.hxx | 27 | ||||
-rw-r--r-- | include/docmodel/color/Transformation.hxx | 91 | ||||
-rw-r--r-- | include/docmodel/dllapi.h | 21 | ||||
-rw-r--r-- | include/docmodel/theme/ColorSet.hxx | 47 | ||||
-rw-r--r-- | include/docmodel/theme/FormatScheme.hxx | 613 | ||||
-rw-r--r-- | include/docmodel/theme/Theme.hxx | 197 | ||||
-rw-r--r-- | include/docmodel/theme/ThemeColorType.hxx | 51 | ||||
-rw-r--r-- | include/docmodel/uno/UnoComplexColor.hxx | 49 | ||||
-rw-r--r-- | include/docmodel/uno/UnoGradientTools.hxx | 33 | ||||
-rw-r--r-- | include/docmodel/uno/UnoTheme.hxx | 46 |
11 files changed, 1458 insertions, 0 deletions
diff --git a/include/docmodel/color/ComplexColor.hxx b/include/docmodel/color/ComplexColor.hxx new file mode 100644 index 0000000000..01709b12f0 --- /dev/null +++ b/include/docmodel/color/ComplexColor.hxx @@ -0,0 +1,283 @@ +/* -*- 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/. + * + */ + +#pragma once + +#include <docmodel/dllapi.h> +#include <tools/color.hxx> +#include <docmodel/theme/ThemeColorType.hxx> +#include <docmodel/color/Transformation.hxx> +#include <o3tl/hash_combine.hxx> + +#include <vector> + +namespace model +{ +enum class ColorType +{ + Unused, + RGB, + CRGB, + HSL, + Theme, + Palette, + System, + Placeholder +}; + +enum class SystemColorType +{ + Unused, + DarkShadow3D, + Light3D, + ActiveBorder, + ActiveCaption, + AppWorkspace, + Background, + ButtonFace, + ButtonHighlight, + ButtonShadow, + ButtonText, + CaptionText, + GradientActiveCaption, + GradientInactiveCaption, + GrayText, + Highlight, + HighlightText, + HotLight, + InactiveBorder, + InactiveCaption, + InactiveCaptionText, + InfoBack, + InfoText, + Menu, + MenuBar, + MenuHighlight, + MenuText, + ScrollBar, + Window, + WindowFrame, + WindowText +}; + +/** Definition of a color with multiple representations + * + * A color that can be expresses as a RGB, CRGB or HSL representation or + * a more abstract representation as for example system color, palette, + * theme color or a placeholder. In these representations the + * color needs to be additionally + * + * The color can also have transformations defined, which in addition + * manipulates the resulting color (i.e. tints, shades, alpha,...). + */ +class DOCMODEL_DLLPUBLIC ComplexColor +{ +private: + ColorType meType = ColorType::Unused; + + double mnComponent1 = 0.0; // Red, Hue + double mnComponent2 = 0.0; // Green, Saturation + double mnComponent3 = 0.0; // Blue, Luminance + + SystemColorType meSystemColorType = SystemColorType::Unused; + ::Color maLastColor; + + ThemeColorType meThemeColorType = ThemeColorType::Unknown; + ThemeColorUsage meThemeColorUsage = ThemeColorUsage::Unknown; + + std::vector<Transformation> maTransformations; + + ::Color maFinalColor; + +public: + ColorType getType() const { return meType; } + void setType(ColorType eType) { meType = eType; } + + ThemeColorType getThemeColorType() const { return meThemeColorType; } + bool isValidThemeType() const + { + return meType == model::ColorType::Theme && meThemeColorType != ThemeColorType::Unknown; + } + + ThemeColorUsage getThemeColorUsage() const { return meThemeColorUsage; } + void setThemeColorUsage(ThemeColorUsage eThemeColorUsage) + { + meThemeColorUsage = eThemeColorUsage; + } + + SystemColorType getSystemColorType() const { return meSystemColorType; } + + void setSystemColorType(SystemColorType eSystemColorType) + { + meSystemColorType = eSystemColorType; + meType = ColorType::System; + } + + Color getRGBColor() const { return Color(mnComponent1, mnComponent2, mnComponent3); } + + std::vector<Transformation> const& getTransformations() const { return maTransformations; } + + void setTransformations(std::vector<Transformation> const& rTransformations) + { + maTransformations = rTransformations; + } + + void addTransformation(Transformation const& rTransform) + { + maTransformations.push_back(rTransform); + } + + void removeTransformations(TransformationType eType) + { + std::erase_if(maTransformations, [eType](Transformation const& rTransform) { + return rTransform.meType == eType; + }); + } + + void clearTransformations() { maTransformations.clear(); } + + double getRed() const { return mnComponent1; } + double getGreen() const { return mnComponent2; } + double getBlue() const { return mnComponent3; } + + void setCRGB(sal_Int32 nR, sal_Int32 nG, sal_Int32 nB) + { + mnComponent1 = nR; + mnComponent2 = nG; + mnComponent3 = nB; + meType = ColorType::CRGB; + } + + Color getRGB() const { return Color(mnComponent1, mnComponent2, mnComponent3); } + + void setColor(Color const& rColor) + { + mnComponent1 = rColor.GetRed(); + mnComponent2 = rColor.GetGreen(); + mnComponent3 = rColor.GetBlue(); + maFinalColor = rColor; + meType = ColorType::RGB; + } + + void setRGB(sal_Int32 nRGB) + { + ::Color aColor(ColorTransparency, nRGB); + setColor(aColor); + } + + void setHSL(sal_Int32 nH, sal_Int32 nS, sal_Int32 nL) + { + mnComponent1 = nH; + mnComponent2 = nS; + mnComponent3 = nL; + meType = ColorType::HSL; + } + + void setSystemColor(SystemColorType eSystemColorType, sal_Int32 nRGB) + { + maLastColor = ::Color(ColorTransparency, nRGB); + meSystemColorType = eSystemColorType; + meType = ColorType::System; + } + + void setThemePlaceholder() { meType = ColorType::Placeholder; } + + void setThemeColor(ThemeColorType eType) + { + meThemeColorType = eType; + meType = ColorType::Theme; + } + + bool operator==(const ComplexColor& rComplexColor) const + { + return meType == rComplexColor.meType && mnComponent1 == rComplexColor.mnComponent1 + && mnComponent2 == rComplexColor.mnComponent2 + && mnComponent3 == rComplexColor.mnComponent3 + && meSystemColorType == rComplexColor.meSystemColorType + && maLastColor == rComplexColor.maLastColor + && meThemeColorType == rComplexColor.meThemeColorType + && maTransformations.size() == rComplexColor.maTransformations.size() + && std::equal(maTransformations.begin(), maTransformations.end(), + rComplexColor.maTransformations.begin()); + } + + /** Applies the defined transformations to the input color */ + Color applyTransformations(Color const& rColor) const + { + Color aColor(rColor); + + for (auto const& rTransform : maTransformations) + { + switch (rTransform.meType) + { + case TransformationType::Tint: + aColor.ApplyTintOrShade(rTransform.mnValue); + break; + case TransformationType::Shade: + aColor.ApplyTintOrShade(-rTransform.mnValue); + break; + case TransformationType::LumMod: + aColor.ApplyLumModOff(rTransform.mnValue, 0); + break; + case TransformationType::LumOff: + aColor.ApplyLumModOff(10000, rTransform.mnValue); + break; + default: + break; + } + } + return aColor; + } + + void setFinalColor(Color const& rColor) { maFinalColor = rColor; } + + Color const& getFinalColor() const { return maFinalColor; } + + std::size_t getHash() const + { + std::size_t seed = 0; + o3tl::hash_combine(seed, meType); + o3tl::hash_combine(seed, mnComponent1); + o3tl::hash_combine(seed, mnComponent2); + o3tl::hash_combine(seed, mnComponent3); + o3tl::hash_combine(seed, meSystemColorType); + o3tl::hash_combine(seed, sal_uInt32(maLastColor)); + for (auto const& rTransform : maTransformations) + o3tl::hash_combine(seed, rTransform); + o3tl::hash_combine(seed, sal_uInt32(maFinalColor)); + return seed; + } + + static model::ComplexColor createRGB(Color const& rColor) + { + model::ComplexColor aComplexColor; + aComplexColor.setColor(rColor); + return aComplexColor; + } + + static model::ComplexColor Theme(ThemeColorType eThemeColorType) + { + model::ComplexColor aComplexColor; + aComplexColor.setThemeColor(eThemeColorType); + return aComplexColor; + } +}; + +} // end of namespace model + +namespace std +{ +template <> struct hash<model::ComplexColor> +{ + std::size_t operator()(model::ComplexColor const& rColor) const { return rColor.getHash(); } +}; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/docmodel/color/ComplexColorJSON.hxx b/include/docmodel/color/ComplexColorJSON.hxx new file mode 100644 index 0000000000..0f95bb2288 --- /dev/null +++ b/include/docmodel/color/ComplexColorJSON.hxx @@ -0,0 +1,27 @@ +/* -*- 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/. + * + */ + +#pragma once + +#include <docmodel/dllapi.h> +#include <docmodel/color/ComplexColor.hxx> +#include <boost/property_tree/ptree_fwd.hpp> + +namespace model::color +{ +DOCMODEL_DLLPUBLIC OString convertToJSON(model::ComplexColor const& rComplexColor); +DOCMODEL_DLLPUBLIC void convertToJSONTree(boost::property_tree::ptree& rTree, + model::ComplexColor const& rComplexColor); +DOCMODEL_DLLPUBLIC bool convertFromJSON(OString const& rJsonString, + model::ComplexColor& rComplexColor); + +} // end of namespace model + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/docmodel/color/Transformation.hxx b/include/docmodel/color/Transformation.hxx new file mode 100644 index 0000000000..fa98b013d0 --- /dev/null +++ b/include/docmodel/color/Transformation.hxx @@ -0,0 +1,91 @@ +/* -*- 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/. + * + */ + +#pragma once + +#include <docmodel/dllapi.h> +#include <o3tl/hash_combine.hxx> + +namespace model +{ +/** Color transformation type */ +enum class TransformationType +{ + Undefined, + Red, + RedMod, + RedOff, + Green, + GreenMod, + GreenOff, + Blue, + BlueMod, + BlueOff, + Alpha, + AlphaMod, + AlphaOff, + Hue, + HueMod, + HueOff, + Sat, + SatMod, + SatOff, + Lum, + LumMod, + LumOff, + Shade, + Tint, + Gray, + Comp, + Inv, + Gamma, + InvGamma +}; + +/** Definition of a color transformation. + * + * This just defines how a color should be transformed (changed). The + * type defines what kind of transformation should occur and the value + * defines by how much. + */ +struct DOCMODEL_DLLPUBLIC Transformation +{ + TransformationType meType = TransformationType::Undefined; + + sal_Int16 mnValue = 0; /// percentage value -10000 to +10000 + + bool operator==(const Transformation& rTransformation) const + { + return meType == rTransformation.meType && mnValue == rTransformation.mnValue; + } + + std::size_t getHash() const + { + std::size_t seed = 0; + o3tl::hash_combine(seed, meType); + o3tl::hash_combine(seed, mnValue); + return seed; + } +}; + +} // end of namespace model + +namespace std +{ +template <> struct hash<model::Transformation> +{ + std::size_t operator()(model::Transformation const& rTransformation) const + { + return rTransformation.getHash(); + } +}; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/docmodel/dllapi.h b/include/docmodel/dllapi.h new file mode 100644 index 0000000000..f90b7cc4c0 --- /dev/null +++ b/include/docmodel/dllapi.h @@ -0,0 +1,21 @@ +/* -*- 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/. + */ + +#pragma once + +#include <sal/types.h> + +#if defined(DOCMODEL_DLLIMPLEMENTATION) +#define DOCMODEL_DLLPUBLIC SAL_DLLPUBLIC_EXPORT +#else +#define DOCMODEL_DLLPUBLIC SAL_DLLPUBLIC_IMPORT +#endif +#define DOCMODEL_DLLPRIVATE SAL_DLLPRIVATE + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/docmodel/theme/ColorSet.hxx b/include/docmodel/theme/ColorSet.hxx new file mode 100644 index 0000000000..5bad82633c --- /dev/null +++ b/include/docmodel/theme/ColorSet.hxx @@ -0,0 +1,47 @@ +/* -*- 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/. + * + */ + +#pragma once + +#include <array> +#include <docmodel/dllapi.h> +#include <rtl/ustring.hxx> +#include <docmodel/theme/ThemeColorType.hxx> +#include <docmodel/color/ComplexColor.hxx> +#include <tools/color.hxx> + +typedef struct _xmlTextWriter* xmlTextWriterPtr; + +namespace model +{ +class DOCMODEL_DLLPUBLIC ColorSet +{ + OUString maName; + std::array<Color, 12> maColors; + +public: + ColorSet(OUString const& rName); + + void setName(OUString const& rName) { maName = rName; } + + void add(model::ThemeColorType Type, Color aColorData); + + const OUString& getName() const { return maName; } + + Color resolveColor(model::ComplexColor const& rComplexColor) const; + + Color getColor(model::ThemeColorType eType) const; + + void dumpAsXml(xmlTextWriterPtr pWriter) const; +}; + +} // end of namespace model + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/docmodel/theme/FormatScheme.hxx b/include/docmodel/theme/FormatScheme.hxx new file mode 100644 index 0000000000..eb1eea3fbd --- /dev/null +++ b/include/docmodel/theme/FormatScheme.hxx @@ -0,0 +1,613 @@ +/* -*- 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/. + * + */ + +#pragma once + +#include <docmodel/dllapi.h> +#include <docmodel/color/ComplexColor.hxx> +#include <com/sun/star/graphic/XGraphic.hpp> + +namespace model +{ +enum class FillType +{ + None, + Solid, + Gradient, + Pattern, + Blip +}; + +class DOCMODEL_DLLPUBLIC Fill +{ +public: + Fill(FillType eType) + : meType(eType) + { + } + + FillType meType; +}; + +class DOCMODEL_DLLPUBLIC NoFill : public Fill +{ +public: + NoFill() + : Fill(FillType::None) + { + } +}; + +class DOCMODEL_DLLPUBLIC SolidFill : public Fill +{ +public: + ComplexColor maColor; + + SolidFill() + : Fill(FillType::Solid) + { + } +}; + +class DOCMODEL_DLLPUBLIC GradientStop +{ +public: + double mfPosition = 0.0; // 0.0 - 1.0 + ComplexColor maColor; +}; + +enum class GradientType +{ + Undefined, + Linear, + Circle, + Rectangle, + Shape, +}; + +struct DOCMODEL_DLLPUBLIC LinearGradientProperties +{ + sal_Int32 mnAngle = 0; + bool mbScaled = false; +}; + +struct DOCMODEL_DLLPUBLIC RelativeRectangle +{ + sal_Int32 mnLeft = 0; + sal_Int32 mnTop = 0; + sal_Int32 mnRight = 0; + sal_Int32 mnBottom = 0; +}; + +class DOCMODEL_DLLPUBLIC GradientFill : public Fill +{ +public: + bool mbRotateWithShape = false; + GradientType meGradientType = GradientType::Undefined; + std::vector<GradientStop> maGradientStops; + LinearGradientProperties maLinearGradient; + RelativeRectangle maFillToRectangle; + RelativeRectangle maTileRectangle; + + GradientFill() + : Fill(FillType::Gradient) + { + } +}; + +enum class PatternPreset +{ + Unused, + Percent_5, + Percent_10, + Percent_20, + Percent_25, + Percent_30, + Percent_40, + Percent_50, + Percent_60, + Percent_70, + Percent_75, + Percent_80, + Percent_90, + Horizontal, + Vertical, + LightHorizontal, + LightVertical, + DarkHorizontal, + DarkVertical, + NarrowHorizontal, + NarrowVertical, + DashedHorizontal, + DashedVertical, + Cross, + DownwardDiagonal, + UpwardDiagonal, + LightDownwardDiagonal, + LightUpwardDiagonal, + DarkDownwardDiagonal, + DarkUpwardDiagonal, + WideDownwardDiagonal, + WideUpwardDiagonal, + DashedDownwardDiagonal, + DashedUpwardDiagonal, + DiagonalCross, + SmallCheckerBoard, + LargeCheckerBoard, + SmallGrid, + LargeGrid, + DottedGrid, + SmallConfetti, + LargeConfetti, + HorizontalBrick, + DiagonalBrick, + SolidDiamond, + OpenDiamond, + DottedDiamond, + Plaid, + Sphere, + Weave, + Divot, + Shingle, + Wave, + Trellis, + ZigZag +}; + +class DOCMODEL_DLLPUBLIC PatternFill : public Fill +{ +public: + PatternPreset mePatternPreset = PatternPreset::Unused; + ComplexColor maForegroundColor; + ComplexColor maBackgroundColor; + + PatternFill() + : Fill(FillType::Pattern) + { + } +}; + +enum class BitmapMode +{ + Unused, + Tile, + Stretch, +}; + +enum class FlipMode +{ + None, + X, + Y, + XY +}; + +enum class RectangleAlignment +{ + Unset, + TopLeft, + Top, + TopRight, + Left, + Center, + Right, + BottomLeft, + Bottom, + BottomRight +}; +constexpr sal_uInt16 RECTANGLE_ALIGNMENT_COUNT + = static_cast<sal_uInt16>(RectangleAlignment::BottomRight) + 1; + +enum class BlipEffectType +{ + None, + AlphaBiLevel, + AlphaCeiling, + AlphaFloor, + AlphaInverse, + AlphaModulate, + AlphaModulateFixed, + AlphaReplace, + BiLevel, + Blur, + ColorChange, + ColorReplace, + DuoTone, + FillOverlay, + Grayscale, + HSL, + Luminance, + Tint, +}; + +class BlipEffect +{ +public: + BlipEffectType meType = BlipEffectType::None; + + sal_Int32 mnThreshold = 0; // AlphaBiLevel, BiLevel + ComplexColor maColor1; // AlphaInverse, ColorReplace, DuoTone, ColorChange (from) + ComplexColor maColor2; // DuoTone, ColorChange (to) + sal_Int32 mnAmount = 0; // AlphaModulateFixed, Tint + sal_Int32 mnRadius = 0; // Blur + bool mbGrow = false; // Blur + sal_Int32 mnAlpha = 0; // AlphaReplace + bool mbUseAlpha = false; // ColorChange + sal_Int32 mnHue = 0; // HSL, Tint + sal_Int32 mnSaturation = 0; // HSL + sal_Int32 mnLuminance = 0; // HSL + sal_Int32 mnBrightness = 0; // Luminance + sal_Int32 mnContrast = 0; // Luminance + + ComplexColor& getColorFrom() { return maColor1; } + ComplexColor& getColorTo() { return maColor2; } +}; + +class DOCMODEL_DLLPUBLIC BlipFill : public Fill +{ +public: + bool mbRotateWithShape = false; + RelativeRectangle maClipRectangle; + RelativeRectangle maFillRectangle; + BitmapMode meMode = BitmapMode::Unused; + + sal_Int32 mnTileOffsetX = 0; + sal_Int32 mnTileOffsetY = 0; + sal_Int32 mnTileScaleX = 0; + sal_Int32 mnTileScaleY = 0; + FlipMode meTileFlipMode = FlipMode::None; + RectangleAlignment meTileAlignment = RectangleAlignment::TopLeft; + + css::uno::Reference<css::graphic::XGraphic> mxGraphic; + std::vector<BlipEffect> maBlipEffects; + + BlipFill() + : Fill(FillType::Blip) + { + } +}; + +class DOCMODEL_DLLPUBLIC FillStyle +{ +public: + std::shared_ptr<Fill> mpFill; +}; + +enum class CapType +{ + Unset, + Flat, + Round, + Square +}; + +enum class PenAlignmentType +{ + Unset, + Center, + Inset +}; + +enum class CompoundLineType +{ + Unset, + Single, + Double, + ThickThin_Double, + ThinThick_Double, + Triple, +}; + +enum class PresetDashType +{ + Unset, + Dash, + DashDot, + Dot, + LargeDash, + LargeDashDot, + LargeDashDotDot, + Solid, + SystemDash, + SystemDashDot, + SystemDashDotDot, + SystemDot, +}; + +enum class LineJoinType +{ + Unset, + Round, + Bevel, + Miter, +}; + +struct DOCMODEL_DLLPUBLIC LineJoin +{ + LineJoinType meType = LineJoinType::Unset; + sal_Int32 mnMiterLimit = 0; // Percentage +}; + +enum class LineEndType +{ + None, + Triangle, + Stealth, + Diamond, + Oval, + Arrow +}; + +enum class LineEndWidth +{ + Unset, + Small, + Medium, + Large +}; + +enum class LineEndLength +{ + Unset, + Small, + Medium, + Large +}; + +struct DOCMODEL_DLLPUBLIC LineEnd +{ + LineEndType meType = LineEndType::None; + LineEndWidth meWidth = LineEndWidth::Unset; + LineEndLength meLength = LineEndLength::Unset; +}; + +struct DOCMODEL_DLLPUBLIC DashStop +{ + sal_Int32 mnDashLength = 0; + sal_Int32 mnStopLength = 0; +}; + +struct DOCMODEL_DLLPUBLIC LineDash +{ + PresetDashType mePresetType = PresetDashType::Unset; + std::vector<DashStop> maCustomList; +}; + +class DOCMODEL_DLLPUBLIC LineStyle +{ +public: + sal_Int32 mnWidth; + CapType meCapType; + PenAlignmentType mePenAlignment; + CompoundLineType meCompoundLineType; + LineDash maLineDash; + LineJoin maLineJoin; + LineEnd maHeadEnd; + LineEnd maTailEnd; + + FillStyle maLineFillStyle; +}; + +enum class EffectType +{ + Unset, + OuterShadow, + InnerShadow, + Glow, + SoftEdge, + Reflection, + Blur +}; + +class DOCMODEL_DLLPUBLIC Effect +{ +public: + EffectType meType = EffectType::Unset; + sal_Int32 mnBlurRadius = 0; + sal_Int32 mnRadius = 0; + sal_Int32 mnDistance = 0; + sal_Int32 mnDirection = 0; + sal_Int32 mnScaleX = 100; + sal_Int32 mnScaley = 100; + sal_Int32 mnScewX = 0; + sal_Int32 mnScewY = 0; + RectangleAlignment meAlignment = RectangleAlignment::Bottom; + bool mbRotateWithShape = true; + ComplexColor maColor; + double mnEndAlpha = 100.0; + double mnEndPosition = 0.0; + double mnStartAlpha = 0.0; + double mnStartPosition = 100.0; + sal_Int32 mnFadeDirection = 0; + bool mbGrow = false; +}; + +class DOCMODEL_DLLPUBLIC EffectStyle +{ +public: + std::vector<Effect> maEffectList; +}; + +class DOCMODEL_DLLPUBLIC FormatScheme +{ +private: + OUString maName; + std::vector<FillStyle> maFillStyleList; + std::vector<LineStyle> maLineStyleList; + std::vector<EffectStyle> maEffectStyleList; + std::vector<FillStyle> maBackgroundFillStyleList; + +public: + FormatScheme() = default; + + FormatScheme(OUString const& rName) + : maName(rName) + { + } + + const OUString& getName() const { return maName; } + + std::vector<FillStyle> const& getFillStyleList() const { return maFillStyleList; } + + FillStyle* addFillStyle() + { + if (maFillStyleList.size() > 3) + return nullptr; + auto& rFillStyle = maFillStyleList.emplace_back(); + return &rFillStyle; + } + + void ensureFillStyleList() const + { + if (!maFillStyleList.empty()) + return; + + auto* pThis = const_cast<FormatScheme*>(this); + { + FillStyle* pFillStyle = pThis->addFillStyle(); + auto pFill = std::make_shared<SolidFill>(); + pFill->maColor.setThemePlaceholder(); + pFillStyle->mpFill = pFill; + } + { + FillStyle* pFillStyle = pThis->addFillStyle(); + auto pFill = std::make_shared<SolidFill>(); + pFill->maColor.setThemePlaceholder(); + pFillStyle->mpFill = pFill; + } + { + FillStyle* pFillStyle = pThis->addFillStyle(); + auto pFill = std::make_shared<SolidFill>(); + pFill->maColor.setThemePlaceholder(); + pFillStyle->mpFill = pFill; + } + } + + std::vector<LineStyle> const& getLineStyleList() const { return maLineStyleList; } + + LineStyle* addLineStyle() + { + if (maLineStyleList.size() > 3) + return nullptr; + auto& rLineStyle = maLineStyleList.emplace_back(); + return &rLineStyle; + } + + void ensureLineStyleList() const + { + if (!maLineStyleList.empty()) + return; + + auto* pThis = const_cast<FormatScheme*>(this); + + { + LineStyle* pLineStyle = pThis->addLineStyle(); + pLineStyle->mnWidth = 6350; + pLineStyle->meCapType = CapType::Flat; + pLineStyle->mePenAlignment = PenAlignmentType::Center; + pLineStyle->meCompoundLineType = CompoundLineType::Single; + pLineStyle->maLineDash.mePresetType = PresetDashType::Solid; + pLineStyle->maLineJoin.meType = LineJoinType::Miter; + auto pFill = std::make_shared<SolidFill>(); + pFill->maColor.setThemePlaceholder(); + pLineStyle->maLineFillStyle.mpFill = pFill; + } + { + LineStyle* pLineStyle = pThis->addLineStyle(); + pLineStyle->mnWidth = 6350; + pLineStyle->meCapType = CapType::Flat; + pLineStyle->mePenAlignment = PenAlignmentType::Center; + pLineStyle->meCompoundLineType = CompoundLineType::Single; + pLineStyle->maLineDash.mePresetType = PresetDashType::Solid; + pLineStyle->maLineJoin.meType = LineJoinType::Miter; + auto pFill = std::make_shared<SolidFill>(); + pFill->maColor.setThemePlaceholder(); + pLineStyle->maLineFillStyle.mpFill = pFill; + } + { + LineStyle* pLineStyle = pThis->addLineStyle(); + pLineStyle->mnWidth = 6350; + pLineStyle->meCapType = CapType::Flat; + pLineStyle->mePenAlignment = PenAlignmentType::Center; + pLineStyle->meCompoundLineType = CompoundLineType::Single; + pLineStyle->maLineDash.mePresetType = PresetDashType::Solid; + pLineStyle->maLineJoin.meType = LineJoinType::Miter; + auto pFill = std::make_shared<SolidFill>(); + pFill->maColor.setThemePlaceholder(); + pLineStyle->maLineFillStyle.mpFill = pFill; + } + } + + std::vector<EffectStyle> const& getEffectStyleList() const { return maEffectStyleList; } + + EffectStyle* addEffectStyle() + { + if (maEffectStyleList.size() > 3) + return nullptr; + auto& rEffectStyle = maEffectStyleList.emplace_back(); + return &rEffectStyle; + } + + void ensureEffectStyleList() const + { + if (!maEffectStyleList.empty()) + return; + + auto* pThis = const_cast<FormatScheme*>(this); + + pThis->addEffectStyle(); + pThis->addEffectStyle(); + pThis->addEffectStyle(); + } + + std::vector<FillStyle> const& getBackgroundFillStyleList() const + { + return maBackgroundFillStyleList; + } + + FillStyle* addBackgroundFillStyle() + { + if (maBackgroundFillStyleList.size() > 3) + return nullptr; + auto& rBackgroundFillStyle = maBackgroundFillStyleList.emplace_back(); + return &rBackgroundFillStyle; + } + + void ensureBackgroundFillStyleList() const + { + if (!maBackgroundFillStyleList.empty()) + return; + + auto* pThis = const_cast<FormatScheme*>(this); + + { + FillStyle* pFillStyle = pThis->addBackgroundFillStyle(); + auto pFill = std::make_shared<SolidFill>(); + pFill->maColor.setThemePlaceholder(); + pFillStyle->mpFill = pFill; + } + { + FillStyle* pFillStyle = pThis->addBackgroundFillStyle(); + auto pFill = std::make_shared<SolidFill>(); + pFill->maColor.setThemePlaceholder(); + pFillStyle->mpFill = pFill; + } + { + FillStyle* pFillStyle = pThis->addBackgroundFillStyle(); + auto pFill = std::make_shared<SolidFill>(); + pFill->maColor.setThemePlaceholder(); + pFillStyle->mpFill = pFill; + } + } +}; + +} // end of namespace svx + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/docmodel/theme/Theme.hxx b/include/docmodel/theme/Theme.hxx new file mode 100644 index 0000000000..898cf3d787 --- /dev/null +++ b/include/docmodel/theme/Theme.hxx @@ -0,0 +1,197 @@ +/* -*- 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/. + * + */ + +#pragma once + +#include <docmodel/dllapi.h> +#include <vector> + +#include <rtl/ustring.hxx> +#include <docmodel/theme/ThemeColorType.hxx> +#include <docmodel/theme/ColorSet.hxx> +#include <docmodel/theme/FormatScheme.hxx> +#include <tools/color.hxx> + +typedef struct _xmlTextWriter* xmlTextWriterPtr; + +namespace model +{ +struct DOCMODEL_DLLPUBLIC ThemeSupplementalFont +{ + OUString maScript; + OUString maTypeface; +}; + +struct DOCMODEL_DLLPUBLIC ThemeFont +{ + OUString maTypeface; + OUString maPanose; + sal_Int16 maPitch = 0; + sal_Int16 maFamily = 0; + sal_Int32 maCharset = 1; + + sal_Int16 getPitchFamily() const { return (maPitch & 0x0F) | (maFamily & 0x0F) << 4; } +}; + +class DOCMODEL_DLLPUBLIC FontScheme +{ +private: + OUString maName; + + ThemeFont maMinorLatin; + ThemeFont maMinorAsian; + ThemeFont maMinorComplex; + + ThemeFont maMajorLatin; + ThemeFont maMajorAsian; + ThemeFont maMajorComplex; + + std::vector<ThemeSupplementalFont> maMinorSupplementalFontList; + std::vector<ThemeSupplementalFont> maMajorSupplementalFontList; + +public: + FontScheme() + : maName("Office") + { + } + + FontScheme(OUString const& rName) + : maName(rName) + { + } + + static FontScheme getDefault() + { + FontScheme aDefault; + aDefault.maMinorLatin.maTypeface = "Arial"; + aDefault.maMinorAsian.maTypeface = "DejaVu Sans"; + aDefault.maMinorComplex.maTypeface = "DejaVu Sans"; + + aDefault.maMajorLatin.maTypeface = "Arial"; + aDefault.maMajorAsian.maTypeface = "DejaVu Sans"; + aDefault.maMajorComplex.maTypeface = "DejaVu Sans"; + return aDefault; + } + + const OUString& getName() const { return maName; } + + ThemeFont const& getMinorLatin() const { return maMinorLatin; } + void setMinorLatin(ThemeFont const& aMinor) { maMinorLatin = aMinor; } + + ThemeFont const& getMinorAsian() const { return maMinorAsian; } + void setMinorAsian(ThemeFont const& aMinor) { maMinorAsian = aMinor; } + + ThemeFont const& getMinorComplex() const { return maMinorComplex; } + void setMinorComplex(ThemeFont const& aMinor) { maMinorComplex = aMinor; } + + ThemeFont const& getMajorLatin() const { return maMajorLatin; } + void setMajorLatin(ThemeFont const& aMajor) { maMajorLatin = aMajor; } + + ThemeFont const& getMajorAsian() const { return maMajorAsian; } + void setMajorAsian(ThemeFont const& aMajor) { maMajorAsian = aMajor; } + + ThemeFont const& getMajorComplex() const { return maMajorComplex; } + void setMajorComplex(ThemeFont const& aMajor) { maMajorComplex = aMajor; } + + OUString findMinorSupplementalTypeface(std::u16string_view rScript) const + { + for (auto const& rSupplementalFont : maMinorSupplementalFontList) + { + if (rSupplementalFont.maScript == rScript) + return rSupplementalFont.maTypeface; + } + return OUString(); + } + + std::vector<ThemeSupplementalFont> const& getMinorSupplementalFontList() const + { + return maMinorSupplementalFontList; + } + + void addMinorSupplementalFont(ThemeSupplementalFont const& rfont) + { + maMinorSupplementalFontList.push_back(rfont); + } + + void setMinorSupplementalFontList(std::vector<ThemeSupplementalFont> const& rSupplementalFont) + { + maMinorSupplementalFontList = rSupplementalFont; + } + + OUString findMajorSupplementalTypeface(std::u16string_view rScript) const + { + for (auto const& rSupplementalFont : maMajorSupplementalFontList) + { + if (rSupplementalFont.maScript == rScript) + return rSupplementalFont.maTypeface; + } + return OUString(); + } + + std::vector<ThemeSupplementalFont> const& getMajorSupplementalFontList() const + { + return maMajorSupplementalFontList; + } + + void addMajorSupplementalFont(ThemeSupplementalFont const& rfont) + { + maMajorSupplementalFontList.push_back(rfont); + } + + void setMajorSupplementalFontList(std::vector<ThemeSupplementalFont> const& rSupplementalFont) + { + maMajorSupplementalFontList = rSupplementalFont; + } +}; + +/// A named theme has a named color set. +class DOCMODEL_DLLPUBLIC Theme +{ +private: + OUString maName; + std::shared_ptr<model::ColorSet> mpColorSet; + + FontScheme maFontScheme = FontScheme::getDefault(); + FormatScheme maFormatScheme; + +public: + Theme(); + Theme(OUString const& rName); + + Theme(Theme const& rTheme); + + void setFontScheme(FontScheme const& rFontScheme) { maFontScheme = rFontScheme; } + FontScheme const& getFontScheme() const { return maFontScheme; } + + void setFormatScheme(FormatScheme const& rFormatScheme) { maFormatScheme = rFormatScheme; } + FormatScheme const& getFormatScheme() const { return maFormatScheme; } + FormatScheme& getFormatScheme() { return maFormatScheme; } + + void setColorSet(std::shared_ptr<model::ColorSet> const& pColorSet) { mpColorSet = pColorSet; } + + std::shared_ptr<model::ColorSet> const& getColorSet() const { return mpColorSet; } + + void SetName(const OUString& rName); + const OUString& GetName() const; + + void dumpAsXml(xmlTextWriterPtr pWriter) const; + + void ToAny(css::uno::Any& rVal) const; + + static std::unique_ptr<Theme> FromAny(const css::uno::Any& rVal); + + std::vector<Color> GetColors() const; + + Color GetColor(model::ThemeColorType eType) const; +}; + +} // end of namespace model + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/docmodel/theme/ThemeColorType.hxx b/include/docmodel/theme/ThemeColorType.hxx new file mode 100644 index 0000000000..cab4174c68 --- /dev/null +++ b/include/docmodel/theme/ThemeColorType.hxx @@ -0,0 +1,51 @@ +/* -*- 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/. + * + */ + +#pragma once + +#include <sal/types.h> + +namespace model +{ +/// Offsets into the color list of a theme. +enum class ThemeColorType : sal_Int32 +{ + Unknown = -1, + Dark1 = 0, + Light1 = 1, + Dark2 = 2, + Light2 = 3, + Accent1 = 4, + Accent2 = 5, + Accent3 = 6, + Accent4 = 7, + Accent5 = 8, + Accent6 = 9, + Hyperlink = 10, + FollowedHyperlink = 11, + LAST = FollowedHyperlink +}; + +enum class ThemeColorUsage +{ + Unknown = 0, + Text, + Background +}; + +constexpr ThemeColorType convertToThemeColorType(sal_Int32 nIndex) +{ + if (nIndex < 0 || nIndex > 11) + return ThemeColorType::Unknown; + return static_cast<ThemeColorType>(nIndex); +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/docmodel/uno/UnoComplexColor.hxx b/include/docmodel/uno/UnoComplexColor.hxx new file mode 100644 index 0000000000..f80e75454c --- /dev/null +++ b/include/docmodel/uno/UnoComplexColor.hxx @@ -0,0 +1,49 @@ +/* -*- 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/. + */ + +#pragma once + +#include <cppuhelper/implbase.hxx> + +#include <com/sun/star/util/Color.hpp> +#include <com/sun/star/util/XComplexColor.hpp> + +#include <docmodel/dllapi.h> +#include <docmodel/color/ComplexColor.hxx> + +class DOCMODEL_DLLPUBLIC UnoComplexColor final + : public cppu::WeakImplHelper<css::util::XComplexColor> +{ +private: + model::ComplexColor maColor; + +public: + UnoComplexColor(model::ComplexColor const& rColor) + : maColor(rColor) + { + } + + model::ComplexColor const& getComplexColor() const { return maColor; } + + // XComplexColor + sal_Int32 SAL_CALL getType() override; + sal_Int32 SAL_CALL getThemeColorType() override; + css::util::Color SAL_CALL + resolveColor(css::uno::Reference<css::util::XTheme> const& xTheme) override; +}; + +namespace model::color +{ +DOCMODEL_DLLPUBLIC css::uno::Reference<css::util::XComplexColor> +createXComplexColor(model::ComplexColor const& rColor); +DOCMODEL_DLLPUBLIC model::ComplexColor +getFromXComplexColor(css::uno::Reference<css::util::XComplexColor> const& rxColor); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/docmodel/uno/UnoGradientTools.hxx b/include/docmodel/uno/UnoGradientTools.hxx new file mode 100644 index 0000000000..3d748d4930 --- /dev/null +++ b/include/docmodel/uno/UnoGradientTools.hxx @@ -0,0 +1,33 @@ +/* -*- 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/. + */ + +#pragma once + +#include <docmodel/dllapi.h> +#include <basegfx/utils/bgradient.hxx> +#include <com/sun/star/awt/Gradient2.hpp> +#include <com/sun/star/awt/ColorStopSequence.hpp> +#include <com/sun/star/uno/Any.hxx> + +namespace model::gradient +{ +DOCMODEL_DLLPUBLIC css::awt::Gradient2 createUnoGradient2(basegfx::BGradient const& rGradient); + +DOCMODEL_DLLPUBLIC basegfx::BGradient getFromUnoGradient2(css::awt::Gradient2 const& rGradient2); +DOCMODEL_DLLPUBLIC basegfx::BGradient getFromAny(css::uno::Any const& rAny); + +DOCMODEL_DLLPUBLIC css::awt::ColorStopSequence +createColorStopSequence(basegfx::BColorStops const& rColorStops); + +DOCMODEL_DLLPUBLIC basegfx::BColorStops +getColorStopsFromUno(css::awt::ColorStopSequence const& rColorStopSequence); +DOCMODEL_DLLPUBLIC basegfx::BColorStops getColorStopsFromAny(css::uno::Any const& rAny); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/docmodel/uno/UnoTheme.hxx b/include/docmodel/uno/UnoTheme.hxx new file mode 100644 index 0000000000..2fde5096f3 --- /dev/null +++ b/include/docmodel/uno/UnoTheme.hxx @@ -0,0 +1,46 @@ +/* -*- 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/. + */ + +#pragma once + +#include <cppuhelper/implbase.hxx> + +#include <com/sun/star/util/XTheme.hpp> + +#include <docmodel/dllapi.h> + +namespace model +{ +class Theme; +} + +class DOCMODEL_DLLPUBLIC UnoTheme final : public cppu::WeakImplHelper<css::util::XTheme> +{ +private: + std::shared_ptr<model::Theme> mpTheme; + +public: + UnoTheme(std::shared_ptr<model::Theme> const& pTheme) + : mpTheme(pTheme) + { + } + + std::shared_ptr<model::Theme> const& getTheme() const { return mpTheme; } + + // XTheme + OUString SAL_CALL getName() override; + css::uno::Sequence<sal_Int32> SAL_CALL getColorSet() override; +}; + +namespace model::theme +{ +DOCMODEL_DLLPUBLIC css::uno::Reference<css::util::XTheme> +createXTheme(std::shared_ptr<model::Theme> const& pTheme); +} +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |