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

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

glyph-module

glyph-block LetterLike-Fraktur-Upper-F : begin
	glyph-block-import Common-Derivatives
	glyph-block-import CommonShapes
	glyph-block-import LetterLike-Fraktur-Common : UpperDf 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

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

		local fBox : S.box CAP 0 df.leftSB df.rightSB
		local topStroke : include : lift-@ : fraktur-stroke S
			g2.ld.start (@xR = fBox.right) (@yT = fBox.top)
			~~~ [Wave.h O]
			g2.ld.end (@xL = fBox.left) (@yT - Wave.DepthY) [change-pen F]
			~~~ [Wave.vc (-Wave.DepthX)]
			g2.ld.end @xL ([fBox.yp 0.625] - 2 * F.thick)

		local mainStroke : include : lift-@ : fraktur-stroke S
			[g2.sl (2 * SlopeA)].start fBox.xMid (fBox.top - 0.5 * Wave.DepthY)
			g2 [fBox.xp 0.875] (@yB + ArchDepthB)
			hookend (sw -- S.thick) (@yB = fBox.bot)
			g2 fBox.left (@yB + SHook)

		include : with-knockout [mainStroke.withPen CutMaskLeft] : lift-@ : fraktur-stroke F
			corner (@xR = [F.connR S fBox.right]) [slY @xMR @yMR @xR SlopeB]
			corner (@xMR = fBox.right - 0.5 * DecoSizeX) (@yMR = [slY @xM @yM @xMR SlopeA])
			corner (@xM = fBox.xMid) (@yM = [mix (fBox.top - 0.5 * Wave.DepthY) (fBox.bot + ArchDepthB) 0.5])

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

		local tBox : S.box CAP 0 df.leftSB df.rightSB
		local topStroke : include : lift-@ : fraktur-stroke S
			g2.ld.start tBox.right (@yT = tBox.top)
			~~~ [Wave.h O]
			g2.ld.end (@xL = tBox.left) (@yT - Wave.DepthY) [change-pen F]
			~~~ [Wave.vc (-Wave.DepthX)]
			g2.ld.end @xL ([tBox.yp 0.625] - 2 * F.thick)

		local bottomStroke : include : fraktur-stroke S
			g2.ld.end tBox.right (tBox.bottom + Wave.DepthY)
			~~~ [Wave.h O]
			g2.ld.start tBox.left tBox.bottom

		local middleStroke : include : fraktur-stroke S
			g2 tBox.xMid (tBox.bottom + 0.5 * Wave.DepthY)
			~~~ [Wave.vc Wave.DepthX]
			g2 tBox.xMid (tBox.top - 0.5 * Wave.DepthY)
