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

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


glyph-module

glyph-block Letter-Latin-Hwair : begin
	glyph-block-import CommonShapes
	glyph-block-import Common-Derivatives
	glyph-block-import Mark-Adjustment : LeaningAnchor
	glyph-block-import Letter-Shared-Shapes : nShoulder SerifFrame

	define Variants : object
		straightSerifless      { false false }
		straightTopLeftSerifed { true  false }
		straightSerifed        { true  true  }

	foreach { suffix { serifLT serifLB } } [pairs-of Variants] : do
		create-glyph "hwair.\(suffix)" : glyph-proc
			local df : include : DivFrame para.advanceScaleMM 3
			include : df.markSet.b
			include : LeaningAnchor.Above.VBar.l df.leftSB
			include : VBar.l df.leftSB 0 Ascender df.mvs
			include : dispiro
				nShoulder.knots (df.leftSB + [HSwToV df.mvs]) (df.middle + [HSwToV : 0.5 * df.mvs]) (df.mvs * 0.4) nothing (XH * 0.51) (SmallArchDepthA * 0.6 * df.adws) (SmallArchDepthB * 0.6 * df.adws) df.mvs
				flat (df.middle + [HSwToV : 0.5 * df.mvs]) (XH * 0.5) [heading Downward]
				curl (df.middle + [HSwToV : 0.5 * df.mvs]) (SmallArchDepthB * 0.6 * df.adws)
				arcvh
				g4 [mix (df.middle - [HSwToV : 0.5 * df.mvs]) df.rightSB 0.5] O [widths.heading df.mvs 0 Rightward]
				archv
				flat df.rightSB (SmallArchDepthA * 0.6 * df.adws)
				curl df.rightSB XH [heading Upward]

			do "slabs"
				local sf1 : SerifFrame.fromDf df Ascender 0
				local sf2 : [SerifFrame.fromDf df XH 0].slice 1 2
				local jut : Jut * 0.75
				if serifLT : include : tagged 'serifLT' sf1.lt.outer
				if serifLB : include : tagged 'serifLB' sf1.lb.full
				if SLAB    : include : tagged 'serifRT' sf2.rt.full

	select-variant 'hwair' 0x195 (follow -- 'heng')
