#include "modules/skparagraph/include/sk4d_textstyle.h"
#include "modules/skparagraph/src/sk4d_paragraph_mapping.h"

void sk4d_textstyle_add_font_feature(sk_textstyle_t* self, const sk_string_t* feature, int32_t value) {
    AsTextStyle(self)->addFontFeature(AsString(*feature), value);
}

void sk4d_textstyle_add_shadow(sk_textstyle_t* self, const sk_textshadow_t* shadow) {
    AsTextStyle(self)->addShadow(AsTextShadow(shadow));
}

void sk4d_textstyle_clear_background_color(sk_textstyle_t* self) {
    AsTextStyle(self)->clearBackgroundColor();
}

void sk4d_textstyle_clear_foreground_color(sk_textstyle_t* self) {
    AsTextStyle(self)->clearForegroundColor();
}

sk_textstyle_t* sk4d_textstyle_create(void) {
    return ToTextStyle(new skia::textlayout::TextStyle());
}

void sk4d_textstyle_destroy(sk_textstyle_t* self) {
    delete AsTextStyle(self);
}

sk_paint_t* sk4d_textstyle_get_background(const sk_textstyle_t* self) {
    return ToPaint(new SkPaint(AsTextStyle(self)->getBackground()));
}

sk_color_t sk4d_textstyle_get_color(const sk_textstyle_t* self) {
    return AsTextStyle(self)->getColor();
}

sk_color_t sk4d_textstyle_get_decoration_color(const sk_textstyle_t* self) {
    return AsTextStyle(self)->getDecorationColor();
}

sk_textdecorationmode_t sk4d_textstyle_get_decoration_mode(const sk_textstyle_t* self) {
    return ToTextDecorationMode(AsTextStyle(self)->getDecorationMode());
}

sk_textdecorationstyle_t sk4d_textstyle_get_decoration_style(const sk_textstyle_t* self) {
    return ToTextDecorationStyle(AsTextStyle(self)->getDecorationStyle());
}

float sk4d_textstyle_get_decoration_thickness_multiplier(const sk_textstyle_t* self) {
    return AsTextStyle(self)->getDecorationThicknessMultiplier();
}

uint32_t sk4d_textstyle_get_decorations(const sk_textstyle_t* self) {
    return ToTextDecoration(AsTextStyle(self)->getDecorationType());
}

size_t sk4d_textstyle_get_font_families(const sk_textstyle_t* self, sk_string_t* result[]) {
    const auto& fontFamilies = AsTextStyle(self)->getFontFamilies();
    size_t count = fontFamilies.size();
    if (result != nullptr) {
        for (size_t i = 0; i < count; i++)
            *AsString(result[i]) = fontFamilies[i];
    }
    return count;
}

void sk4d_textstyle_get_font_metrics(const sk_textstyle_t* self, sk_fontmetrics_t* metrics) {
    AsTextStyle(self)->getFontMetrics(AsFontMetrics(metrics));
}

float sk4d_textstyle_get_font_size(const sk_textstyle_t* self) {
    return AsTextStyle(self)->getFontSize();
}

void sk4d_textstyle_get_font_style(const sk_textstyle_t* self, sk_fontstyle_t* result) {
    *result = ToFontStyle(AsTextStyle(self)->getFontStyle());
}

sk_paint_t* sk4d_textstyle_get_foreground(const sk_textstyle_t* self) {
    return ToPaint(new SkPaint(AsTextStyle(self)->getForeground()));
}

float sk4d_textstyle_get_height(const sk_textstyle_t* self) {
    return AsTextStyle(self)->getHeight();
}

bool sk4d_textstyle_get_height_override(const sk_textstyle_t* self) {
    return AsTextStyle(self)->getHeightOverride();
}

float sk4d_textstyle_get_letter_spacing(const sk_textstyle_t* self) {
    return AsTextStyle(self)->getLetterSpacing();
}

sk_string_t* sk4d_textstyle_get_locale(const sk_textstyle_t* self) {
    return ToString(new SkString(AsTextStyle(self)->getLocale()));
}

sk_textbaseline_t sk4d_textstyle_get_text_baseline(const sk_textstyle_t* self) {
    return  ToTextBaseline(AsTextStyle(self)->getTextBaseline());
}

sk_typeface_t* sk4d_textstyle_get_typeface(const sk_textstyle_t* self) {
    return ToTypeface(AsTextStyle(self)->refTypeface().release());
}

float sk4d_textstyle_get_word_spacing(const sk_textstyle_t* self) {
    return AsTextStyle(self)->getWordSpacing();
}

