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

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

glyph-module

glyph-block Letter-Cyrillic-Dje : begin
	glyph-block-import CommonShapes
	glyph-block-import Common-Derivatives
	glyph-block-import Letter-Shared-Shapes : MidHook

	create-glyph 'cyrl/Dje' 0x402 : glyph-proc
		local df : include : DivFrame para.advanceScaleT
		include : df.markSet.capital

		local sw : AdviceStroke 2.75
		local left : [mix df.leftSB df.rightSB : if (df.adws <= 1) 0.2 : if SLAB 0.3 0.25] + OX
		local right : df.rightSB - OX

		local xTopBarLeft : df.leftSB - SideJut
		local xTopBarRightSym : 2 * left + [HSwToV sw] - xTopBarLeft
		local xTopBarRight : Math.max xTopBarRightSym : mix left df.rightSB 0.475

		include : VBar.l left 0 CAP sw
		include : HBar.t xTopBarLeft xTopBarRight CAP sw
		include : MidHook.general
			left   -- (left + [HSwToV sw])
			right  -- right
			top    -- [Math.min XH : if SLAB (CAP - VJut - sw / 4) XH]
			bottom -- (Hook + sw / 2 + O)
			ada    -- ArchDepthA
			adb    -- ArchDepthB
			sw     -- sw
			xDepth -- [Math.max ((left - right) / 2 + sw / 2) (HookX * (-1.2))]

		if SLAB : begin
			local swVJut : Math.min (0.625 * (left - xTopBarLeft)) : AdviceStroke 4.5
			include : HSerif.lb left 0 SideJut
			include : VSerif.dl xTopBarLeft  CAP VJut swVJut
			include : VSerif.dr xTopBarRight CAP VJut swVJut
