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

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

glyph-module

glyph-block LetterLike-Fraktur-DOQ : 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
	glyph-block-import LetterLike-Fraktur-Common : Wave FHook PHexTop PHexBot CutMaskUp CutMaskDown

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

		local box : S.box CAP 0 df.leftSB df.rightSB
		local frame : include : lift-@ : fraktur-stroke S
			cg2.ru.start (@xLB = box.left - 0.25 * DecoSizeX) (@yB = box.bottom)
			~~~ [g2.right.mid [mix @xLB @xB (1/3)] (@yB + Wave.DepthY - O)]
			g2 (@xB = [box.xp 0.625]) (@yB + O)
			~~~ [archv]
			straight.up.mid (box.right - OX) [box.yp 0.5]
			arch.lhs (sw -- S.thick) (blendPost -- {}) (@yT = box.top)
			corner [T.connL S : @xLB - 0.25 * DecoSizeX] [T.connB S : @yT - FHook] [change-pen T]

		local inner : include : intersection
			union
				intersection [MaskAbove : box.yMid - TINY] [frame.withPen CutMaskDown]
				intersection [MaskBelow : box.yMid + TINY] [frame.withPen CutMaskUp]
			lift-@ : fraktur-stroke S
				corner (@xS = [frame.first 2].x) [frame.first 2].y
				~~~ [Wave.vc (0.75 * Wave.DepthX)]
				corner @xS (box.top - 0.25 * SHook)
				corner @xS  box.top


	define [FrakOShape box] : lift-@ : fraktur-stroke S
		cg2.ru.start (@xLB = box.left - 0.25 * DecoSizeX) (@yB = box.bottom)
		~~~ [g2.right.mid (@xLB2 = [mix @xLB @xB (1/3)]) (@yLB2 = @yB + Wave.DepthY - O)]
		g2 (@xB = [box.xp 0.625]) (@yB + O)
		~~~ [archv]
		straight.up.mid (box.right - OX) [box.yp 0.5]
		arch.lhs (sw -- S.thick) (blendPost -- {}) (@yT = box.top)
		~~~ [corner (@xTI = [box.xp 0.25]) (@yTI = @yT - FHook)]
		corner (@xTL = @xTI - DecoSizeX) (@yTI + DecoSizeY)
		~~~ [Wave.vc (0.75 * -Wave.DepthX)]
		corner @xLB2 @yLB2

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

		local box : S.box CAP 0 df.leftSB df.rightSB
		include : FrakOShape box

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

		local box : S.box CAP 0 df.leftSB df.rightSB
		local frame : include : FrakOShape box

		include : with-knockout [frame.withPen CutMaskUp] : lift-@ : fraktur-stroke S
			corner (@xR + DecoSizeX)           (@yR + DecoSizeY)
			corner (@xR = box.right + O)       (@yR = box.bottom + O)
			corner (@xL = @xR - 2 * DecoSizeX) [slY @xR @yR @xL SlopeB]
