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

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

glyph-module

glyph-block Letter-Cyrillic-Tshe : begin
	glyph-block-import CommonShapes
	glyph-block-import Common-Derivatives
	glyph-block-import Letter-Shared-Shapes : nShoulder

	create-glyph 'cyrl/Tshe' 0x40B : 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 : SB - SideJut
		local xTopBarRightSym : 2 * left + [HSwToV sw] - xTopBarLeft
		local xTopBarRight : Math.max xTopBarRightSym : mix left df.rightSB 0.475

		include : nShoulder.shape
			left   -- (left + [HSwToV sw])
			right  -- right
			top    -- [Math.min XH : if SLAB (CAP - VJut - sw / 4) XH]
			stroke -- sw
		include : VBar.l left 0 CAP sw
		include : HBar.t xTopBarLeft xTopBarRight CAP sw

		if SLAB : begin
			local swVJut : Math.min (0.625 * (left - xTopBarLeft)) : AdviceStroke 4.5
			include : HSerif.mb (left  + [HSwToV : 0.5 * sw]) 0 Jut
			include : HSerif.mb (right - [HSwToV : 0.5 * sw]) 0 Jut
			include : VSerif.dl xTopBarLeft  CAP VJut swVJut
			include : VSerif.dr xTopBarRight CAP VJut swVJut
