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

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


glyph-module

glyph-block Letter-Latin-Egyptological : begin
	glyph-block-import CommonShapes
	glyph-block-import Common-Derivatives

	define [EgyptologicalYodComponent sw x bot top] : glyph-proc
		local rad : (top - bot) / 2
		local wid : rad * 1.2
		local balance : wid * 0.55
		include : dispiro
			widths.rhs sw
			g4.right.start (x - balance)       (top - O)         [heading Rightward]
			archv
			g4.down.mid    (x + wid - balance) [mix bot top 0.5] [heading Downward]
			arcvh
			g4.left.end    (x - balance)       (bot + O)         [heading Leftward]

	define [EgyptologicalAyinComponent sw x bot top] : glyph-proc
		local rad : (top - bot) / 2
		local wid : rad * 1.2
		local balance : wid * 0.55
		include : dispiro
			widths.lhs sw
			g4.left.start (x + balance)       (top - O)         [heading Leftward]
			archv
			g4.down.mid   (x - wid + balance) [mix bot top 0.5] [heading Downward]
			arcvh
			g4.right.end  (x + balance)       (bot + O)         [heading Rightward]

	define [EgyptologicalAlefShape bot top] : glyph-proc
		local sw : AdviceStroke2 4 4 top
		local gap : Math.max (sw / 2) (top / 12)
		local rad : (top - gap) / 4
		include : EgyptologicalYodComponent sw Middle (top - rad * 2) top
		include : EgyptologicalYodComponent sw Middle bot (bot + rad * 2)

	define [EgyptologicalAyinShape bot top] : glyph-proc
		local sw : AdviceStroke2 4 4 top
		local gap : Math.max (sw / 2) (top / 12)
		local rad : (top + gap) / 4
		include : EgyptologicalAyinComponent sw Middle (top - rad * 2) top

	create-glyph 'EgyptologicalCapitalAlef' 0xA722 : glyph-proc
		include : MarkSet.capital
		include : EgyptologicalAlefShape 0 CAP

	create-glyph 'EgyptologicalSmallAlef'   0xA723 : glyph-proc
		include : MarkSet.e
		include : EgyptologicalAlefShape 0 XH # Per Unicode chart

	create-glyph 'EgyptologicalCapitalAyin' 0xA724 : glyph-proc
		include : MarkSet.capital
		include : EgyptologicalAyinShape 0 CAP

	create-glyph 'EgyptologicalSmallAyin'   0xA725 : glyph-proc
		include : MarkSet.e
		include : EgyptologicalAyinShape 0 XH # Per Unicode chart

	glyph-block-import Mark-Shared-Metrics : markMiddle
	glyph-block-import Mark-Above : aboveMarkTop aboveMarkBot aboveMarkMid aboveMarkStack

	create-glyph 'EgyptologicalYodAbove' : glyph-proc
		set-width 0
		set-mark-anchor 'above' markMiddle XH markMiddle aboveMarkStack
		set-base-anchor 'aboveBraceL' markMiddle aboveMarkMid
		set-base-anchor 'aboveBraceR' markMiddle aboveMarkMid
		local fine : AdviceStroke 5
		include : EgyptologicalYodComponent fine markMiddle aboveMarkBot aboveMarkTop

	create-glyph 'EgyptologicalYodTonos' : glyph-proc
		set-width 0
		include : refer-glyph 'EgyptologicalYodAbove'
		set-mark-anchor 'grekUpperTonos' markMiddle XH
		set-base-anchor 'aboveBraceL' markMiddle aboveMarkMid
		set-base-anchor 'aboveBraceR' markMiddle aboveMarkMid