bool sk4d_textstyle_has_background(const sk_textstyle_t* self) {
    return AsTextStyle(self)->hasBackground();
}

bool sk4d_textstyle_has_foreground(const sk_textstyle_t* self) {
    return AsTextStyle(self)->hasForeground();
}

bool sk4d_textstyle_is_equal(const sk_textstyle_t* self, const sk_textstyle_t* text_style) {
    return AsTextStyle(*self) == AsTextStyle(*text_style);
}

bool sk4d_textstyle_is_placeholder(const sk_textstyle_t* self) {
    return AsTextStyle(self)->isPlaceholder();
}

void sk4d_textstyle_reset_font_features(sk_textstyle_t* self) {
    AsTextStyle(self)->resetFontFeatures();
}

void sk4d_textstyle_reset_shadows(sk_textstyle_t* self) {
    AsTextStyle(self)->resetShadows();
}

void sk4d_textstyle_set_background_color(sk_textstyle_t* self, sk_paint_t* paint) {
    AsTextStyle(self)->setBackgroundColor(*AsPaint(paint));
}

void sk4d_textstyle_set_color(sk_textstyle_t* self, sk_color_t value) {
    AsTextStyle(self)->setColor(value);
}

void sk4d_textstyle_set_decoration_color(sk_textstyle_t* self, sk_color_t value) {
    AsTextStyle(self)->setDecorationColor(value);
}

void sk4d_textstyle_set_decoration_mode(sk_textstyle_t* self, sk_textdecorationmode_t value) {
    AsTextStyle(self)->setDecorationMode(AsTextDecorationMode(value));
}

void sk4d_textstyle_set_decoration_style(sk_textstyle_t* self, sk_textdecorationstyle_t value) {
    AsTextStyle(self)->setDecorationStyle(AsTextDecorationStyle(value));
}

void sk4d_textstyle_set_decoration_thickness_multiplier(sk_textstyle_t* self, float value) {
    AsTextStyle(self)->setDecorationThicknessMultiplier(value);
}

void sk4d_textstyle_set_decorations(sk_textstyle_t* self, uint32_t value) {
    AsTextStyle(self)->setDecoration(AsTextDecoration(value));
}

void sk4d_textstyle_set_font_families(sk_textstyle_t* self, const sk_string_t* values[], size_t count) {
    std::vector<SkString> fontFamilies(count);
    for (size_t i = 0; i < count; i++)
        fontFamilies[i] = *AsString(values[i]);
    AsTextStyle(self)->setFontFamilies(fontFamilies);
}

void sk4d_textstyle_set_font_size(sk_textstyle_t* self, float value) {
    AsTextStyle(self)->setFontSize(value);
}

void sk4d_textstyle_set_font_style(sk_textstyle_t* self, const sk_fontstyle_t* value) {
    AsTextStyle(self)->setFontStyle(AsFontStyle(value));
}

void sk4d_textstyle_set_foreground_color(sk_textstyle_t* self, sk_paint_t* paint) {
    AsTextStyle(self)->setForegroundColor(*AsPaint(paint));
}

void sk4d_textstyle_set_height(sk_textstyle_t* self, float value) {
    AsTextStyle(self)->setHeight(value);
}

void sk4d_textstyle_set_height_override(sk_textstyle_t* self, bool value) {
    AsTextStyle(self)->setHeightOverride(value);
}

void sk4d_textstyle_set_letter_spacing(sk_textstyle_t* self, float value) {
    AsTextStyle(self)->setLetterSpacing(value);
}

void sk4d_textstyle_set_locale(sk_textstyle_t* self, const sk_string_t* value) {
    AsTextStyle(self)->setLocale(AsString(*value));
}

void sk4d_textstyle_set_place_holder(sk_textstyle_t* self) {
    AsTextStyle(self)->setPlaceholder();
}

void sk4d_textstyle_set_text_baseline(sk_textstyle_t* self, sk_textbaseline_t value) {
    AsTextStyle(self)->setTextBaseline(AsTextBaseline(value));
}

void sk4d_textstyle_set_typeface(sk_textstyle_t* self, sk_typeface_t* value) {
    AsTextStyle(self)->setTypeface(sk_ref_sp(AsTypeface(value)));
}

