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

import [Arcs ShapeConv] from "typo-geom"
import [OffsetCurve BezToContoursSink GEOMETRY_PRECISION] from "@iosevka/geometry/curve-util"
import [mix linreg clamp fallback] from "@iosevka/util"
import [DesignParameters] from "../meta/aesthetics.mjs"
import [ScheduleLeaningMark] from "@iosevka/glyph/relation"
import [Box] from "@iosevka/geometry/box"
import [Point] from "@iosevka/geometry/point"

glyph-module

glyph-block Mark-Above : begin
	glyph-block-import CommonShapes
	glyph-block-import Common-Derivatives

	glyph-block-import Mark-Shared-Metrics : markExtend markStroke markHalfStroke markStress markFine
	glyph-block-import Mark-Shared-Metrics : asciiMarkZoomX asciiMarkZoomY
	glyph-block-import Mark-Shared-Metrics : markMiddle markDotsRadius dialytikaRadius

	glyph-block-export aboveMarkTop aboveMarkBot aboveMarkMid aboveMarkStack
	define aboveMarkTop   (XH + AccentClearance + AccentHeight)
	define aboveMarkBot   (XH + AccentClearance)
	define aboveMarkMid   [mix aboveMarkBot aboveMarkTop 0.5]
	define aboveMarkStack (XH + AccentStackOffset)

	glyph-block-export commaOvershoot commaOvershoot2 commaAboveRadius
	define commaOvershoot  : O * [linreg 16 0 90 (-1) markStroke]
	define commaOvershoot2 : O * [linreg 16 1 90 (-1) markStroke]
	define commaAboveRadius : 0.85 * DotRadius * markHalfStroke / HalfStroke

	glyph-block-export StdAnchors
	define StdAnchors : namespace
		export : define [impl mk padding k fLeaning] : glyph-proc
			if (mk === 'above')
			: then : set-mark-anchor mk markMiddle (XH - padding * AccentHeight) markMiddle (aboveMarkStack + padding * AccentHeight)
			: else : set-mark-anchor mk markMiddle (XH - padding * AccentHeight)
			set-base-anchor 'aboveBraceL' (markMiddle - k * markExtend) aboveMarkMid
			set-base-anchor 'aboveBraceR' (markMiddle + k * markExtend) aboveMarkMid
			if fLeaning : ScheduleLeaningMark.set currentGlyph

		export : define [narrow]       : impl 'above' 0 0    true
		export : define [mediumNarrow] : impl 'above' 0 0.25 true
		export : define [medium]       : impl 'above' 0 0.5  true
		export : define [mediumWide]   : impl 'above' 0 0.75
		export : define [wide]         : impl 'above' 0 1
		export : define [extraWide]    : impl 'above' 0 1.5

	### Above marks
	foreach { suffix { DrawAt kdr } } [Object.entries DotVariants] : do
		create-glyph "dotAbove.\(suffix)" : glyph-proc
			set-width 0
			include : StdAnchors.narrow
			include : DrawAt markMiddle aboveMarkMid (DotRadius * kdr)
			ScheduleLeaningMark.set currentGlyph

		create-glyph "dieresisAbove.\(suffix)" : glyph-proc
			set-width 0
			include : StdAnchors.wide
			include : DrawAt (markMiddle - markExtend) aboveMarkMid (markDotsRadius * kdr)
			include : DrawAt (markMiddle + markExtend) aboveMarkMid (markDotsRadius * kdr)

		create-glyph "dieresisAboveAlwaysUpright.\(suffix)" : glyph-proc
			set-width 0
			include : StdAnchors.wide
			include : ForceUpright
			include : DrawAt (markMiddle - markExtend) aboveMarkMid (markDotsRadius * kdr)
			include : DrawAt (markMiddle + markExtend) aboveMarkMid (markDotsRadius * kdr)

		create-glyph "dialytikaAbove.\(suffix)" : glyph-proc
			set-width 0
			include : DrawAt (markMiddle - markExtend * 1.25) aboveMarkMid (dialytikaRadius * kdr)
			include : DrawAt (markMiddle + markExtend * 1.25) aboveMarkMid (dialytikaRadius * kdr)

		create-glyph "tripleDotAbove.\(suffix)" : glyph-proc
			set-width 0
			local height : markExtend * [Math.sqrt 3]
			set-mark-anchor 'above' markMiddle XH markMiddle (aboveMarkStack + height)
			set-base-anchor 'aboveBraceL' (markMiddle - markExtend) (aboveMarkMid + height / 2)
			set-base-anchor 'aboveBraceR' (markMiddle + markExtend) (aboveMarkMid + height / 2)

			include : DrawAt (markMiddle - markExtend) aboveMarkMid (markDotsRadius * kdr)
			include : DrawAt (markMiddle + markExtend) aboveMarkMid (markDotsRadius * kdr)
			include : DrawAt markMiddle (aboveMarkMid + height) (markDotsRadius * kdr)

		create-glyph "elipsisAbove.\(suffix)" : glyph-proc
			set-width 0
			include : StdAnchors.wide
			local fine : Math.min (markDotsRadius * kdr) (markExtend * 0.375)
			local coFine : markExtend * 1.5 - fine
			include : DrawAt (markMiddle - coFine) aboveMarkMid fine
			include : DrawAt  markMiddle           aboveMarkMid fine
			include : DrawAt (markMiddle + coFine) aboveMarkMid fine

		create-glyph "fourDotsAbove.\(suffix)" : glyph-proc
			set-width 0
			include : StdAnchors.extraWide
			local fine : Math.min (markDotsRadius * kdr) (markExtend * 0.3125)
			local coFine : markExtend * 2 - fine
			include : DrawAt (markMiddle - coFine)     aboveMarkMid fine
			include : DrawAt (markMiddle - coFine / 3) aboveMarkMid fine
			include : DrawAt (markMiddle + coFine / 3) aboveMarkMid fine
			include : DrawAt (markMiddle + coFine)     aboveMarkMid fine

	select-variant 'dotAbove'             0x307 (follow -- 'diacriticDot')
	select-variant 'dieresisAbove'        0x308 (follow -- 'diacriticDot')
	select-variant 'dieresisAboveAlwaysUpright' (follow -- 'diacriticDot')
	select-variant 'dialytikaAbove'             (follow -- 'diacriticDot')
	select-variant 'tripleDotAbove'      0x1AB4 (follow -- 'diacriticDot')
	select-variant 'elipsisAbove'        0x20DB (follow -- 'diacriticDot')
	select-variant 'fourDotsAbove'       0x20DC (follow -- 'diacriticDot')
	select-variant 'tittleAbove'       (shapeFrom -- "dotAbove") (follow -- 'tittle')
	select-variant 'i.TRK/tittleAbove' (shapeFrom -- "dotAbove") (follow -- 'diacriticDot')
	select-variant 'kropkaAbove'       (shapeFrom -- "dotAbove") (follow -- 'tittle')

	glyph-block-export RingDims RingShape
	define [RingDims _radiusOut] : begin
		local radiusOut : fallback _radiusOut : AccentHeight * [linreg 16 0.5 90 0.75 markStroke]
		local radiusIn  : radiusOut - markFine * [linreg 16 2 90 1.75 markStroke]
		return [object radiusIn radiusOut]

	define [RingShape cx cy _radiusOut] : glyph-proc
		local [object radiusIn radiusOut] : RingDims _radiusOut
		include : difference
			DotAt cx cy radiusOut
			DotAt cx cy radiusIn

	create-glyph 'ringAbove' 0x30A : glyph-proc
		set-width 0
		include : StdAnchors.medium
		include : RingShape markMiddle aboveMarkMid

	create-glyph 'dblRingAbove' 0x1AB2 : glyph-proc
		set-width 0
		local [object radiusIn radiusOut] : RingDims
		local k : 2 * (radiusOut - (radiusOut - radiusIn) * 0.25)
		include : with-transform [Translate (+k / 2) 0] : refer-glyph 'ringAbove'
		include : with-transform [Translate (-k / 2) 0] : refer-glyph 'ringAbove'
		include : StdAnchors.wide

	foreach { suffix { DrawAt kdr } } [Object.entries DotVariants] : do
		create-glyph "dieresisRingAbove.\(suffix)" : glyph-proc
			set-width 0
			include : StdAnchors.extraWide
			include : RingShape markMiddle aboveMarkMid
			include : DrawAt (markMiddle + markExtend * 1.7) aboveMarkMid (markDotsRadius * kdr)
			include : DrawAt (markMiddle - markExtend * 1.7) aboveMarkMid (markDotsRadius * kdr)

	select-variant 'dieresisRingAbove' 0x1AB1 (follow -- 'diacriticDot')

	create-glyph 'graveAbove' 0x300 : glyph-proc
		set-width 0
		include : StdAnchors.medium
		include : dispiro
			flat (markMiddle + markStress) aboveMarkBot [widths.center : 2 * markFine]
			curl (markMiddle - 0.875 * markExtend) aboveMarkTop [widths.center : 2 * markStress]

	create-glyph 'asciiGrave/body/straight' : glyph-proc
		local df : include : DivFrame para.advanceScaleF
		include : dispiro
			flat (df.middle + HalfStroke * 1.1 * asciiMarkZoomX * [Math.sqrt df.adws]) [mix aboveMarkMid aboveMarkBot asciiMarkZoomY] [widths.center : Stroke * 0.9]
			curl (df.middle - markExtend * asciiMarkZoomX * [Math.sqrt df.adws]) [mix aboveMarkMid aboveMarkTop asciiMarkZoomY] [widths.center : Stroke * 1.1]

	create-glyph 'acuteAbove' 0x301 : glyph-proc
		set-width 0
		include : StdAnchors.medium
		include : dispiro
			flat (markMiddle - markStress) aboveMarkBot [widths.center : 2 * markFine]
			curl (markMiddle + 0.875 * markExtend) aboveMarkTop [widths.center : 2 * markStress]

	create-glyph 'latin1acute' 0xB4 : glyph-proc
		local df : include : DivFrame para.advanceScaleF
		include : dispiro
			flat (df.middle - HalfStroke * 1.1 * asciiMarkZoomX * [Math.sqrt df.adws]) [mix aboveMarkMid aboveMarkBot asciiMarkZoomY] [widths.center : Stroke * 0.9]
			curl (df.middle + markExtend * asciiMarkZoomX * [Math.sqrt df.adws]) [mix aboveMarkMid aboveMarkTop asciiMarkZoomY] [widths.center : Stroke * 1.1]

	glyph-block-export CaretCaronWidth CaretCaronMidSw CaretCaronTerminalSw
	define CaretCaronWidth : 2 * markExtend + markStress
	define CaretCaronMidSw : [StrokeWidthBlend 1.375 1.25] * markStroke
	define CaretCaronTerminalSw : AdviceStroke 5

	glyph-block-export CaretShape
	define [CaretLeftShape] : with-params [top bottom xMiddle width swEnd swMid] : dispiro
		flat (xMiddle - 0.5 * width) bottom [widths.center swEnd]
		curl xMiddle                 top    [widths.center.heading swMid Upward]
	define [CaretRightShape] : with-params [top bottom xMiddle width swEnd swMid] : dispiro
		flat (xMiddle + 0.5 * width) bottom [widths.center swEnd]
		curl xMiddle                 top    [widths.center.heading swMid Upward]
	define [CaretTopBarShape] : with-params [top xMiddle width pL pR swMid swBar] : dispiro
		widths.rhs swBar
		flat [Math.min (xMiddle + 0.5 * width * pL) (xMiddle - [HSwToV : 0.5 * swMid])] top
		curl [Math.max (xMiddle + 0.5 * width * pR) (xMiddle + [HSwToV : 0.5 * swMid])] top
	define [CaretShape] : with-params [top bottom xMiddle width swEnd swMid] : union
		CaretLeftShape  top bottom xMiddle width swEnd swMid
		CaretRightShape top bottom xMiddle width swEnd swMid

	create-glyph 'asciiCaret.high' : glyph-proc
		include : CaretShape
			xMiddle -- Middle
			width   -- (3 * markExtend * asciiMarkZoomX - QuarterStroke)
			top     -- ([mix aboveMarkMid aboveMarkTop asciiMarkZoomY] + HalfStroke)
			bottom  -- [mix aboveMarkMid aboveMarkBot asciiMarkZoomY]
			swEnd   -- (Stroke * 1.05)
			swMid   -- ([StrokeWidthBlend 1.25 1] * Stroke)

	create-glyph 'circumflexAbove' 0x302 : glyph-proc
		set-width 0
		include : StdAnchors.medium
		include : CaretShape
			xMiddle -- markMiddle
			width   -- CaretCaronWidth
			top     -- (aboveMarkTop + markFine * 0.7)
			bottom  -- (aboveMarkBot + markStress - markFine)
			swEnd   -- CaretCaronTerminalSw
			swMid   -- CaretCaronMidSw

	create-glyph 'bardownAbove' 0x1DC6 : glyph-proc
		set-width 0
		include : StdAnchors.medium
		include : CaretRightShape
			xMiddle -- markMiddle
			width   -- CaretCaronWidth
			top     -- (aboveMarkTop + markFine * 0.7)
			bottom  -- (aboveMarkBot + markStress - markFine)
			swEnd   -- CaretCaronTerminalSw
			swMid   -- CaretCaronMidSw
		include : CaretTopBarShape
			xMiddle -- markMiddle
			width   -- CaretCaronWidth
			top     -- (aboveMarkTop + markFine * 0.7)
			pL      -- (-1)
			pR      -- 0
			swMid   -- CaretCaronMidSw
			swBar   -- (2 * markFine)

	create-glyph 'upbarAbove' 0x1DC7 : glyph-proc
		set-width 0
		include : StdAnchors.medium
		include : CaretLeftShape
			xMiddle -- markMiddle
			width   -- CaretCaronWidth
			top     -- (aboveMarkTop + markFine * 0.7)
			bottom  -- (aboveMarkBot + markStress - markFine)
			swEnd   -- CaretCaronTerminalSw
			swMid   -- CaretCaronMidSw
		include : CaretTopBarShape
			xMiddle -- markMiddle
			width   -- CaretCaronWidth
			top     -- (aboveMarkTop + markFine * 0.7)
			pL      -- 0
			pR      -- 1
			swMid   -- CaretCaronMidSw
			swBar   -- (2 * markFine)

	define [CaronLeftShape] : with-params [top bottom xMiddle width swEnd swMid] : dispiro
		flat (xMiddle - 0.5 * width) top    [widths.center swEnd]
		curl xMiddle                 bottom [widths.center.heading swMid Downward]
	define [CaronRightShape] : with-params [top bottom xMiddle width swEnd swMid] : dispiro
		flat (xMiddle + 0.5 * width) top    [widths.center swEnd]
		curl xMiddle                 bottom [widths.center.heading swMid Downward]
	define [CaronBottomBarShape] : with-params [bottom xMiddle width pL pR swMid swBar] : dispiro
		widths.lhs swBar
		flat [Math.min (xMiddle + 0.5 * width * pL) (xMiddle - [HSwToV : 0.5 * swMid])] bottom
		curl [Math.max (xMiddle + 0.5 * width * pR) (xMiddle + [HSwToV : 0.5 * swMid])] bottom
	define [CaronShape] : with-params [top bottom xMiddle width swEnd swMid] : union
		CaronLeftShape  top bottom xMiddle width swEnd swMid
		CaronRightShape top bottom xMiddle width swEnd swMid

	create-glyph 'caronAbove' 0x30C : glyph-proc
		set-width 0
		include : StdAnchors.medium
		include : CaronShape
			xMiddle -- markMiddle
			width   -- CaretCaronWidth
			top     -- (aboveMarkTop - markStress + 1.7 * markFine)
			bottom  -- aboveMarkBot
			swEnd   -- CaretCaronTerminalSw
			swMid   -- CaretCaronMidSw

	create-glyph 'barupAbove' 0x1DC4 : glyph-proc
		set-width 0
		include : StdAnchors.medium
		include : CaronRightShape
			xMiddle -- markMiddle
			width   -- CaretCaronWidth
			top     -- (aboveMarkTop - markStress + 1.7 * markFine)
			bottom  -- aboveMarkBot
			swEnd   -- CaretCaronTerminalSw
			swMid   -- CaretCaronMidSw
		include : CaronBottomBarShape
			xMiddle -- markMiddle
			width   -- CaretCaronWidth
			bottom  -- aboveMarkBot
			pL      -- (-1)
			pR      -- 0
			swMid   -- CaretCaronMidSw
			swBar   -- (2 * markFine)

	create-glyph 'downbarAbove' 0x1DC5 : glyph-proc
		set-width 0
		include : StdAnchors.medium
		include : CaronLeftShape
			xMiddle -- markMiddle
			width   -- CaretCaronWidth
			top     -- (aboveMarkTop - markStress + 1.7 * markFine)
			bottom  -- aboveMarkBot
			swEnd   -- CaretCaronTerminalSw
			swMid   -- CaretCaronMidSw
		include : CaronBottomBarShape
			xMiddle -- markMiddle
			width   -- CaretCaronWidth
			bottom  -- aboveMarkBot
			pL      -- 0
			pR      -- 1
			swMid   -- CaretCaronMidSw
			swBar   -- (2 * markFine)

	create-glyph 'dblCircumflexAbove' 0x1AB0 : glyph-proc
		set-width 0
		include : intersection [MaskRight markMiddle]
			with-transform [Translate (+markExtend) 0] : refer-glyph 'circumflexAbove'
		include : intersection [MaskLeft markMiddle]
			with-transform [Translate (-markExtend) 0] : refer-glyph 'circumflexAbove'
		include : StdAnchors.extraWide

	define [TildeKnots] : with-params [ttop tbot leftEnd rightEnd hs] : glyph-proc
		local fine : hs * 8 / 9
		local hsvh : hs * 2 / [Math.abs (ttop - tbot)]
		local hvc : (rightEnd - leftEnd) / [Math.abs (ttop - tbot)]
		local defaultHvc : markExtend * 3 / (aboveMarkTop - aboveMarkBot - markFine / 2)

		local hsvhThin 0.116
		local hsvhHeav 0.732
		local tildeWave : [linreg hsvhThin 2.925 hsvhHeav 2.375 hsvh] * [linreg defaultHvc 1 4.35 1.1 hvc]
		local tildeWaveX 0.51

		define z1 : currentGlyph.gizmo.apply : object [x leftEnd] [y tbot]
		define z2 : currentGlyph.gizmo.apply : object [x : mix leftEnd rightEnd tildeWaveX] [y : mix tbot ttop tildeWave]
		define z3 : currentGlyph.gizmo.apply : object [x : mix leftEnd rightEnd (1 - tildeWaveX)] [y : mix tbot ttop (1 - tildeWave)]
		define z4 : currentGlyph.gizmo.apply : object [x rightEnd] [y ttop]

		return { z1 z2 z3 z4 }

	glyph-block-export TildeShape
	define [TildeShape] : with-params [ttop tbot leftEnd rightEnd hs] : glyph-proc
		define { z1 z2 z3 z4 } : include : TildeKnots ttop tbot leftEnd rightEnd hs
		define bone : new Arcs.Bez3 z1 z2 z3 z4

		define inner : new OffsetCurve bone (+hs) HVContrast
		define outer : new Arcs.Reverted : new OffsetCurve bone (-hs) HVContrast

		define cs : new BezToContoursSink
		ShapeConv.transferGenericShapeAsBezier {{inner outer}} cs GEOMETRY_PRECISION
		currentGlyph.includeContours cs.contours

	create-glyph 'tildeAbove' 0x303 : glyph-proc
		set-width 0
		include : StdAnchors.wide
		include : TildeShape
			ttop     -- aboveMarkTop
			tbot     -- aboveMarkBot + markFine / 2
			leftEnd  -- (markMiddle - markExtend * 1.5)
			rightEnd -- (markMiddle + markExtend * 1.5)
			hs       -- markHalfStroke

	create-glyph 'asciiTilde.high' : glyph-proc
		include : TildeShape
			ttop     -- [mix aboveMarkMid aboveMarkTop asciiMarkZoomY]
			tbot     -- [mix aboveMarkMid (aboveMarkBot + markFine / 2) asciiMarkZoomY]
			leftEnd  -- SB
			rightEnd -- RightSB
			hs       -- (OperatorStroke / 2)

	for-width-kinds WideWidth1
		define emDashWidth : if (para.isQuasiProportional && MosaicWidthScalar > 1) UPM MosaicWidth
		create-glyph [MangleName 'swungDash.high'] : glyph-proc
			set-width emDashWidth
			include : TildeShape
				ttop     -- [mix aboveMarkMid aboveMarkTop asciiMarkZoomY]
				tbot     -- [mix aboveMarkMid (aboveMarkBot + markFine / 2) asciiMarkZoomY]
				leftEnd  -- SB
				rightEnd -- (emDashWidth - SB)
				hs       -- (OperatorStroke / 2)

	define [OverlayTildeT sink] : begin
		local t : mix aboveMarkMid aboveMarkTop asciiMarkZoomY
		local b : mix aboveMarkMid (aboveMarkBot + markFine / 2) asciiMarkZoomY
		local offset : SymbolMid - [mix t b (1 / 2)]
		return : sink
			ttop     -- (t + offset)
			tbot     -- (b + offset)
			leftEnd  -- [mix 0 SB (1/3)]
			rightEnd -- [mix Width RightSB (1/3)]
			hs       -- ([AdviceStroke 4] / 2)

	create-glyph 'overlayTildeOperator' : glyph-proc
		include : OverlayTildeT TildeShape

	create-glyph 'overlayTildeOperatorAboveMask' : glyph-proc
		define FarRight : (+Width) * 4
		define FarLeft  : (-Width) * 3
		define FarAbove :   CAP    * 4

		define { z1 z2 z3 z4 } : include : OverlayTildeT TildeKnots
		define arcs : list : list
			new Arcs.Bez3 z1 z2 z3 z4
			new Arcs.StraightSegment z4 [Point.withX z4 FarRight]
			new Arcs.StraightSegment [Point.withX z4 FarRight] [Point.corner FarRight FarAbove]
			new Arcs.StraightSegment [Point.corner FarRight FarAbove] [Point.corner FarLeft FarAbove]
			new Arcs.StraightSegment [Point.corner FarLeft FarAbove] [Point.withX z1 FarLeft]
			new Arcs.StraightSegment [Point.withX z1 FarLeft] z1

		define cs : new BezToContoursSink
		ShapeConv.transferGenericShapeAsBezier arcs cs GEOMETRY_PRECISION
		currentGlyph.includeContours cs.contours

	create-glyph : glyph-proc
		set-width 0
		include : StdAnchors.wide

		local m : mix aboveMarkBot aboveMarkTop 0.4
		local ttop : mix m aboveMarkTop 0.7
		local tbot : mix m (aboveMarkBot + markFine / 2) 0.7
		local fine : [AdviceStroke 4.5] / 2

		include : TildeShape
			ttop     -- ttop
			tbot     -- tbot
			leftEnd  -- (markMiddle - markExtend * 1.5)
			rightEnd -- (markMiddle + markExtend * 1.5)
			hs       -- fine

		create-forked-glyph 'tildeSlashAbove' 0x34A : glyph-proc
			include : dispiro
				widths.center (fine * 2)
				flat (markMiddle + markExtend * 0.2) [mix tbot ttop 1.5]
				curl (markMiddle - markExtend * 0.2) [mix ttop tbot 1.5]

		foreach { suffix { DrawAt kdr } } [Object.entries DotVariants] : do
			create-forked-glyph "tildedotdotAbove.\(suffix)" : glyph-proc
				include : StdAnchors.impl 'above' (1 / 4) 1
				local r : 0.75 * DotRadius * fine / HalfStroke
				include : DrawAt markMiddle [mix tbot ttop 1.5] (r * kdr)
				include : DrawAt markMiddle [mix ttop tbot 1.5] (r * kdr)

	select-variant 'tildedotdotAbove' 0x34B (follow -- 'diacriticDot')

	create-glyph 'dblTildeAbove' 0x34C : glyph-proc
		set-width 0
		include : StdAnchors.impl 'above' (1 / 4) 1
		local m aboveMarkBot
		local ttop : mix m aboveMarkTop 0.7
		local tbot : mix m (aboveMarkBot + markFine / 2) 0.7

		define [addTilde] : TildeShape
			ttop     -- ttop
			tbot     -- tbot
			leftEnd  -- (markMiddle - markExtend * 1.5)
			rightEnd -- (markMiddle + markExtend * 1.5)
			hs       -- ([AdviceStroke 4.5] / 2)

		local shift : (ttop - tbot) * 1.2
		include : addTilde
		include : ApparentTranslate 0 shift

		include : addTilde
		include : ApparentTranslate 0 ((-0.5) * shift)

	create-glyph 'macronAbove' 0x304 : glyph-proc
		set-width 0
		include : StdAnchors.wide

		local leftEnd  : markMiddle - markExtend * 1.5
		local rightEnd : markMiddle + markExtend * 1.5

		include : dispiro
			flat leftEnd  aboveMarkMid [widths.center : 2 * markHalfStroke]
			curl rightEnd aboveMarkMid

	create-glyph 'overlineAbove' 0x305 : glyph-proc
		set-width 0
		include : StdAnchors.impl 'above' 0 2
		include : dispiro
			flat (0 - Width) aboveMarkMid [widths.center : 2 * markHalfStroke]
			curl  0          aboveMarkMid

	create-glyph 'sbRsbOverlineAbove' : glyph-proc
		set-width 0
		include : StdAnchors.impl 'above' 0 1.5
		include : dispiro
			flat (SB - Width)      aboveMarkMid [widths.center : 2 * markHalfStroke]
			curl (RightSB - Width) aboveMarkMid

	create-glyph 'cyrl/ghe.SRB/overlineAbove' : glyph-proc
		local df : DivFrame para.advanceScaleI
		set-width 0
		set-mark-anchor 'above' markMiddle XH markMiddle aboveMarkStack

		local leftEnd  : markMiddle - (df.rightSB - df.leftSB) / 2
		local rightEnd : markMiddle + (df.rightSB - df.leftSB) / 2

		set-base-anchor 'aboveBraceL' leftEnd aboveMarkMid
		set-base-anchor 'aboveBraceR' rightEnd aboveMarkMid

		include : dispiro
			flat leftEnd  aboveMarkMid [widths.center : 2 * markHalfStroke]
			curl rightEnd aboveMarkMid

	create-glyph 'cyrl/pe.SRB/overlineAbove' : glyph-proc
		local df : DivFrame 1
		set-width 0
		set-mark-anchor 'above' markMiddle XH markMiddle aboveMarkStack

		local leftEnd  : markMiddle - (df.rightSB - df.leftSB) / 2
		local rightEnd : markMiddle + (df.rightSB - df.leftSB) / 2

		set-base-anchor 'aboveBraceL' leftEnd aboveMarkMid
		set-base-anchor 'aboveBraceR' rightEnd aboveMarkMid

		include : dispiro
			flat leftEnd  aboveMarkMid [widths.center : 2 * markHalfStroke]
			curl rightEnd aboveMarkMid

	create-glyph 'cyrl/te.SRB/overlineAbove' : glyph-proc
		local df : DivFrame para.advanceScaleMM 3
		set-width 0
		set-mark-anchor 'above' markMiddle XH markMiddle aboveMarkStack

		local leftEnd  : markMiddle - (df.rightSB - df.leftSB) / 2
		local rightEnd : markMiddle + (df.rightSB - df.leftSB) / 2

		set-base-anchor 'aboveBraceL' leftEnd aboveMarkMid
		set-base-anchor 'aboveBraceR' rightEnd aboveMarkMid

		include : dispiro
			flat leftEnd  aboveMarkMid [widths.center : 2 * markHalfStroke]
			curl rightEnd aboveMarkMid

	create-glyph 'latin1macron' 0xAF : glyph-proc
		local df : include : DivFrame 1
		include : dispiro
			flat df.leftSB  aboveMarkMid [widths.center : 2 * markHalfStroke]
			curl df.rightSB aboveMarkMid

	create-glyph 'dblOverlineAbove' 0x33F : glyph-proc
		set-width 0
		include : StdAnchors.impl 'above' 0 2

		local boxsw : Math.min (markFine * 2) ((aboveMarkTop - aboveMarkBot) / 3)

		include : dispiro
			widths.lhs boxsw
			flat (0 - Width) aboveMarkBot
			curl  0          aboveMarkBot

		include : dispiro
			widths.rhs boxsw
			flat (0 - Width) aboveMarkTop
			curl  0          aboveMarkTop

	glyph-block-export BreveShape
	define [BreveShape] : with-params [top bottom xMiddle width hs] : glyph-proc
		local leftEnd  : xMiddle - width * 0.5
		local rightEnd : xMiddle + width * 0.5
		include : dispiro
			g4.down.start leftEnd top [widths.heading hs hs Downward]
			arcvh
			g4.right.mid xMiddle (bottom + hs) [heading Rightward]
			archv
			g4.up.end rightEnd top [heading Upward]

	glyph-block-export InvBreveShape
	define [InvBreveShape] : with-params [top bottom xMiddle width hs] : glyph-proc
		local leftEnd  : xMiddle - width * 0.5
		local rightEnd : xMiddle + width * 0.5
		include : dispiro
			g4.up.start leftEnd bottom [widths.heading hs hs Upward]
			arcvh
			g4.right.mid xMiddle (top - hs) [heading Rightward]
			archv
			g4.down.end rightEnd bottom [heading Downward]

	create-glyph 'breveAbove' 0x306 : glyph-proc
		set-width 0
		include : StdAnchors.wide
		include : BreveShape
			xMiddle -- markMiddle
			width   -- (2.4 * markExtend)
			top     -- aboveMarkTop
			bottom  -- aboveMarkBot
			hs      -- markHalfStroke

	create-glyph 'archAbove' 0x311 : glyph-proc
		set-width 0
		include : StdAnchors.wide
		include : InvBreveShape
			xMiddle -- markMiddle
			width   -- (2.4 * markExtend)
			top     -- aboveMarkTop
			bottom  -- aboveMarkBot
			hs      -- markHalfStroke

	create-glyph 'hookAbove' 0x309 : glyph-proc
		set-width 0
		include : StdAnchors.medium

		local fine : Math.min markFine : (aboveMarkTop - aboveMarkBot) * 0.2

		local hookBot : aboveMarkBot - fine / 2
		local hookTop : [mix aboveMarkBot aboveMarkTop 0.9] + fine / 2
		include : dispiro
			widths.lhs (fine * 2)
			flat (markMiddle - [HSwToV fine]) hookBot [heading Rightward]
			curl (markMiddle + fine * 0.4) hookBot [heading Rightward]
			archv
			g4.up.mid (markMiddle + markExtend - O) [mix hookBot hookTop (ArchDepthB / (ArchDepthB + ArchDepthA))] [heading Upward]
			arcvh
			flat (markMiddle + fine * 0.4) hookTop [heading Leftward]
			curl (markMiddle - markExtend + fine) hookTop [heading Leftward]

	create-glyph 'doubleGraveAbove' 0x30F : glyph-proc
		set-width 0
		include : StdAnchors.wide

		local m1 : markMiddle - markExtend * 0.85
		local m2 : markMiddle + markExtend * 0.85
		include : dispiro
			flat (m1 + markStress) aboveMarkBot [widths.center : 2 * markFine]
			curl (m1 - markExtend) aboveMarkTop [widths.center : 2 * markStress]
		include : dispiro
			flat (m2 + markStress) aboveMarkBot [widths.center : 2 * markFine]
			curl (m2 - markExtend) aboveMarkTop [widths.center : 2 * markStress]

	create-glyph 'doubleAcuteAbove' 0x30B : glyph-proc
		set-width 0
		include : StdAnchors.wide

		local m1 : markMiddle - markExtend * 0.85
		local m2 : markMiddle + markExtend * 0.85
		include : dispiro
			flat (m1 - markStress) aboveMarkBot [widths.center : 2 * markFine]
			curl (m1 + markExtend) aboveMarkTop [widths.center : 2 * markStress]
		include : dispiro
			flat (m2 - markStress) aboveMarkBot [widths.center : 2 * markFine]
			curl (m2 + markExtend) aboveMarkTop [widths.center : 2 * markStress]

	create-glyph 'tripleAcuteAbove' 0x1ACB : glyph-proc
		set-width 0
		include : StdAnchors.extraWide

		local fine : 0.5 * [AdviceStroke 6]
		local stress : 1.2 * fine

		local m1 : markMiddle - markExtend * 1.275
		local m2   markMiddle
		local m3 : markMiddle + markExtend * 1.275
		include : dispiro
			flat (m1 - markStress) aboveMarkBot [widths.center : 2 * fine]
			curl (m1 + markExtend) aboveMarkTop [widths.center : 2 * stress]
		include : dispiro
			flat (m2 - markStress) aboveMarkBot [widths.center : 2 * fine]
			curl (m2 + markExtend) aboveMarkTop [widths.center : 2 * stress]
		include : dispiro
			flat (m3 - markStress) aboveMarkBot [widths.center : 2 * fine]
			curl (m3 + markExtend) aboveMarkTop [widths.center : 2 * stress]

	create-glyph 'commaAbove.round' : glyph-proc
		set-width 0
		include : StdAnchors.narrow

		local radius commaAboveRadius
		include : Ring (aboveMarkTop + commaOvershoot) (aboveMarkTop - radius * 2 + commaOvershoot) (markMiddle - radius) (markMiddle + radius)
		include : dispiro
			widths.rhs [Math.min radius : markFine * [linreg 16 2 90 1.75 markStroke]]
			straight.down.start (markMiddle + radius) (aboveMarkTop - radius + commaOvershoot)
			quadControls 0 0.6
			g4   [mix markMiddle (markMiddle - radius) 0.2] (aboveMarkBot - radius - commaOvershoot2)
		include : ApparentTranslate 0 (DotRadius * 0.3)

	create-glyph 'commaAbove.square' : glyph-proc
		set-width 0
		include : StdAnchors.narrow

		local radius : commaAboveRadius * DesignParameters.squareDotScalar
		include : Rect aboveMarkTop (aboveMarkTop - radius * 2) (markMiddle - radius) (markMiddle + radius)
		include : dispiro
			widths.rhs [Math.min radius : markFine * [linreg 16 2 90 1.75 markStroke]]
			flat (markMiddle + radius)  aboveMarkTop [heading Downward]
			curl (markMiddle + radius) (aboveMarkTop - 2 * radius) [heading Downward]
			quadControls 0 0.6
			g4   [mix markMiddle (markMiddle - radius) 0.2] (aboveMarkBot - radius - commaOvershoot2)
		include : ApparentTranslate 0 (DotRadius * 0.3)

	select-variant 'commaAbove' 0x313 (follow -- 'diacriticDot')
	select-variant 'commaAbove/asPunctuation' (shapeFrom -- 'commaAbove') (follow -- 'punctuationDot')

	derive-glyphs 'commaGrekUpperTonos' null 'commaAbove' : function [src gr] : glyph-proc
		set-width 0
		include : refer-glyph src
		include : StdAnchors.impl 'grekUpperTonos' 0 0

	derive-glyphs 'turnCommaAbove' 0x312 'commaAbove' : function [src gr] : glyph-proc
		set-width 0
		include : refer-glyph src
		include : FlipAround markMiddle ([mix aboveMarkTop (aboveMarkBot - commaAboveRadius) 0.5] + (DotRadius * 0.3) + commaOvershoot / 2)
		include : StdAnchors.narrow

	create-glyph 'revCommaAbove.round' : glyph-proc
		set-width 0
		include : StdAnchors.narrow

		local radius commaAboveRadius
		include : Ring (aboveMarkTop + commaOvershoot) (aboveMarkTop - radius * 2 + commaOvershoot) (markMiddle - radius) (markMiddle + radius)
		include : dispiro
			widths.lhs [Math.min radius : markFine * [linreg 16 2 90 1.75 markStroke]]
			straight.down.start (markMiddle - radius) (aboveMarkTop - radius + commaOvershoot)
			quadControls 0 0.6
			g4   [mix markMiddle (markMiddle + radius) 0.2] (aboveMarkBot - radius - commaOvershoot2)
		include : ApparentTranslate 0 (DotRadius * 0.3)

	create-glyph 'revCommaAbove.square' : glyph-proc
		set-width 0
		include : StdAnchors.narrow

		local radius : commaAboveRadius * DesignParameters.squareDotScalar
		include : Rect (aboveMarkTop + commaOvershoot) (aboveMarkTop - radius * 2 + commaOvershoot) (markMiddle - radius) (markMiddle + radius)
		include : dispiro
			widths.lhs [Math.min radius : markFine * [linreg 16 2 90 1.75 markStroke]]
			flat (markMiddle - radius) aboveMarkTop [heading Downward]
			curl (markMiddle - radius) (aboveMarkTop - 2 * radius) [heading Downward]
			quadControls 0 0.6
			g4   [mix markMiddle (markMiddle + radius) 0.2] (aboveMarkBot - radius - commaOvershoot2)
		include : ApparentTranslate 0 (DotRadius * 0.3)

	select-variant 'revCommaAbove' 0x314 (follow -- 'diacriticDot')

	derive-glyphs 'revCommaGrekUpperTonos' null 'revCommaAbove' : function [src gr] : glyph-proc
		set-width 0
		include : refer-glyph src
		include : StdAnchors.impl 'grekUpperTonos' 0 0

	create-glyph 'barAbove' 0x30D : glyph-proc
		set-width 0
		include : StdAnchors.narrow
		include : VBar.m markMiddle aboveMarkBot aboveMarkTop markStroke

	create-glyph 'ascenderBarAbove' : glyph-proc
		set-width 0
		include : StdAnchors.narrow
		include : VBar.m markMiddle [mix XH aboveMarkBot 0.5] CAP markStroke

	create-glyph 'dblBarAbove' 0x30E : glyph-proc
		set-width 0
		include : StdAnchors.mediumWide

		include : VBar.m (markMiddle - markExtend * 0.75) aboveMarkBot aboveMarkTop markStroke
		include : VBar.m (markMiddle + markExtend * 0.75) aboveMarkBot aboveMarkTop markStroke

	create-glyph 'bridgeAbove' 0x346 : glyph-proc
		set-width 0
		include : StdAnchors.wide

		include : VBar.m (markMiddle - markExtend) aboveMarkBot aboveMarkTop (markFine * 2)
		include : VBar.m (markMiddle + markExtend) aboveMarkBot aboveMarkTop (markFine * 2)
		include : HBar.t (markMiddle - markExtend) (markMiddle + markExtend) aboveMarkTop (markFine * 2)

	create-glyph 'wideBridgeAbove' 0x20E9 : glyph-proc
		set-width 0
		include : StdAnchors.impl 'above' 0 1.5

		include : VBar.m (SB - Width)      aboveMarkBot aboveMarkTop (markFine * 2)
		include : VBar.m (RightSB - Width) aboveMarkBot aboveMarkTop (markFine * 2)
		include : HBar.t (SB - Width) (RightSB - Width) aboveMarkTop (markFine * 2)

	create-glyph 'crossAbove' 0x33D : glyph-proc
		set-width 0
		include : StdAnchors.mediumWide

		include : dispiro
			flat (markMiddle - markExtend) aboveMarkTop [widths.center : 2 * markFine]
			curl (markMiddle + markExtend) aboveMarkBot
		include : dispiro
			flat (markMiddle - markExtend) aboveMarkBot [widths.center : 2 * markFine]
			curl (markMiddle + markExtend) aboveMarkTop

	create-glyph 'yerikAbove' 0x33E : glyph-proc
		set-width 0
		include : StdAnchors.narrow

		include : dispiro
			widths.center (markFine * 2)
			g2 (markMiddle - markFine * 0.5) aboveMarkBot [heading Upward]
			alsoThruThem {{0.9 0.36} {0.1 0.64}} [heading Upward]
			g2 (markMiddle + markFine * 0.5) aboveMarkTop  [heading Upward]

	foreach { suffix { DrawAt kdr } } [Object.entries DotVariants] : do
		create-glyph "candrabinduAbove.\(suffix)" : glyph-proc
			set-width 0
			local fine : AdviceStroke 6.5
			local arcSw : Math.min markStroke (fine * 1.25)
			local radius : Math.max (markExtend - DotRadius) (fine * 1.35)
			local yDot : mix aboveMarkBot aboveMarkTop 0.625
			include : dispiro
				widths.rhs arcSw
				g4.down.start (markMiddle - radius) yDot [heading Downward]
				arcvh
				g4.right.mid markMiddle (yDot - radius)
				archv
				g4.up.end (markMiddle + radius) yDot [heading Upward]
			include : DrawAt markMiddle yDot (fine * kdr)
			include : ApparentTranslate 0 (fine * 0.5)
			include : StdAnchors.mediumWide
		create-glyph "largeFermataAbove.\(suffix)" : glyph-proc
			set-width 0
			local fine : AdviceStroke 6.5 asciiMarkZoomX
			local arcSw : Math.min markStroke (fine * 1.25)
			local radius : Math.max (asciiMarkZoomX * markExtend - DotRadius) (fine * 1.35)
			local yDot : mix [mix aboveMarkMid aboveMarkBot asciiMarkZoomY] [mix aboveMarkMid aboveMarkTop asciiMarkZoomY] 0.375
			include : dispiro
				widths.lhs arcSw
				g4.up.start (markMiddle - radius) yDot [heading Upward]
				arcvh
				g4.right.mid markMiddle (yDot + radius)
				archv
				g4.down.end (markMiddle + radius) yDot [heading Downward]
			include : DrawAt markMiddle yDot (fine * kdr)
			include : ApparentTranslate 0 (fine * (-0.5))
			include : StdAnchors.extraWide
		create-glyph "cyrlKavykaWithDotAbove.\(suffix)" : glyph-proc
			set-width 0
			local radius : markExtend * 1.5
			local arcHs : Math.min markHalfStroke (radius * 0.4)
			local yDot : mix aboveMarkBot aboveMarkTop 0.625
			local bottom : yDot - radius
			local top : bottom + AccentHeight
			include : dispiro
				g4.down.start (markMiddle - radius) (top - arcHs) [widths.heading arcHs arcHs Downward]
				arcvh
				g4.right.mid markMiddle bottom
				archv
				g4.up.end (markMiddle + radius) (top - arcHs) [heading Upward]
			include : DrawAt markMiddle yDot [Math.min (markDotsRadius * kdr) (radius * 0.4)]
			include : ApparentTranslate 0 ([Math.max 0 (aboveMarkBot - yDot + radius)] + arcHs)
			include : StdAnchors.extraWide

	select-variant 'candrabinduAbove' 0x310 (follow -- 'diacriticDot')
	turned 'fermataAbove' 0x352 'candrabinduAbove' markMiddle aboveMarkMid
	select-variant 'largeFermataAbove' (follow -- 'diacriticDot')
	select-variant 'cyrlKavykaWithDotAbove' null (follow -- 'diacriticDot')

	alias 'graveToneAbove' 0x340 'graveAbove'
	alias 'acuteToneAbove' 0x341 'acuteAbove'

	create-glyph 'tonosAbove' : glyph-proc
		set-width 0
		include : StdAnchors.narrow
		local shift : 0.05 * markExtend + [HSwToV : markStress - markFine]
		include : dispiro
			flat (markMiddle + shift) (aboveMarkTop + 0.4 * markStress) [widths.center.heading (markStress * 2) Downward]
			curl (markMiddle - 0.5 * shift) aboveMarkBot [widths.center.heading (markFine * 2) Downward]

	create-glyph 'tonosGrekUpperTonos' : glyph-proc
		set-width 0
		include : refer-glyph 'tonosAbove'
		include : StdAnchors.impl 'grekUpperTonos' 0 0

	create-glyph 'variaAbove' : glyph-proc
		set-width 0
		include : StdAnchors.medium

		include : dispiro
			flat (markMiddle + markStress) (aboveMarkBot - markFine * 0.5) [widths.center : 2 * markFine]
			curl (markMiddle - markExtend * 0.5) (aboveMarkTop + markStress * 0.25) [widths.center : 2 * markStress]

	create-glyph 'variaGrekUpperTonos' : glyph-proc
		set-width 0
		include : refer-glyph 'variaAbove'
		include : StdAnchors.impl 'grekUpperTonos' 0 0

	create-glyph 'oxiaAbove' : glyph-proc
		set-width 0
		include : StdAnchors.medium

		include : dispiro
			flat (markMiddle - markStress) (aboveMarkBot - markFine * 0.5) [widths.center : 2 * markFine]
			curl (markMiddle + markExtend * 0.5) (aboveMarkTop + markStress * 0.25) [widths.center : 2 * markStress]

	create-glyph 'oxiaGrekUpperTonos' : glyph-proc
		set-width 0
		include : refer-glyph 'oxiaAbove'
		include : StdAnchors.impl 'grekUpperTonos' 0 0

	create-glyph 'perispomeniAbove' 0x342 : glyph-proc
		set-width 0
		include : refer-glyph "archAbove"
		include : StdAnchors.wide

	alias 'koronisAbove' 0x343 'commaAbove'

	foreach { suffix { DrawAt kdr } } [Object.entries DotVariants] : do
		create-glyph "dialytikaTonosAbove.\(suffix)" : glyph-proc
			set-width 0
			include : with-transform [ApparentTranslate 0 ((-AccentHeight) / 8)] : refer-glyph "dialytikaAbove.\(suffix)"
			include : with-transform [ApparentTranslate 0 0] : refer-glyph 'tonosAbove'
			include : StdAnchors.wide

		create-glyph "dialytikaVariaAbove.\(suffix)" : glyph-proc
			set-width 0
			local shift : 0.125 * (markExtend * 0.875 - markStress)
			include : with-transform [ApparentTranslate 0 ((-AccentHeight) / 8)] : refer-glyph "dialytikaAbove.\(suffix)"
			include : with-transform [ApparentTranslate shift 0] : refer-glyph 'variaAbove'
			include : StdAnchors.wide

		create-glyph "dialytikaOxiaAbove.\(suffix)" : glyph-proc
			set-width 0
			local shift : 0.125 * (markExtend * 0.875 - markStress)
			include : with-transform [ApparentTranslate 0 ((-AccentHeight) / 8)] : refer-glyph "dialytikaAbove.\(suffix)"
			include : with-transform [ApparentTranslate (-shift) 0] : refer-glyph 'oxiaAbove'
			include : StdAnchors.wide

	select-variant 'dialytikaTonosAbove' 0x344 (follow -- 'diacriticDot')
	select-variant 'dialytikaVariaAbove' (follow -- 'diacriticDot')
	select-variant 'dialytikaOxiaAbove' (follow -- 'diacriticDot')

	create-glyph 'lessAbove' 0x1DFE : glyph-proc
		set-width 0
		include : StdAnchors.mediumWide

		local top aboveMarkTop
		local bot aboveMarkBot
		local exp : Math.sqrt : 1 + (((top - bot) / markExtend) ** 2)
		include : dispiro
			widths.center (markFine * 2)
			flat (markMiddle + markExtend) top
			curl (markMiddle - markExtend) [mix top bot 0.5] [widths.center.heading (markFine * exp) Leftward]

		include : dispiro
			widths.center (markFine * 2)
			flat (markMiddle + markExtend) bot
			curl (markMiddle - markExtend) [mix top bot 0.5] [widths.center.heading (markFine * exp) Leftward]

	turned 'greaterAbove' 0x350 'lessAbove' markMiddle aboveMarkMid

	create-glyph 'leftHalfCircleAbove' 0x351 : glyph-proc
		set-width 0
		include : StdAnchors.narrow
		local [object radiusIn radiusOut] : RingDims
		include : dispiro
			g4.left.start markMiddle aboveMarkTop [widths.center.heading (radiusOut - radiusIn) Leftward]
			archv
			g4.down.mid  (markMiddle - (aboveMarkTop - aboveMarkBot) / 2) [mix aboveMarkTop aboveMarkBot 0.5] [heading Downward]
			arcvh
			g4.right.end  markMiddle aboveMarkBot [heading Rightward]
		include : Translate (0.25 * (aboveMarkTop - aboveMarkBot)) 0

	create-glyph 'rightHalfCircleAbove' 0x357 : glyph-proc
		set-width 0
		include : StdAnchors.narrow
		local [object radiusIn radiusOut] : RingDims
		include : dispiro
			g4.right.start markMiddle aboveMarkTop [widths.center.heading (radiusOut - radiusIn) Rightward]
			archv
			g4.down.mid   (markMiddle + (aboveMarkTop - aboveMarkBot) / 2) [mix aboveMarkTop aboveMarkBot 0.5] [heading Downward]
			arcvh
			g4.left.end    markMiddle aboveMarkBot [heading Leftward]
		include : Translate ((-0.25) * (aboveMarkTop - aboveMarkBot)) 0

	create-glyph 'zigzagAbove' 0x35B : glyph-proc
		set-width 0
		include : StdAnchors.mediumWide

		local ext : 0.625 * markExtend + markFine
		local coSlope  0.2
		local fr : new Box aboveMarkTop aboveMarkBot (markMiddle - ext) (markMiddle + ext)
		include : HBar.m fr.left fr.right fr.yMid (markFine * 2)
		include : intersection [MaskBelow fr.top] [MaskAbove (fr.yMid - markFine)]
			ExtLineLhs 4 (markFine * 2) (fr.left  + coSlope * (fr.top - fr.yMid - markFine)) fr.top (fr.left  - 2 * markFine * coSlope) (fr.yMid - markFine)
		include : intersection [MaskAbove fr.bot] [MaskBelow (fr.yMid + markFine)]
			ExtLineLhs 4 (markFine * 2) (fr.right - coSlope * (fr.yMid - fr.bot - markFine)) fr.bot (fr.right + 2 * markFine * coSlope) (fr.yMid + markFine)

	create-glyph 'upArrowHeadAbove' : glyph-proc
		set-width 0
		include : StdAnchors.medium

		local top aboveMarkTop
		local bot aboveMarkBot
		local exp : Math.sqrt : 1 + ((3 * markExtend / (top - bot)) ** 2)
		include : dispiro
			widths.center (markFine * 2)
			flat (markMiddle - markExtend) bot
			curl markMiddle top [widths.center.heading (markFine * exp) Upward]

		include : dispiro
			widths.center (markFine * 2)
			flat (markMiddle + markExtend) bot
			curl markMiddle top [widths.center.heading (markFine * exp) Upward]

	turned 'downArrowHeadAbove' null 'upArrowHeadAbove' markMiddle aboveMarkMid

	define [ArrowheadForArrowMarkAbove-Up] : new-glyph : glyph-proc
		local fine : [AdviceStroke 6] / 2
		local top aboveMarkTop
		local bot aboveMarkMid
		local left  : markMiddle - markExtend * 0.75
		local right : markMiddle + markExtend * 0.75
		local exp : Math.sqrt : 1 + (2 * (top - bot)) / (right - left) * (2 * (top - bot)) / (right - left)
		include : dispiro
			widths.center (fine * 2)
			flat left bot
			curl [mix left right 0.5] top [widths.heading (fine * exp) (fine * exp) Rightward]
		include : dispiro
			widths.center (fine * 2)
			flat right bot
			curl [mix left right 0.5] top [widths.heading (fine * exp) (fine * exp) Leftward]

	define [ArrowheadForArrowMarkAbove-Down] : new-glyph : glyph-proc
		include : ArrowheadForArrowMarkAbove-Up
		include : FlipAround markMiddle aboveMarkMid

	define [VBar.mForArrowMarkAbove] : glyph-proc
		local fine : [AdviceStroke 6] / 2
		include : VBar.m markMiddle aboveMarkTop aboveMarkBot (fine * 2)

	define [ArrowheadForArrowMarkAbove-Left] : new-glyph : glyph-proc
		local fine : [AdviceStroke 5.75] / 2
		local top aboveMarkTop
		local bot aboveMarkBot
		local left  : markMiddle - markExtend * 1.5
		local right : markMiddle - markExtend * 0.5
		local exp : Math.sqrt : 1 + (top - bot) / (2 * (right - left)) * (top - bot) / (2 * (right - left))
		include : dispiro
			widths.center (fine * 2)
			flat right top
			curl left [mix top bot 0.5] [widths.heading (fine * exp) (fine * exp) Downward]

		include : dispiro
			widths.center (fine * 2)
			flat right bot
			curl left [mix top bot 0.5] [widths.heading (fine * exp) (fine * exp) Upward]

	define [ArrowheadForArrowMarkAbove-Right] : new-glyph : glyph-proc
		include : ArrowheadForArrowMarkAbove-Left
		include : FlipAround markMiddle aboveMarkMid

	define [HBar.mForArrowMarkAbove] : glyph-proc
		local fine : [AdviceStroke 5.75] / 2
		include : HBar.m (markMiddle - markExtend * 1.5) (markMiddle + markExtend * 1.5) aboveMarkMid (fine * 2)

	create-glyph 'upArrowAbove' : glyph-proc
		set-width 0
		include : StdAnchors.medium
		include : ArrowheadForArrowMarkAbove-Up
		include : VBar.mForArrowMarkAbove

	create-glyph 'downArrowAbove' 0x1AB3 : glyph-proc
		set-width 0
		include : StdAnchors.medium
		include : ArrowheadForArrowMarkAbove-Down
		include : VBar.mForArrowMarkAbove

	create-glyph 'leftArrowAbove' 0x20D6 : glyph-proc
		set-width 0
		include : StdAnchors.wide
		include : ArrowheadForArrowMarkAbove-Left
		include : HBar.mForArrowMarkAbove

	create-glyph 'rightArrowAbove' 0x20D7 : glyph-proc
		set-width 0
		include : StdAnchors.wide
		include : ArrowheadForArrowMarkAbove-Right
		include : HBar.mForArrowMarkAbove

	create-glyph 'lrArrowAbove' 0x20E1 : glyph-proc
		set-width 0
		include : StdAnchors.wide
		include : ArrowheadForArrowMarkAbove-Left
		include : ArrowheadForArrowMarkAbove-Right
		include : HBar.mForArrowMarkAbove

	alias 'cyrlDasiaAbove' 0x485 'revCommaAbove'
	alias 'cyrlPsiliAbove' 0x486 'commaAbove'

	create-glyph 'cyrlPalatilizationAbove' 0x484 : glyph-proc
		set-width 0
		include : StdAnchors.wide

		local leftEnd  : markMiddle - markExtend * 2.0
		local rightEnd : markMiddle + markExtend * 1.2

		include : dispiro
			g4.up.start rightEnd aboveMarkBot [widths.heading markHalfStroke markHalfStroke Upward]
			arcvh
			g2.left.mid markMiddle (aboveMarkTop - markHalfStroke) [heading Leftward]
			alsoThru.g2 0.5 0.5
			g2.left.end leftEnd ([mix aboveMarkBot aboveMarkTop 0.5] - markHalfStroke) [heading Leftward]

	create-glyph 'cyrlPokrytieAbove' 0x487 : glyph-proc
		set-width 0
		include : StdAnchors.wide

		local leftEnd  : markMiddle - markExtend * 1.2
		local rightEnd : markMiddle + markExtend * 2.0

		include : dispiro
			g4.up.start leftEnd aboveMarkBot [widths.heading markHalfStroke markHalfStroke Upward]
			arcvh
			g2.right.mid markMiddle (aboveMarkTop - markHalfStroke) [heading Rightward]
			alsoThru.g2 0.5 0.5
			g2.right.end rightEnd ([mix aboveMarkBot aboveMarkTop 0.5] - markHalfStroke) [heading Rightward]

	create-glyph 'cyrlTitloAbove' 0x483 : glyph-proc
		set-width 0
		include : StdAnchors.wide

		include : VBar.m (markMiddle - markExtend) aboveMarkBot (aboveMarkMid + markFine) (markFine * 2)
		include : VBar.m (markMiddle + markExtend) (aboveMarkMid - markFine) aboveMarkTop (markFine * 2)
		include : HBar.m (markMiddle - markExtend) (markMiddle + markExtend) aboveMarkMid (markFine * 2)

	create-glyph 'cyrlVzmetAbove' 0xA66F : glyph-proc
		set-width 0
		include : StdAnchors.wide

		include : VBar.m (markMiddle - markExtend) aboveMarkBot (aboveMarkMid + markFine) (markFine * 2)
		include : VBar.m (markMiddle + markExtend) aboveMarkBot (aboveMarkMid + markFine) (markFine * 2)
		include : HBar.m (markMiddle - markExtend) (markMiddle + markExtend) aboveMarkMid (markFine * 2)

	create-glyph 'cyrlKavykaAbove' 0xA67C : glyph-proc
		set-width 0
		include : StdAnchors.extraWide
		include : BreveShape
			xMiddle -- markMiddle
			width   -- (3 * markExtend)
			top     -- aboveMarkTop
			bottom  -- aboveMarkBot
			hs      -- markHalfStroke

	create-glyph 'cyrlInvKavykaAbove' : glyph-proc
		set-width 0
		include : StdAnchors.extraWide
		include : InvBreveShape
			xMiddle -- markMiddle
			width   -- (3 * markExtend)
			top     -- aboveMarkTop
			bottom  -- aboveMarkBot
			hs      -- markHalfStroke

	create-glyph 'cyrlPayerokAbove' 0xA67D : glyph-proc
		set-width 0
		include : StdAnchors.mediumWide

		local ext : 0.625 * markExtend + markFine
		local coSlope 0.2
		local fr : new Box aboveMarkTop aboveMarkBot (markMiddle - ext) (markMiddle + ext)
		include : HBar.m fr.left (fr.right - coSlope * (fr.top - fr.yMid)) fr.yMid (markFine * 2)
		include : intersection [MaskBelow fr.top] [MaskAbove (fr.yMid - markFine)]
			ExtLineLhs 4 (markFine * 2) (fr.left + coSlope * (fr.top - fr.yMid - markFine)) fr.top (fr.left - 2 * markFine * coSlope) (fr.yMid - markFine)
		include : intersection [MaskAbove fr.bot] [MaskBelow fr.top]
			ExtLineLhs 4 (markFine * 2) (fr.right - coSlope * (fr.top - fr.bot - 2 * markFine)) fr.bot (fr.right + 2 * markFine * coSlope) fr.top

	create-glyph 'ogonekAbove' 0x1DCE : glyph-proc
		set-width 0

		set-mark-anchor 'above' markMiddle XH markMiddle aboveMarkStack
		set-base-anchor 'aboveBraceL' (markMiddle - 0.25 * markExtend) aboveMarkMid
		set-base-anchor 'aboveBraceR' (markMiddle + 0.25 * markExtend + [HSwToV : 0.25 * markStroke]) aboveMarkMid

		local fine : AdviceStroke 8
		local depth : 0 - Descender - markStroke
		local fullExt : (7 / 16) * depth + 0.125 * markStress
		local extR : 0.25 * fullExt
		local extL : 0.5 * fullExt + 0.375 * markStroke + [Math.max (0.125 * markExtend) (1.5 * TanSlope * markStroke)]

		local turnSlope : 0.5 * ((markStroke - fine) / markStroke - (ArchDepthB - ArchDepth) / ArchDepth)

		include : intersection
			MaskAbove (XH + O)
			dispiro
				g4 (markMiddle + [mix extR (-extL) 0.75]) XH [widths.rhs.heading fine Rightward]
				alsoThru 0.5 (0.375 - 0.2 * markStroke / depth) [widths.rhs : mix fine markStroke 0.25]
				g4.up.mid (markMiddle + extR) (XH + 0.75 * depth) [widths.rhs.heading markStroke {.x (-HVContrast) .y (-turnSlope)}]
				arcvh [widths.rhs markStroke]
				g4 (markMiddle + [mix extR (-extL) 0.625]) (XH + depth - O) [heading Leftward]
				g4 (markMiddle - extL) (XH + depth - 0.5 * O) [heading Leftward]

	create-glyph 'dblBreveAbove' 0x1AC7 : glyph-proc
		set-width 0
		include : StdAnchors.wide

		local sw : markStroke * ([AdviceStroke 3.5] / Stroke)
		local extend : (aboveMarkTop - aboveMarkBot - 0.5 * markStroke) * 1.25

		include : dispiro
			g4.down.start (markMiddle - extend) aboveMarkTop [widths.center.heading sw Downward]
			arcvh
			g4.right.mid  [mix markMiddle (markMiddle - extend) 0.5] (aboveMarkBot + 0.5 * sw) [heading Rightward]
			archv
			g4.up.end     markMiddle aboveMarkTop [heading Upward]
		include : dispiro
			g4.down.start markMiddle aboveMarkTop [widths.center.heading sw Downward]
			arcvh
			g4.right.mid  [mix markMiddle (markMiddle + extend) 0.5] (aboveMarkBot + 0.5 * sw) [heading Rightward]
			archv
			g4.up.end     (markMiddle + extend) aboveMarkTop [heading Upward]

	create-glyph 'dblArchAbove' : glyph-proc
		set-width 0
		include : refer-glyph "dblBreveAbove"
		include : FlipAround markMiddle [mix aboveMarkTop aboveMarkBot 0.5]
		include : StdAnchors.wide

	create-glyph 'breveMacronAbove' 0x1DCB : glyph-proc
		set-width 0
		include : StdAnchors.wide

		local sw : markStroke * ([AdviceStroke 3.5] / Stroke)
		local extend : (aboveMarkTop - aboveMarkBot - 0.5 * markStroke) * 1.25

		include : dispiro
			g4.down.start (markMiddle - extend) aboveMarkTop [widths.center.heading sw Downward]
			arcvh
			g4.right.mid  [mix markMiddle (markMiddle - extend) 0.5] (aboveMarkBot + 0.5 * sw) [heading Rightward]
			archv
			g4.up.end     markMiddle aboveMarkTop [heading Upward]
		include : HBar.t markMiddle (markMiddle + extend + 0.5 * markStress) aboveMarkTop sw

	create-glyph 'macronBreveAbove' 0x1DCC : glyph-proc
		set-width 0
		include : StdAnchors.wide

		local sw : markStroke * ([AdviceStroke 3.5] / Stroke)
		local extend : (aboveMarkTop - aboveMarkBot - 0.5 * markStroke) * 1.25

		include : HBar.t (markMiddle - extend - 0.5 * markStress) markMiddle aboveMarkTop sw
		include : dispiro
			g4.down.start markMiddle aboveMarkTop [widths.center.heading sw Downward]
			arcvh
			g4.right.mid  [mix markMiddle (markMiddle + extend) 0.5] (aboveMarkBot + 0.5 * sw) [heading Rightward]
			archv
			g4.up.end     (markMiddle + extend) aboveMarkTop [heading Upward]

	create-glyph 'plusAbove' 0x1AC8 : glyph-proc
		set-width 0
		include : StdAnchors.mediumWide

		include : VBar.m markMiddle aboveMarkBot aboveMarkTop (markFine * 2)
		include : HBar.m (markMiddle - markExtend) (markMiddle + markExtend) aboveMarkMid (markFine * 2)

	create-glyph 'minusAbove' : glyph-proc
		set-width 0
		include : StdAnchors.mediumWide

		include : HBar.m (markMiddle - markExtend) (markMiddle + markExtend) aboveMarkMid (markFine * 2)

	create-glyph 'dblPlusAbove' 0x1AC9 : glyph-proc
		set-width 0
		include : with-transform [Translate (+markExtend) 0] : refer-glyph 'plusAbove'
		include : with-transform [Translate (-markExtend) 0] : refer-glyph 'plusAbove'
		include : StdAnchors.extraWide

	create-glyph 'upTackAbove' 0x1DF5 : glyph-proc
		set-width 0
		include : StdAnchors.medium

		include : VBar.m markMiddle aboveMarkBot aboveMarkTop (markFine * 2)
		include : HBar.b (markMiddle - markExtend) (markMiddle + markExtend) aboveMarkBot (markFine * 2)

	create-glyph 'downTackAbove' : glyph-proc
		set-width 0
		include : StdAnchors.medium

		include : VBar.m markMiddle aboveMarkBot aboveMarkTop (markFine * 2)
		include : HBar.t (markMiddle - markExtend) (markMiddle + markExtend) aboveMarkTop (markFine * 2)

	create-glyph 'suspensionMarkAbove' 0x1DC3 : glyph-proc
		set-width 0
		include : StdAnchors.wide

		local leftEnd  : markMiddle - markExtend * 1.2
		local rightEnd : markMiddle + markExtend * 2.0

		include : dispiro
			g4.down.start leftEnd aboveMarkTop [widths.heading markHalfStroke markHalfStroke Downward]
			arcvh
			g2.right.mid markMiddle (aboveMarkBot + markHalfStroke) [heading Rightward]
			alsoThru.g2 0.5 0.5
			g2.right.end rightEnd (aboveMarkTop - markHalfStroke) [heading Rightward]

	create-glyph 'deletionMarkAbove' 0x1DFB : glyph-proc
		set-width 0
		include : StdAnchors.medium

		local wide : markExtend * 0.3
		local d : markExtend * 0.7

		local fine : 0.5 * [Math.min (markStroke * ([AdviceStroke 3.5] / Stroke)) (markExtend / 3)]
		local stress : 1.2 * fine

		include : dispiro
			widths.center (stress * 2)
			flat (markMiddle - d + wide) aboveMarkTop [heading Downward]
			curl (markMiddle - d - wide) aboveMarkBot [widths.heading fine fine Downward]
		include : dispiro
			widths.center (stress * 2)
			flat (markMiddle + wide) aboveMarkTop [heading Downward]
			curl (markMiddle - wide) aboveMarkBot [widths.heading fine fine Downward]
		include : dispiro
			widths.center (stress * 2)
			flat (markMiddle + d + wide) aboveMarkTop [heading Downward]
			curl (markMiddle + d - wide) aboveMarkBot [widths.heading fine fine Downward]

	create-glyph 'kreskaAbove' : glyph-proc
		set-width 0
		include : refer-glyph 'tonosAbove'
		include : StdAnchors.narrow

	# Scaled-down glyphs for Vietnamese's secondary mark
	define [VNSecondaryMark s kx ky d] : glyph-proc
		include : ScaleAround markMiddle aboveMarkMid s s
		include : ApparentTranslate (1.5 * kx * markExtend) 0
		local my : aboveMarkStack - 0.5 * ky * AccentHeight
		set-mark-anchor 'above' markMiddle my markMiddle (my + d * AccentHeight)

	derive-composites 'acuteAbove/viSide' null 'acuteAbove' [VNSecondaryMark 0.75 1    1 0]
	derive-composites 'graveAbove/viSide' null 'graveAbove' [VNSecondaryMark 0.75 (-1) 1 0]
	derive-composites 'hookAbove/viSide'  null 'hookAbove'  [VNSecondaryMark 0.75 1    1 0]

	derive-composites 'acuteAbove/viCenter' null 'acuteAbove' [VNSecondaryMark 0.875 0 1.75 0.5]
	derive-composites 'graveAbove/viCenter' null 'graveAbove' [VNSecondaryMark 0.875 0 1.75 0.5]
	derive-composites 'hookAbove/viCenter'  null 'hookAbove'  [VNSecondaryMark 0.875 0 1.75 0.5]

	# Combining brackets

	create-glyph 'leftParenAbove' 0x1AC1 : glyph-proc
		set-width 0
		set-mark-anchor 'aboveBraceL' markMiddle aboveMarkMid (markMiddle - markExtend) aboveMarkMid
		local braceDepth : markExtend * 0.25
		local left : markMiddle - 1.5 * markExtend
		include : dispiro
			widths.lhs markFine
			g4 (left + braceDepth) (aboveMarkTop + markFine)
			g4 (left + OX)          aboveMarkMid
			g4 (left + braceDepth) (aboveMarkBot - markFine)

	create-glyph 'rightParenAbove' 0x1AC2 : glyph-proc
		set-width 0
		set-mark-anchor 'aboveBraceR' markMiddle aboveMarkMid (markMiddle + markExtend) aboveMarkMid
		local braceDepth : markExtend * 0.25
		local right : markMiddle + 1.5 * markExtend
		include : dispiro
			widths.rhs markFine
			g4 (right - braceDepth) (aboveMarkTop + markFine)
			g4 (right - OX)          aboveMarkMid
			g4 (right - braceDepth) (aboveMarkBot - markFine)

	create-glyph 'parenAbove' 0x1ABB : glyph-proc
		set-width 0
		include : refer-glyph 'leftParenAbove'
		include : refer-glyph 'rightParenAbove'
		# No need to setup anchors -- ccmp will help us

	create-glyph 'leftDoubleParenAbove' : glyph-proc
		set-width 0
		set-mark-anchor 'aboveBraceL' markMiddle aboveMarkMid (markMiddle - 1.5 * markExtend) aboveMarkMid
		local braceDepth : markExtend * 0.25
		local left : markMiddle - 1.5 * markExtend
		local gap : [HSwToV markFine] + [Math.max markFine : markExtend * 0.5]
		include : dispiro
			widths.lhs markFine
			g4 (left + braceDepth) (aboveMarkTop + markFine)
			g4 (left + OX)          aboveMarkMid
			g4 (left + braceDepth) (aboveMarkBot - markFine)
		include : dispiro
			widths.lhs markFine
			g4 (left - gap + braceDepth) (aboveMarkTop + markFine)
			g4 (left - gap + OX)          aboveMarkMid
			g4 (left - gap + braceDepth) (aboveMarkBot - markFine)

	create-glyph 'rightDoubleParenAbove' : glyph-proc
		set-width 0
		set-mark-anchor 'aboveBraceR' markMiddle aboveMarkMid (markMiddle + 1.5 * markExtend) aboveMarkMid
		local braceDepth : markExtend * 0.25
		local right : markMiddle + 1.5 * markExtend
		local gap : [HSwToV markFine] + [Math.max markFine : markExtend * 0.5]
		include : dispiro
			widths.rhs markFine
			g4 (right - braceDepth) (aboveMarkTop + markFine)
			g4 (right - OX)          aboveMarkMid
			g4 (right - braceDepth) (aboveMarkBot - markFine)
		include : dispiro
			widths.rhs markFine
			g4 (right + gap - braceDepth) (aboveMarkTop + markFine)
			g4 (right + gap - OX)          aboveMarkMid
			g4 (right + gap - braceDepth) (aboveMarkBot - markFine)

	create-glyph 'doubleParenAbove' 0x1ABC : glyph-proc
		set-width 0
		include : refer-glyph 'leftDoubleParenAbove'
		include : refer-glyph 'rightDoubleParenAbove'
		# No need to setup anchors -- ccmp will help us

	create-glyph 'leftBrackAbove' : glyph-proc
		set-width 0
		set-mark-anchor 'aboveBraceL' markMiddle aboveMarkMid (markMiddle - markExtend) aboveMarkMid
		local braceDepth : markExtend * 0.75
		local left : markMiddle - 1.75 * markExtend
		include : VBar.l left aboveMarkBot aboveMarkTop markFine
		include : HBar.t left (left + braceDepth) aboveMarkTop markFine
		include : HBar.b left (left + braceDepth) aboveMarkBot markFine

	create-glyph 'rightBrackAbove' : glyph-proc
		set-width 0
		set-mark-anchor 'aboveBraceR' markMiddle aboveMarkMid (markMiddle + markExtend) aboveMarkMid
		local braceDepth : markExtend * 0.75
		local right : markMiddle + 1.75 * markExtend
		include : VBar.r right aboveMarkBot aboveMarkTop markFine
		include : HBar.t (right - braceDepth) right aboveMarkTop markFine
		include : HBar.b (right - braceDepth) right aboveMarkBot markFine

	create-glyph 'brackAbove' 0x1AC5 : glyph-proc
		set-width 0
		include : refer-glyph 'leftBrackAbove'
		include : refer-glyph 'rightBrackAbove'
		# No need to setup anchors -- ccmp will help us

	create-glyph 'armn/abbreviationMark' 0x55F : glyph-proc
		set-width 0
		include : StdAnchors.wide

		local leftEnd  : markMiddle - markExtend * 1.5
		local rightEnd : markMiddle + markExtend * 1.5
		include : VBar.l leftEnd aboveMarkBot aboveMarkTop (markFine * 2)
		include : HBar.b leftEnd rightEnd aboveMarkBot (markFine * 2)
