| 1 |
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
| 2 |
/* |
| 3 |
* This file is part of the LibreOffice project. |
| 4 |
* |
| 5 |
* This Source Code Form is subject to the terms of the Mozilla Public |
| 6 |
* License, v. 2.0. If a copy of the MPL was not distributed with this |
| 7 |
* file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 8 |
* |
| 9 |
*/ |
| 10 |
|
| 11 |
#pragma once |
| 12 |
|
| 13 |
#include <docmodel/dllapi.h> |
| 14 |
#include <vector> |
| 15 |
|
| 16 |
#include <rtl/ustring.hxx> |
| 17 |
#include <docmodel/theme/ThemeColorType.hxx> |
| 18 |
#include <docmodel/theme/ColorSet.hxx> |
| 19 |
#include <docmodel/theme/FormatScheme.hxx> |
| 20 |
#include <tools/color.hxx> |
| 21 |
|
| 22 |
typedef struct _xmlTextWriter* xmlTextWriterPtr; |
| 23 |
|
| 24 |
namespace model |
| 25 |
{ |
| 26 |
struct DOCMODEL_DLLPUBLIC ThemeSupplementalFont |
| 27 |
{ |
| 28 |
OUString maScript; |
| 29 |
OUString maTypeface; |
| 30 |
}; |
| 31 |
|
| 32 |
struct DOCMODEL_DLLPUBLIC ThemeFont |
| 33 |
{ |
| 34 |
OUString maTypeface; |
| 35 |
OUString maPanose; |
| 36 |
sal_Int16 maPitch = 0; |
| 37 |
sal_Int16 maFamily = 0; |
| 38 |
sal_Int32 maCharset = 1; |
| 39 |
|
| 40 |
sal_Int16 getPitchFamily() const { return (maPitch & 0x0F) | (maFamily & 0x0F) << 4; } |
| 41 |
}; |
| 42 |
|
| 43 |
class DOCMODEL_DLLPUBLIC FontScheme |
| 44 |
{ |
| 45 |
private: |
| 46 |
OUString maName; |
| 47 |
|
| 48 |
ThemeFont maMinorLatin; |
| 49 |
ThemeFont maMinorAsian; |
| 50 |
ThemeFont maMinorComplex; |
| 51 |
|
| 52 |
ThemeFont maMajorLatin; |
| 53 |
ThemeFont maMajorAsian; |
| 54 |
ThemeFont maMajorComplex; |
| 55 |
|
| 56 |
std::vector<ThemeSupplementalFont> maMinorSupplementalFontList; |
| 57 |
std::vector<ThemeSupplementalFont> maMajorSupplementalFontList; |
| 58 |
|
| 59 |
public: |
| 60 |
FontScheme() |
| 61 |
: maName(u"Office"_ustr) |
| 62 |
{ |
| 63 |
} |
| 64 |
|
| 65 |
FontScheme(OUString const& rName) |
| 66 |
: maName(rName) |
| 67 |
{ |
| 68 |
} |
| 69 |
|
| 70 |
static FontScheme getDefault() |
| 71 |
{ |
| 72 |
FontScheme aDefault; |
| 73 |
aDefault.maMinorLatin.maTypeface = "Arial"; |
| 74 |
aDefault.maMinorAsian.maTypeface = "DejaVu Sans"; |
| 75 |
aDefault.maMinorComplex.maTypeface = "DejaVu Sans"; |
| 76 |
|
| 77 |
aDefault.maMajorLatin.maTypeface = "Arial"; |
| 78 |
aDefault.maMajorAsian.maTypeface = "DejaVu Sans"; |
| 79 |
aDefault.maMajorComplex.maTypeface = "DejaVu Sans"; |
| 80 |
return aDefault; |
| 81 |
} |
| 82 |
|
| 83 |
const OUString& getName() const { return maName; } |
| 84 |
|
| 85 |
ThemeFont const& getMinorLatin() const { return maMinorLatin; } |
| 86 |
void setMinorLatin(ThemeFont const& aMinor) { maMinorLatin = aMinor; } |
| 87 |
|
| 88 |
ThemeFont const& getMinorAsian() const { return maMinorAsian; } |
| 89 |
void setMinorAsian(ThemeFont const& aMinor) { maMinorAsian = aMinor; } |
| 90 |
|
| 91 |
ThemeFont const& getMinorComplex() const { return maMinorComplex; } |
| 92 |
void setMinorComplex(ThemeFont const& aMinor) { maMinorComplex = aMinor; } |
| 93 |
|
| 94 |
ThemeFont const& getMajorLatin() const { return maMajorLatin; } |
| 95 |
void setMajorLatin(ThemeFont const& aMajor) { maMajorLatin = aMajor; } |
| 96 |
|
| 97 |
ThemeFont const& getMajorAsian() const { return maMajorAsian; } |
| 98 |
void setMajorAsian(ThemeFont const& aMajor) { maMajorAsian = aMajor; } |
| 99 |
|
| 100 |
ThemeFont const& getMajorComplex() const { return maMajorComplex; } |
| 101 |
void setMajorComplex(ThemeFont const& aMajor) { maMajorComplex = aMajor; } |
| 102 |
|
| 103 |
OUString findMinorSupplementalTypeface(std::u16string_view rScript) const |
| 104 |
{ |
| 105 |
for (auto const& rSupplementalFont : maMinorSupplementalFontList) |
| 106 |
{ |
| 107 |
if (rSupplementalFont.maScript == rScript) |
| 108 |
return rSupplementalFont.maTypeface; |
| 109 |
} |
| 110 |
return OUString(); |
| 111 |
} |
| 112 |
|
| 113 |
std::vector<ThemeSupplementalFont> const& getMinorSupplementalFontList() const |
| 114 |
{ |
| 115 |
return maMinorSupplementalFontList; |
| 116 |
} |
| 117 |
|
| 118 |
void addMinorSupplementalFont(ThemeSupplementalFont const& rfont) |
| 119 |
{ |
| 120 |
maMinorSupplementalFontList.push_back(rfont); |
| 121 |
} |
| 122 |
|
| 123 |
void setMinorSupplementalFontList(std::vector<ThemeSupplementalFont> const& rSupplementalFont) |
| 124 |
{ |
| 125 |
maMinorSupplementalFontList = rSupplementalFont; |
| 126 |
} |
| 127 |
|
| 128 |
OUString findMajorSupplementalTypeface(std::u16string_view rScript) const |
| 129 |
{ |
| 130 |
for (auto const& rSupplementalFont : maMajorSupplementalFontList) |
| 131 |
{ |
| 132 |
if (rSupplementalFont.maScript == rScript) |
| 133 |
return rSupplementalFont.maTypeface; |
| 134 |
} |
| 135 |
return OUString(); |
| 136 |
} |
| 137 |
|
| 138 |
std::vector<ThemeSupplementalFont> const& getMajorSupplementalFontList() const |
| 139 |
{ |
| 140 |
return maMajorSupplementalFontList; |
| 141 |
} |
| 142 |
|
| 143 |
void addMajorSupplementalFont(ThemeSupplementalFont const& rfont) |
| 144 |
{ |
| 145 |
maMajorSupplementalFontList.push_back(rfont); |
| 146 |
} |
| 147 |
|
| 148 |
void setMajorSupplementalFontList(std::vector<ThemeSupplementalFont> const& rSupplementalFont) |
| 149 |
{ |
| 150 |
maMajorSupplementalFontList = rSupplementalFont; |
| 151 |
} |
| 152 |
}; |
| 153 |
|
| 154 |
/// A named theme has a named color set. |
| 155 |
class DOCMODEL_DLLPUBLIC Theme |
| 156 |
{ |
| 157 |
private: |
| 158 |
OUString maName; |
| 159 |
std::shared_ptr<model::ColorSet> mpColorSet; |
| 160 |
|
| 161 |
FontScheme maFontScheme = FontScheme::getDefault(); |
| 162 |
FormatScheme maFormatScheme; |
| 163 |
|
| 164 |
public: |
| 165 |
Theme(); |
| 166 |
Theme(OUString const& rName); |
| 167 |
|
| 168 |
Theme(Theme const& rTheme); |
| 169 |
|
| 170 |
void setFontScheme(FontScheme const& rFontScheme) { maFontScheme = rFontScheme; } |
| 171 |
FontScheme const& getFontScheme() const { return maFontScheme; } |
| 172 |
|
| 173 |
void setFormatScheme(FormatScheme const& rFormatScheme) { maFormatScheme = rFormatScheme; } |
| 174 |
FormatScheme const& getFormatScheme() const { return maFormatScheme; } |
| 175 |
FormatScheme& getFormatScheme() { return maFormatScheme; } |
| 176 |
|
| 177 |
void setColorSet(std::shared_ptr<model::ColorSet> const& pColorSet) { mpColorSet = pColorSet; } |
| 178 |
|
| 179 |
std::shared_ptr<model::ColorSet> const& getColorSet() const { return mpColorSet; } |
| 180 |
|
| 181 |
void SetName(const OUString& rName); |
| 182 |
const OUString& GetName() const; |
| 183 |
|
| 184 |
void dumpAsXml(xmlTextWriterPtr pWriter) const; |
| 185 |
|
| 186 |
void ToAny(css::uno::Any& rVal) const; |
| 187 |
|
| 188 |
static std::shared_ptr<Theme> FromAny(const css::uno::Any& rVal); |
| 189 |
|
| 190 |
std::vector<Color> GetColors() const; |
| 191 |
|
| 192 |
Color GetColor(model::ThemeColorType eType) const; |
| 193 |
}; |
| 194 |
|
| 195 |
} // end of namespace model |
| 196 |
|
| 197 |
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |