$$include '../../meta/macros.ptl'

import [mix linreg clamp fallback] from "@iosevka/util"
import [DependentSelector] from "@iosevka/glyph/relation"

glyph-module

glyph-block Letter-Armenian-To : begin
	glyph-block-import CommonShapes
	glyph-block-import Common-Derivatives
	glyph-block-import Letter-Shared-Shapes : SerifFrame

	# Common Params
	define barPos : XH / 2
	define highBarPos XH
	define jut Jut

	do "T'o"
		create-glyph 'armn/To' 0x539 : glyph-proc
			local df : include : DivFrame para.advanceScaleT
			include : df.markSet.capital
			local fine : df.adviceStroke2 3 3 XH
			local cofine : Math.min fine : VSwToH : (df.rightSB - df.leftSB) / 2 - [HSwToV df.mvs]
			local barPosT : barPos + fine / 2
			include : dispiro
				widths.rhs df.mvs
				flat df.leftSB 0 [heading Upward]
				curl df.leftSB [if (df.archDepthA + df.archDepthB < CAP) (CAP - df.archDepthA) : mix CAP 0 (df.archDepthA / (df.archDepthA + df.archDepthB))]
				arch.rhs CAP (sw -- df.mvs)
				flatside.rd df.rightSB 0 CAP df.archDepthA df.archDepthB 0
				arch.rhs 0 (sw -- df.mvs) (swAfter -- cofine)
				g4 (df.middle - [HSwToV : 0.5 * cofine]) [mix 0 barPosT (df.archDepthB / (df.archDepthA + df.archDepthB))] [widths.rhs cofine]
				arcvh
				flat [mix (df.middle - [HSwToV : 0.5 * cofine]) df.rightSB 0.5] barPosT [widths.rhs fine]
				curl (df.rightSB + jut * [if SLAB 1.5 1] - [HSwToV : 0.5 * df.mvs]) barPosT [heading Rightward]
			if SLAB : begin
				local sf : SerifFrame.fromDf df CAP 0
				include sf.lb.full

		create-glyph 'armn/to' 0x569 : glyph-proc
			local df : include : DivFrame para.advanceScaleT
			include : df.markSet.p
			local fine : df.adviceStroke2 3 3 XH
			local cofine : Math.min fine : VSwToH : (df.rightSB - df.leftSB) / 2 - [HSwToV df.mvs]
			local barPosT : barPos + fine / 2
			include : VBar.l df.leftSB Descender XH df.mvs
			include : dispiro
				widths.rhs df.shoulderFine
				straight.up.start (df.leftSB + [HSwToV : df.mvs - df.shoulderFine]) [if (df.smallArchDepthA + df.smallArchDepthB < XH) (XH - df.smallArchDepthA) : mix XH 0 (df.smallArchDepthA / (df.smallArchDepthA + df.smallArchDepthB))] [heading Upward]
				arch.rhs XH (sw -- df.mvs) (swBefore -- df.shoulderFine)
				flatside.rd df.rightSB 0 XH df.smallArchDepthA df.smallArchDepthB 0 [widths.rhs df.mvs]
				arch.rhs 0 (sw -- df.mvs) (swAfter -- cofine)
				g4 (df.middle - [HSwToV : 0.5 * cofine]) [mix 0 barPosT (df.smallArchDepthB / (df.smallArchDepthA + df.smallArchDepthB))] [widths.rhs cofine]
				arcvh
				flat [mix (df.middle - [HSwToV : 0.5 * cofine]) df.rightSB 0.5] barPosT [widths.rhs fine]
				curl (df.rightSB + jut * [if SLAB 1.5 1] - [HSwToV : 0.5 * df.mvs]) barPosT [heading Rightward]
			if SLAB : begin
				local sf : SerifFrame.fromDf df XH Descender
				include : composite-proc sf.lt.outer sf.lb.fullSide
