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

import [mix fallback slY] from "@iosevka/util"

glyph-module

glyph-block LetterLike-Fraktur-Upper-A : begin
	glyph-block-import Common-Derivatives
	glyph-block-import CommonShapes
	glyph-block-import LetterLike-Fraktur-Common : UpperDf S F T fraktur-stroke change-pen
	glyph-block-import LetterLike-Fraktur-Common : DecoSizeX DecoSizeY SlopeA SlopeB
	glyph-block-import LetterLike-Fraktur-Common : Wave PHexTop PHexBot LTDecoration RBDecoration

	create-glyph 'frak/A' 0x1D504 : glyph-proc
		local df : include : UpperDf 1
		include : df.markSet.capital

		local aBox  : S.box CAP 0 df.leftSB df.rightSB

		include : lift-@ : fraktur-stroke F
			g2.ru.start            @xL                           ([aBox.yp 0.625] - 2 * F.thick)
			~~~ [Wave.vc Wave.DepthX]
			g2.ru.mid             (@xL = aBox.left)              (@yT - DecoSizeY) [change-pen S]
			arch.rhs (sw -- S.thick) (blendPre -- null)          (@yT = aBox.top) 0.4
			straight.down.mid     [aBox.xp 0.5]                  [mix @yT @yA 0.375]
			[flatc.sl SlopeA].end (@xA = @xL - 0.25 * DecoSizeX) (@yA = [slY @xB @yB @xA SlopeB])
			corner                (@xB = [aBox.xp PHexBot])      (@yB = aBox.bot)
			corner                (@xR = aBox.right)             [slY @xB @yB @xR SlopeA]

		include : lift-@ : fraktur-stroke S
			corner (@x2 - DecoSizeX) (@y2 - DecoSizeY)
			corner (@x2 = aBox.right) (@y2 = aBox.top)
			RBDecoration @x2 aBox.bot

	create-glyph 'frak/U' 0x1D518 : glyph-proc
		local df : include : UpperDf 1
		include : df.markSet.capital

		local uBox  : S.box CAP 0 df.leftSB df.rightSB
		local uDeco : uBox.padLeft (-0.25 * DecoSizeX) # top-left decoration ref box
		local uBody : uBox.padLeft (+1.50 * DecoSizeX) # body ref box

		include : lift-@ : fraktur-stroke S
			LTDecoration.g2 [mix uDeco.left uBody.left 0.5] (@yT = uBody.top) nothing
			g2.down.mid      uBody.left                     [mix @yT @yL 0.45]
			corner          (@xL = uDeco.left)              (@yL = [slY @xB @yB @xL SlopeB])
			corner          (@xB = [uDeco.xp PHexBot])      (@yB = uDeco.bot)
			corner          (@xR = uDeco.right)             [slY @xB @yB @xR SlopeA]

		include : lift-@ : fraktur-stroke S
			corner (@x2 - DecoSizeX) (@y2 - DecoSizeY)
			corner (@x2 = uDeco.right) (@y2 = uDeco.top)
			RBDecoration @x2 uBox.bot
