/*
* InfiniPaint
* Copyright (C) 2025-2026 Yousef Khadadeh
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
#pragma once
#include
#include
#include
#include "cereal/archives/portable_binary.hpp"
#include "../SharedTypes.hpp"
#include "../FontData.hpp"
namespace RichText {
class TextStyleModifier {
public:
enum class ModifierType : uint16_t {
SIZE = 0,
COLOR,
WEIGHT,
SLANT,
DECORATION,
FONT_FAMILIES,
HIGHLIGHT_COLOR,
COUNT
};
typedef std::unordered_map> ModifierMap;
static std::shared_ptr allocate_modifier(ModifierType type);
static std::shared_ptr get_default_modifier(ModifierType type);
static const ModifierMap& get_default_modifiers();
virtual ModifierType get_type() const = 0;
virtual void save(cereal::PortableBinaryOutputArchive& a) const = 0;
virtual void load(cereal::PortableBinaryInputArchive& a) = 0;
virtual void modify_text_style(skia::textlayout::TextStyle& style) const = 0;
bool equivalent(TextStyleModifier& modifier) const;
virtual ~TextStyleModifier();
private:
static ModifierMap defaultMods;
virtual bool equivalent_data(TextStyleModifier& modifier) const = 0;
};
class DecorationTextStyleModifier : public TextStyleModifier {
public:
DecorationTextStyleModifier() = default;
DecorationTextStyleModifier(uint8_t initDecorationValue);
virtual ModifierType get_type() const override;
virtual void save(cereal::PortableBinaryOutputArchive& a) const override;
virtual void load(cereal::PortableBinaryInputArchive& a) override;
virtual void modify_text_style(skia::textlayout::TextStyle& style) const override;
uint8_t get_decoration_value() const;
private:
uint8_t decorationValue;
virtual bool equivalent_data(TextStyleModifier& modifier) const override;
};
class WeightTextStyleModifier : public TextStyleModifier {
public:
WeightTextStyleModifier() = default;
WeightTextStyleModifier(SkFontStyle::Weight initWeight);
virtual ModifierType get_type() const override;
virtual void save(cereal::PortableBinaryOutputArchive& a) const override;
virtual void load(cereal::PortableBinaryInputArchive& a) override;
virtual void modify_text_style(skia::textlayout::TextStyle& style) const override;
SkFontStyle::Weight get_weight() const;
private:
virtual bool equivalent_data(TextStyleModifier& modifier) const override;
uint8_t weightValue;
};
class SlantTextStyleModifier : public TextStyleModifier {
public:
SlantTextStyleModifier() = default;
SlantTextStyleModifier(uint8_t initSlantValue);
virtual ModifierType get_type() const override;
virtual void save(cereal::PortableBinaryOutputArchive& a) const override;
virtual void load(cereal::PortableBinaryInputArchive& a) override;
virtual void modify_text_style(skia::textlayout::TextStyle& style) const override;
SkFontStyle::Slant get_slant() const;
private:
virtual bool equivalent_data(TextStyleModifier& modifier) const override;
uint8_t slantValue;
};
class ColorTextStyleModifier : public TextStyleModifier {
public:
ColorTextStyleModifier() = default;
ColorTextStyleModifier(const Vector4f& initColor);
virtual ModifierType get_type() const override;
virtual void save(cereal::PortableBinaryOutputArchive& a) const override;
virtual void load(cereal::PortableBinaryInputArchive& a) override;
virtual void modify_text_style(skia::textlayout::TextStyle& style) const override;
const Vector4f& get_color() const;
private:
Vector4f color;
virtual bool equivalent_data(TextStyleModifier& modifier) const override;
};
class HighlightColorTextStyleModifier : public TextStyleModifier {
public:
HighlightColorTextStyleModifier() = default;
HighlightColorTextStyleModifier(const Vector4f& initColor);
virtual ModifierType get_type() const override;
virtual void save(cereal::PortableBinaryOutputArchive& a) const override;
virtual void load(cereal::PortableBinaryInputArchive& a) override;
virtual void modify_text_style(skia::textlayout::TextStyle& style) const override;
const Vector4f& get_color() const;
private:
Vector4f color;
virtual bool equivalent_data(TextStyleModifier& modifier) const override;
};
class SizeTextStyleModifier : public TextStyleModifier {
public:
SizeTextStyleModifier() = default;
SizeTextStyleModifier(float initSize);
virtual ModifierType get_type() const override;
virtual void save(cereal::PortableBinaryOutputArchive& a) const override;
virtual void load(cereal::PortableBinaryInputArchive& a) override;
virtual void modify_text_style(skia::textlayout::TextStyle& style) const override;
float get_size() const;
private:
float size;
virtual bool equivalent_data(TextStyleModifier& modifier) const override;
};
class FontFamiliesTextStyleModifier : public TextStyleModifier {
public:
static std::shared_ptr globalFontData;
FontFamiliesTextStyleModifier() = default;
FontFamiliesTextStyleModifier(const std::vector& initFamilies);
virtual ModifierType get_type() const override;
virtual void save(cereal::PortableBinaryOutputArchive& a) const override;
virtual void load(cereal::PortableBinaryInputArchive& a) override;
virtual void modify_text_style(skia::textlayout::TextStyle& style) const override;
const std::vector& get_families() const;
private:
std::vector families;
virtual bool equivalent_data(TextStyleModifier& modifier) const override;
};
}