void sk4d_textstyle_set_word_spacing(sk_textstyle_t* self, float value) {
    AsTextStyle(self)->setWordSpacing(value);
}
/*
 * Copyright (c) 2011-2021 Google LLC.
 * Copyright (c) 2021 Skia4Delphi Project.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#include "modules/skparagraph/include/sk4d_textstyle.h"
#include "modules/skparagraph/src/sk4d_paragraph_mapping.h"

void sk4d_textstyle_add_font_feature(sk_textstyle_t* self, const sk_string_t* feature, int32_t value) {
    AsTextStyle(self)->addFontFeature(AsString(*feature), value);
}

void sk4d_textstyle_add_shadow(sk_textstyle_t* self, const sk_textshadow_t* shadow) {
    AsTextStyle(self)->addShadow(AsTextShadow(shadow));
}

void sk4d_textstyle_clear_background_color(sk_textstyle_t* self) {
    AsTextStyle(self)->clearBackgroundColor();
}

void sk4d_textstyle_clear_foreground_color(sk_textstyle_t* self) {
    AsTextStyle(self)->clearForegroundColor();
}

sk_textstyle_t* sk4d_textstyle_create(void) {
    return ToTextStyle(new skia::textlayout::TextStyle());
}

void sk4d_textstyle_destroy(sk_textstyle_t* self) {
    delete AsTextStyle(self);
}

sk_paint_t* sk4d_textstyle_get_background(const sk_textstyle_t* self) {
    return ToPaint(new SkPaint(AsTextStyle(self)->getBackground()));
}

sk_color_t sk4d_textstyle_get_color(const sk_textstyle_t* self) {
    return AsTextStyle(self)->getColor();
}

sk_color_t sk4d_textstyle_get_decoration_color(const sk_textstyle_t* self) {
    return AsTextStyle(self)->getDecorationColor();
}

sk_textdecorationmode_t sk4d_textstyle_get_decoration_mode(const sk_textstyle_t* self) {
    return ToTextDecorationMode(AsTextStyle(self)->getDecorationMode());
}

sk_textdecorationstyle_t sk4d_textstyle_get_decoration_style(const sk_textstyle_t* self) {
    return ToTextDecorationStyle(AsTextStyle(self)->getDecorationStyle());
}

float sk4d_textstyle_get_decoration_thickness_multiplier(const sk_textstyle_t* self) {
    return AsTextStyle(self)->getDecorationThicknessMultiplier();
}

uint32_t sk4d_textstyle_get_decorations(const sk_textstyle_t* self) {
    return ToTextDecoration(AsTextStyle(self)->getDecorationType());
}

size_t sk4d_textstyle_get_font_families(const sk_textstyle_t* self, sk_string_t* result[]) {
    const auto& fontFamilies = AsTextStyle(self)->getFontFamilies();
    size_t count = fontFamilies.size();
    if (result != nullptr) {
        for (size_t i = 0; i < count; i++)
            *AsString(result[i]) = fontFamilies[i];
    }
    return count;
}

void sk4d_textstyle_get_font_metrics(const sk_textstyle_t* self, sk_fontmetrics_t* metrics) {
    AsTextStyle(self)->getFontMetrics(AsFontMetrics(metrics));
}

float sk4d_textstyle_get_font_size(const sk_textstyle_t* self) {
    return AsTextStyle(self)->getFontSize();
}

void sk4d_textstyle_get_font_style(const sk_textstyle_t* self, sk_fontstyle_t* result) {
    *result = ToFontStyle(AsTextStyle(self)->getFontStyle());
}

sk_paint_t* sk4d_textstyle_get_foreground(const sk_textstyle_t* self) {
    return ToPaint(new SkPaint(AsTextStyle(self)->getForeground()));
}

float sk4d_textstyle_get_height(const sk_textstyle_t* self) {
    return AsTextStyle(self)->getHeight();
}

bool sk4d_textstyle_get_height_override(const sk_textstyle_t* self) {
    return AsTextStyle(self)->getHeightOverride();
}

float sk4d_textstyle_get_letter_spacing(const sk_textstyle_t* self) {
    return AsTextStyle(self)->getLetterSpacing();
}

sk_string_t* sk4d_textstyle_get_locale(const sk_textstyle_t* self) {
    return ToString(new SkString(AsTextStyle(self)->getLocale()));
}

sk_textbaseline_t sk4d_textstyle_get_text_baseline(const sk_textstyle_t* self) {
    return  ToTextBaseline(AsTextStyle(self)->getTextBaseline());
}

sk_typeface_t* sk4d_textstyle_get_typeface(const sk_textstyle_t* self) {
    return ToTypeface(AsTextStyle(self)->refTypeface().release());
}

float sk4d_textstyle_get_word_spacing(const sk_textstyle_t* self) {
    return AsTextStyle(self)->getWordSpacing();
}

bool sk4d_textstyle_has_background(const sk_textstyle_t* self) {
    return AsTextStyle(self)->hasBackground();
}

bool sk4d_textstyle_has_foreground(const sk_textstyle_t* self) {
    return AsTextStyle(self)->hasForeground();
}

bool sk4d_textstyle_is_equal(const sk_textstyle_t* self, const sk_textstyle_t* text_style) {
    return AsTextStyle(*self) == AsTextStyle(*text_style);
}

bool sk4d_textstyle_is_placeholder(const sk_textstyle_t* self) {
    return AsTextStyle(self)->isPlaceholder();
}

void sk4d_textstyle_reset_font_features(sk_textstyle_t* self) {
    AsTextStyle(self)->resetFontFeatures();
}

void sk4d_textstyle_reset_shadows(sk_textstyle_t* self) {
    AsTextStyle(self)->resetShadows();
}

void sk4d_textstyle_set_background_color(sk_textstyle_t* self, sk_paint_t* paint) {
    AsTextStyle(self)->setBackgroundColor(*AsPaint(paint));
}

void sk4d_textstyle_set_color(sk_textstyle_t* self, sk_color_t value) {
    AsTextStyle(self)->setColor(value);
}

void sk4d_textstyle_set_decoration_color(sk_textstyle_t* self, sk_color_t value) {
    AsTextStyle(self)->setDecorationColor(value);
}

void sk4d_textstyle_set_decoration_mode(sk_textstyle_t* self, sk_textdecorationmode_t value) {
    AsTextStyle(self)->setDecorationMode(AsTextDecorationMode(value));
}

void sk4d_textstyle_set_decoration_style(sk_textstyle_t* self, sk_textdecorationstyle_t value) {
    AsTextStyle(self)->setDecorationStyle(AsTextDecorationStyle(value));
}

void sk4d_textstyle_set_decoration_thickness_multiplier(sk_textstyle_t* self, float value) {
    AsTextStyle(self)->setDecorationThicknessMultiplier(value);
}

void sk4d_textstyle_set_decorations(sk_textstyle_t* self, uint32_t value) {
    AsTextStyle(self)->setDecoration(AsTextDecoration(value));
}

void sk4d_textstyle_set_font_families(sk_textstyle_t* self, const sk_string_t* values[], size_t count) {
    std::vector<SkString> fontFamilies(count);
    for (size_t i = 0; i < count; i++)
        fontFamilies[i] = *AsString(values[i]);
    AsTextStyle(self)->setFontFamilies(fontFamilies);
}

void sk4d_textstyle_set_font_size(sk_textstyle_t* self, float value) {
    AsTextStyle(self)->setFontSize(value);
}

void sk4d_textstyle_set_font_style(sk_textstyle_t* self, const sk_fontstyle_t* value) {
    AsTextStyle(self)->setFontStyle(AsFontStyle(value));
}

void sk4d_textstyle_set_foreground_color(sk_textstyle_t* self, sk_paint_t* paint) {
    AsTextStyle(self)->setForegroundColor(*AsPaint(paint));
}

void sk4d_textstyle_set_height(sk_textstyle_t* self, float value) {
    AsTextStyle(self)->setHeight(value);
}

void sk4d_textstyle_set_height_override(sk_textstyle_t* self, bool value) {
    AsTextStyle(self)->setHeightOverride(value);
}

void sk4d_textstyle_set_letter_spacing(sk_textstyle_t* self, float value) {
    AsTextStyle(self)->setLetterSpacing(value);
}

void sk4d_textstyle_set_locale(sk_textstyle_t* self, const sk_string_t* value) {
    AsTextStyle(self)->setLocale(AsString(*value));
}

void sk4d_textstyle_set_place_holder(sk_textstyle_t* self) {
    AsTextStyle(self)->setPlaceholder();
}

void sk4d_textstyle_set_text_baseline(sk_textstyle_t* self, sk_textbaseline_t value) {
    AsTextStyle(self)->setTextBaseline(AsTextBaseline(value));
}

void sk4d_textstyle_set_typeface(sk_textstyle_t* self, sk_typeface_t* value) {
    AsTextStyle(self)->setTypeface(sk_ref_sp(AsTypeface(value)));
}

void sk4d_textstyle_set_word_spacing(sk_textstyle_t* self, float value) {
    AsTextStyle(self)->setWordSpacing(value);
}
