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

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

glyph-module

glyph-block Symbol-Pictograph-Flags : begin
	glyph-block-import CommonShapes
	glyph-block-import Common-Derivatives

	local sw : AdviceStroke 5
	local flagDown : 0.07 * (ParenTop - ParenBot)
	local delta 1
	local curliness 0.85
	define [FlagBar] : VBar.m SB PictBot PictTop sw

	create-glyph 'blackflag' 0x2691 : glyph-proc
		include : spiro-outline
			corner SB PictTop
			curl (SB + delta) PictTop
			alsoThru 0.5 (1 - curliness)
			g4 Middle (PictTop - flagDown / 2)
			alsoThru 0.5 curliness
			flat (RightSB - delta) (PictTop - flagDown)
			corner RightSB (PictTop - flagDown)
			corner RightSB (SymbolMid - flagDown)
			curl (RightSB - delta) (SymbolMid - flagDown)
			alsoThru 0.5 (1 - curliness)
			g4 Middle (SymbolMid - flagDown / 2)
			alsoThru 0.5 curliness
			flat (SB + delta) SymbolMid
			corner SB SymbolMid
			close
		include : Translate [HSwToV : 0.5 * sw] 0
		include : FlagBar

	create-glyph 'whiteflag' 0x2690 : glyph-proc
		include : VBar.r RightSB (SymbolMid - flagDown) (PictTop - flagDown) sw
		include : dispiro
			widths.rhs sw
			flat SB PictTop [heading Rightward]
			curl (SB + delta) PictTop [heading Rightward]
			alsoThru 0.5 (1 - curliness)
			g4 Middle (PictTop - flagDown / 2)
			alsoThru 0.5 curliness
			flat (RightSB - delta) (PictTop - flagDown) [heading Rightward]
			curl RightSB (PictTop - flagDown) [heading Rightward]
		include : dispiro
			widths.rhs sw
			flat RightSB ((SymbolMid - sw / 2) - flagDown) [heading Leftward]
			curl (RightSB - delta) ((SymbolMid - sw / 2) - flagDown) [heading Leftward]
			alsoThru 0.5 (1 - curliness)
			g4 Middle ((SymbolMid - sw / 2) - flagDown / 2)
			alsoThru 0.5 curliness
			flat (SB + delta) (SymbolMid - sw / 2) [heading Leftward]
			curl SB (SymbolMid - sw / 2) [heading Leftward]
		include : Translate [HSwToV : 0.5 * sw] 0
		include : FlagBar
