#pragma once

#include <eepp/config.hpp>
#include <eepp/math/vector2.hpp>

using namespace EE::Math;

namespace EE::Graphics {

class FontTrueType;

/** TextDirection values are the same as in hb_direction_t from HarfBuzz */
enum class TextDirection : Uint8 {
	Unspecified = 0, //!< Unspecified
	LeftToRight = 4, //!< Left-to-right
	RightToLeft,	 //!< Right-to-left
	TopToBottom,	 //!< Top-to-bottom
	BottomToTop		 //!< Bottom-to-top
};

/** LangScript values are the same as in hb_script_t from HarfBuzz */
enum class LangScript : Uint32 {
	COMMON = EE_TAG( 'Z', 'y', 'y', 'y' ),
	INHERITED = EE_TAG( 'Z', 'i', 'n', 'h' ),
	UNKNOWN = EE_TAG( 'Z', 'z', 'z', 'z' ),
	ARABIC = EE_TAG( 'A', 'r', 'a', 'b' ),
	ARMENIAN = EE_TAG( 'A', 'r', 'm', 'n' ),
	BENGALI = EE_TAG( 'B', 'e', 'n', 'g' ),
	CYRILLIC = EE_TAG( 'C', 'y', 'r', 'l' ),
	DEVANAGARI = EE_TAG( 'D', 'e', 'v', 'a' ),
	GEORGIAN = EE_TAG( 'G', 'e', 'o', 'r' ),
	GREEK = EE_TAG( 'G', 'r', 'e', 'k' ),
	GUJARATI = EE_TAG( 'G', 'u', 'j', 'r' ),
	GURMUKHI = EE_TAG( 'G', 'u', 'r', 'u' ),
	HANGUL = EE_TAG( 'H', 'a', 'n', 'g' ),
	HAN = EE_TAG( 'H', 'a', 'n', 'i' ),
	HEBREW = EE_TAG( 'H', 'e', 'b', 'r' ),
	HIRAGANA = EE_TAG( 'H', 'i', 'r', 'a' ),
	KANNADA = EE_TAG( 'K', 'n', 'd', 'a' ),
	KATAKANA = EE_TAG( 'K', 'a', 'n', 'a' ),
	LAO = EE_TAG( 'L', 'a', 'o', 'o' ),
	LATIN = EE_TAG( 'L', 'a', 't', 'n' ),
	MALAYALAM = EE_TAG( 'M', 'l', 'y', 'm' ),
	ORIYA = EE_TAG( 'O', 'r', 'y', 'a' ),
	TAMIL = EE_TAG( 'T', 'a', 'm', 'l' ),
	TELUGU = EE_TAG( 'T', 'e', 'l', 'u' ),
	THAI = EE_TAG( 'T', 'h', 'a', 'i' ),
	TIBETAN = EE_TAG( 'T', 'i', 'b', 't' ),
	BOPOMOFO = EE_TAG( 'B', 'o', 'p', 'o' ),
	BRAILLE = EE_TAG( 'B', 'r', 'a', 'i' ),
	CANADIAN_SYLLABICS = EE_TAG( 'C', 'a', 'n', 's' ),
	CHEROKEE = EE_TAG( 'C', 'h', 'e', 'r' ),
	ETHIOPIC = EE_TAG( 'E', 't', 'h', 'i' ),
	KHMER = EE_TAG( 'K', 'h', 'm', 'r' ),
	MONGOLIAN = EE_TAG( 'M', 'o', 'n', 'g' ),
	MYANMAR = EE_TAG( 'M', 'y', 'm', 'r' ),
	OGHAM = EE_TAG( 'O', 'g', 'a', 'm' ),
	RUNIC = EE_TAG( 'R', 'u', 'n', 'r' ),
	SINHALA = EE_TAG( 'S', 'i', 'n', 'h' ),
	SYRIAC = EE_TAG( 'S', 'y', 'r', 'c' ),
	THAANA = EE_TAG( 'T', 'h', 'a', 'a' ),
	YI = EE_TAG( 'Y', 'i', 'i', 'i' ),
	DESERET = EE_TAG( 'D', 's', 'r', 't' ),
	GOTHIC = EE_TAG( 'G', 'o', 't', 'h' ),
	OLD_ITALIC = EE_TAG( 'I', 't', 'a', 'l' ),
	BUHID = EE_TAG( 'B', 'u', 'h', 'd' ),
	HANUNOO = EE_TAG( 'H', 'a', 'n', 'o' ),
	TAGALOG = EE_TAG( 'T', 'g', 'l', 'g' ),
	TAGBANWA = EE_TAG( 'T', 'a', 'g', 'b' ),
	CYPRIOT = EE_TAG( 'C', 'p', 'r', 't' ),
	LIMBU = EE_TAG( 'L', 'i', 'm', 'b' ),
	LINEAR_B = EE_TAG( 'L', 'i', 'n', 'b' ),
	OSMANYA = EE_TAG( 'O', 's', 'm', 'a' ),
	SHAVIAN = EE_TAG( 'S', 'h', 'a', 'w' ),
	TAI_LE = EE_TAG( 'T', 'a', 'l', 'e' ),
	UGARITIC = EE_TAG( 'U', 'g', 'a', 'r' ),
	BUGINESE = EE_TAG( 'B', 'u', 'g', 'i' ),
	COPTIC = EE_TAG( 'C', 'o', 'p', 't' ),
	GLAGOLITIC = EE_TAG( 'G', 'l', 'a', 'g' ),
	KHAROSHTHI = EE_TAG( 'K', 'h', 'a', 'r' ),
	NEW_TAI_LUE = EE_TAG( 'T', 'a', 'l', 'u' ),
	OLD_PERSIAN = EE_TAG( 'X', 'p', 'e', 'o' ),
	SYLOTI_NAGRI = EE_TAG( 'S', 'y', 'l', 'o' ),
	TIFINAGH = EE_TAG( 'T', 'f', 'n', 'g' ),
	BALINESE = EE_TAG( 'B', 'a', 'l', 'i' ),
	CUNEIFORM = EE_TAG( 'X', 's', 'u', 'x' ),
	NKO = EE_TAG( 'N', 'k', 'o', 'o' ),
	PHAGS_PA = EE_TAG( 'P', 'h', 'a', 'g' ),
	PHOENICIAN = EE_TAG( 'P', 'h', 'n', 'x' ),
	CARIAN = EE_TAG( 'C', 'a', 'r', 'i' ),
	CHAM = EE_TAG( 'C', 'h', 'a', 'm' ),
	KAYAH_LI = EE_TAG( 'K', 'a', 'l', 'i' ),
	LEPCHA = EE_TAG( 'L', 'e', 'p', 'c' ),
	LYCIAN = EE_TAG( 'L', 'y', 'c', 'i' ),
	LYDIAN = EE_TAG( 'L', 'y', 'd', 'i' ),
	OL_CHIKI = EE_TAG( 'O', 'l', 'c', 'k' ),
	REJANG = EE_TAG( 'R', 'j', 'n', 'g' ),
	SAURASHTRA = EE_TAG( 'S', 'a', 'u', 'r' ),
	SUNDANESE = EE_TAG( 'S', 'u', 'n', 'd' ),
	VAI = EE_TAG( 'V', 'a', 'i', 'i' ),
	AVESTAN = EE_TAG( 'A', 'v', 's', 't' ),
	BAMUM = EE_TAG( 'B', 'a', 'm', 'u' ),
	EGYPTIAN_HIEROGLYPHS = EE_TAG( 'E', 'g', 'y', 'p' ),
	IMPERIAL_ARAMAIC = EE_TAG( 'A', 'r', 'm', 'i' ),
	INSCRIPTIONAL_PAHLAVI = EE_TAG( 'P', 'h', 'l', 'i' ),
	INSCRIPTIONAL_PARTHIAN = EE_TAG( 'P', 'r', 't', 'i' ),
	JAVANESE = EE_TAG( 'J', 'a', 'v', 'a' ),
	KAITHI = EE_TAG( 'K', 't', 'h', 'i' ),
	LISU = EE_TAG( 'L', 'i', 's', 'u' ),
	MEETEI_MAYEK = EE_TAG( 'M', 't', 'e', 'i' ),
	OLD_SOUTH_ARABIAN = EE_TAG( 'S', 'a', 'r', 'b' ),
	OLD_TURKIC = EE_TAG( 'O', 'r', 'k', 'h' ),
	SAMARITAN = EE_TAG( 'S', 'a', 'm', 'r' ),
	TAI_THAM = EE_TAG( 'L', 'a', 'n', 'a' ),
	TAI_VIET = EE_TAG( 'T', 'a', 'v', 't' ),
	BATAK = EE_TAG( 'B', 'a', 't', 'k' ),
	BRAHMI = EE_TAG( 'B', 'r', 'a', 'h' ),
	MANDAIC = EE_TAG( 'M', 'a', 'n', 'd' ),
	CHAKMA = EE_TAG( 'C', 'a', 'k', 'm' ),
	MEROITIC_CURSIVE = EE_TAG( 'M', 'e', 'r', 'c' ),
	MEROITIC_HIEROGLYPHS = EE_TAG( 'M', 'e', 'r', 'o' ),
	MIAO = EE_TAG( 'P', 'l', 'r', 'd' ),
	SHARADA = EE_TAG( 'S', 'h', 'r', 'd' ),
	SORA_SOMPENG = EE_TAG( 'S', 'o', 'r', 'a' ),
	TAKRI = EE_TAG( 'T', 'a', 'k', 'r' ),
	BASSA_VAH = EE_TAG( 'B', 'a', 's', 's' ),
	CAUCASIAN_ALBANIAN = EE_TAG( 'A', 'g', 'h', 'b' ),
	DUPLOYAN = EE_TAG( 'D', 'u', 'p', 'l' ),
	ELBASAN = EE_TAG( 'E', 'l', 'b', 'a' ),
	GRANTHA = EE_TAG( 'G', 'r', 'a', 'n' ),
	KHOJKI = EE_TAG( 'K', 'h', 'o', 'j' ),
	KHUDAWADI = EE_TAG( 'S', 'i', 'n', 'd' ),
	LINEAR_A = EE_TAG( 'L', 'i', 'n', 'a' ),
	MAHAJANI = EE_TAG( 'M', 'a', 'h', 'j' ),
	MANICHAEAN = EE_TAG( 'M', 'a', 'n', 'i' ),
	MENDE_KIKAKUI = EE_TAG( 'M', 'e', 'n', 'd' ),
	MODI = EE_TAG( 'M', 'o', 'd', 'i' ),
	MRO = EE_TAG( 'M', 'r', 'o', 'o' ),
	NABATAEAN = EE_TAG( 'N', 'b', 'a', 't' ),
	OLD_NORTH_ARABIAN = EE_TAG( 'N', 'a', 'r', 'b' ),
	OLD_PERMIC = EE_TAG( 'P', 'e', 'r', 'm' ),
	PAHAWH_HMONG = EE_TAG( 'H', 'm', 'n', 'g' ),
	PALMYRENE = EE_TAG( 'P', 'a', 'l', 'm' ),
	PAU_CIN_HAU = EE_TAG( 'P', 'a', 'u', 'c' ),
	PSALTER_PAHLAVI = EE_TAG( 'P', 'h', 'l', 'p' ),
	SIDDHAM = EE_TAG( 'S', 'i', 'd', 'd' ),
	TIRHUTA = EE_TAG( 'T', 'i', 'r', 'h' ),
	WARANG_CITI = EE_TAG( 'W', 'a', 'r', 'a' ),
	AHOM = EE_TAG( 'A', 'h', 'o', 'm' ),
	ANATOLIAN_HIEROGLYPHS = EE_TAG( 'H', 'l', 'u', 'w' ),
	HATRAN = EE_TAG( 'H', 'a', 't', 'r' ),
	MULTANI = EE_TAG( 'M', 'u', 'l', 't' ),
	OLD_HUNGARIAN = EE_TAG( 'H', 'u', 'n', 'g' ),
	SIGNWRITING = EE_TAG( 'S', 'g', 'n', 'w' ),
	ADLAM = EE_TAG( 'A', 'd', 'l', 'm' ),
	BHAIKSUKI = EE_TAG( 'B', 'h', 'k', 's' ),
	MARCHEN = EE_TAG( 'M', 'a', 'r', 'c' ),
	OSAGE = EE_TAG( 'O', 's', 'g', 'e' ),
	TANGUT = EE_TAG( 'T', 'a', 'n', 'g' ),
	NEWA = EE_TAG( 'N', 'e', 'w', 'a' ),
	MASARAM_GONDI = EE_TAG( 'G', 'o', 'n', 'm' ),
	NUSHU = EE_TAG( 'N', 's', 'h', 'u' ),
	SOYOMBO = EE_TAG( 'S', 'o', 'y', 'o' ),
	ZANABAZAR_SQUARE = EE_TAG( 'Z', 'a', 'n', 'b' ),
	DOGRA = EE_TAG( 'D', 'o', 'g', 'r' ),
	GUNJALA_GONDI = EE_TAG( 'G', 'o', 'n', 'g' ),
	HANIFI_ROHINGYA = EE_TAG( 'R', 'o', 'h', 'g' ),
	MAKASAR = EE_TAG( 'M', 'a', 'k', 'a' ),
	MEDEFAIDRIN = EE_TAG( 'M', 'e', 'd', 'f' ),
	OLD_SOGDIAN = EE_TAG( 'S', 'o', 'g', 'o' ),
	SOGDIAN = EE_TAG( 'S', 'o', 'g', 'd' ),
	ELYMAIC = EE_TAG( 'E', 'l', 'y', 'm' ),
	NANDINAGARI = EE_TAG( 'N', 'a', 'n', 'd' ),
	NYIAKENG_PUACHUE_HMONG = EE_TAG( 'H', 'm', 'n', 'p' ),
	WANCHO = EE_TAG( 'W', 'c', 'h', 'o' ),
	CHORASMIAN = EE_TAG( 'C', 'h', 'r', 's' ),
	DIVES_AKURU = EE_TAG( 'D', 'i', 'a', 'k' ),
	KHITAN_SMALL_SCRIPT = EE_TAG( 'K', 'i', 't', 's' ),
	YEZIDI = EE_TAG( 'Y', 'e', 'z', 'i' ),
	CYPRO_MINOAN = EE_TAG( 'C', 'p', 'm', 'n' ),
	OLD_UYGHUR = EE_TAG( 'O', 'u', 'g', 'r' ),
	TANGSA = EE_TAG( 'T', 'n', 's', 'a' ),
	TOTO = EE_TAG( 'T', 'o', 't', 'o' ),
	VITHKUQI = EE_TAG( 'V', 'i', 't', 'h' ),
	MATH = EE_TAG( 'Z', 'm', 't', 'h' ),
	KAWI = EE_TAG( 'K', 'a', 'w', 'i' ),
	NAG_MUNDARI = EE_TAG( 'N', 'a', 'g', 'm' ),

	/* No script set. */
	INVALID = EE_TAG_NONE,
};

struct ShapedGlyph {
	FontTrueType* font{ nullptr };
	Uint32 glyphIndex{ 0 };
	Uint32 stringIndex{ 0 };
	Vector2f position;
	Vector2f advance;
	LangScript script;
	TextDirection direction;
};

} // namespace EE::Graphics
