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

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

glyph-module

glyph-block Letter-Greek-Lower-Kappa : begin
	glyph-block-import CommonShapes
	glyph-block-import Common-Derivatives
	glyph-block-import Letter-Shared-Shapes : PalatalHook

	define [DfKappasymbol] : DivFrame 1 3

	create-glyph "grek/kappaSymbol" 0x3F0 : glyph-proc
		local df : DfKappasymbol
		include : df.markSet.e
		define xLeft : df.leftSB + [HSwToV : 0.25 * df.mvs]
		define xRight : df.rightSB - [HSwToV : 0.25 * df.mvs]
		define yBottom : 0 + 0.2 * Stroke
		define yTop : XH - 0.2 * Stroke

		define deltaX : TINY * (xRight - xLeft)
		define deltaY : TINY * (yTop - yBottom)

		define swTerm : AdviceStroke 3
		define swTermThin : swTerm * CThinB

		define kArcX 0.08
		define kArcY 0.3
		define kSwMid 0.1

		include : dispiro [widths.center swTerm] [flat xLeft yBottom] [curl xRight yTop]

		include : dispiro [widths.center]
			straight.right.start df.leftSB (XH - HalfStroke) [heading Rightward]
			archv
			g2 (df.leftSB + 0.625 * HookX) (XH - SHook - HalfStroke) [widths.center df.mvs]
			alsoThru.g2 kArcX kArcY : widths
				mix (df.mvs / 2) (swTermThin / 2) kSwMid
				mix (df.mvs / 2) (swTerm / 2) kSwMid
			g2 (xLeft + deltaX) (yBottom + deltaY) [widths (swTermThin / 2) (swTerm / 2)]
			g2 xLeft yBottom
		include : dispiro [widths.center]
			straight.left.start df.rightSB (0 + HalfStroke) [heading Leftward]
			archv
			g2 (df.rightSB - 0.625 * HookX) (0 + SHook + HalfStroke) [widths.center df.mvs]
			alsoThru.g2 kArcX kArcY : widths
				mix (df.mvs / 2) (swTermThin / 2) kSwMid
				mix (df.mvs / 2) (swTerm / 2) kSwMid
			g2 (xRight - deltaX) (yTop - deltaY) [widths (swTermThin / 2) (swTerm / 2)]
			g2 xRight yTop

	create-glyph "grek/kaiSymbol" 0x3D7 : glyph-proc
		include [refer-glyph "grek/kappaSymbol"] AS_BASE ALSO_METRICS
		local df : DfKappasymbol
		include : PalatalHook.rExt df.rightSB 0 (sw -- df.mvs) (yAttach -- Stroke)
