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

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

glyph-module

glyph-block LetterLike-Fraktur-X : begin
	glyph-block-import Common-Derivatives
	glyph-block-import CommonShapes
	glyph-block-import LetterLike-Fraktur-Common : UpperDf LowerDf S M F T fraktur-stroke change-pen
	glyph-block-import LetterLike-Fraktur-Common : DecoSizeX DecoSizeY SlopeA SlopeB CutMaskLeft
	glyph-block-import LetterLike-Fraktur-Common : Wave FHook PHexTop PHexBot

	define [XShapeHalf pen box] : glyph-proc
		include : lift-@ : fraktur-stroke pen
			corner (@xL - DecoSizeX)   (@yT - DecoSizeY)
			corner (@xL = box.left)    (@yT = box.top)
			straight.down.mid box.xMid  box.yMid
			corner  @xL                (@yB = box.bot)
			corner (@xL - DecoSizeX)   (@yB + DecoSizeY)

	define [XSHapeImpl pen box] : glyph-proc
		local bodyBox : box.withXPadding (0.5 * DecoSizeX)
		include : XShapeHalf pen bodyBox
		include : FlipAround box.xMid box.yMid
		include : XShapeHalf pen bodyBox
		include : lift-@ : fraktur-stroke F
			corner (@xL = [box.xp 0.25] - 0.5 * DecoSizeX) [slY @xM @yM @xL : 0.25 * SlopeA]
			corner (@xM = box.xMid)                        (@yM = box.yMid)
			corner (@xR = [box.xp 0.75])                   (@yR = [slY @xM @yM @xR : 0.25 * SlopeA])
			corner (@xR + 0.5 * DecoSizeX)                 (@yR - 0.5 * DecoSizeY)

	create-glyph "frak/X" 0x1D51B : glyph-proc
		local df : include : UpperDf 1
		include : df.markSet.capital

		local xBox : S.box CAP 0 df.leftSB df.rightSB
		include : XSHapeImpl S xBox

	create-glyph "frak/x" 0x1D535 : glyph-proc
		local df : include : LowerDf 1
		include : df.markSet.e

		local xBox : S.box XH 0 df.leftSB df.rightSB
		include : XSHapeImpl S xBox
