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

import [mix fallback SuffixCfg] from "@iosevka/util"
import [MathSansSerif] from "@iosevka/glyph/relation"

glyph-module

glyph-block Letter-Latin-W : begin
	glyph-block-import CommonShapes
	glyph-block-import Common-Derivatives
	glyph-block-import Letter-Shared : CreateTurnedLetter
	glyph-block-import Letter-Shared-Shapes : DiagTail SerifFrame VerticalHook
	glyph-block-import Letter-Latin-Lower-M : EarlessRoundedDoubleArchSmallMShape
	glyph-block-import Letter-Latin-Upper-M : MShape

	define FORM-CURLY             0
	define FORM-STRAIGHT          1
	define FORM-VERTICAL          2
	define FORM-DOUBLE-V          3
	define FORM-ASYMMETRIC        4
	define FORM-CURSIVE           5
	define FORM-CYRL-OMEGA        6

	define MIDH-OTHER             0
	define MIDH-TOP               1
	define MIDH-ALMOST-TOP        2

	define SERIFS-NONE            0
	define SERIFS-AUTO            1
	define SERIFS-MOTION          2
	define SERIFS-DOUBLE-V        3
	define SERIFS-ASYMMETRIC      4
	define SERIFS-CURSIVE         5
	define SERIFS-CYRL-OMEGA      6
	define SERIFS-ALL             7
	define SERIFS-ALL-OUTER       8
	define SERIFS-ALL-ASYMMETRIC  9

	define CwFineOuter            5.0
	define CwFineInner            6.0
	define CwFineOuterStraight    5.5
	define CwFineInnerStraight    5.5
	define CwFineInnerDoubleV     4.25
	define CwOuterStrokeCurly     2.5
	define CwOuterStrokeStraight1 2.5
	define CwOuterStrokeStraight2 3.0
	define CwDoubleV              3.625
	define CwCyrlOmega            3.00
	define CwWCoCurly             5.0
	define CwWCoStraight          3.5
	define CwWCoDoubleV           3.5
	define PXBot1Curly            0.25
	define PXBot1Straight         0.235

	define [WMidHeight df top bodyType midHClass] : match bodyType
		[Just FORM-CURLY]    : top * 0.6
		[Just FORM-VERTICAL] : top * 0.55
		[Just FORM-STRAIGHT] : WMidHeightExt (top * 0.72) top bodyType midHClass
		[Just FORM-CURSIVE]  : WMidHeightExt [mix [df.adviceStroke 3.25] top (11 / 16)] top bodyType midHClass
		__                   : WMidHeightExt top top bodyType midHClass
	define [WMidHeightExt midh top bodyType midHClass] : match midHClass
		[Just MIDH-TOP]            top
		[Just MIDH-ALMOST-TOP]   : top - Stroke
		[Just MIDH-OTHER]          midh

	define [WDim df top bodyType slabType midHClass] : begin
		local CwOuterStrokeStraight : if (midHClass === MIDH-OTHER) CwOuterStrokeStraight1 CwOuterStrokeStraight2
		local strokeOuter : match bodyType
			[Just FORM-CURLY]             : AdviceStroke CwOuterStrokeCurly    : Math.sqrt df.adws
			[Just FORM-STRAIGHT]          : AdviceStroke CwOuterStrokeStraight : Math.sqrt df.adws
			[Just FORM-DOUBLE-V]          : AdviceStroke CwDoubleV             : Math.sqrt df.adws
			[Just FORM-ASYMMETRIC]        : AdviceStroke CwDoubleV             : Math.sqrt df.adws
			[Just FORM-CYRL-OMEGA]        : AdviceStroke CwCyrlOmega           : Math.sqrt df.adws
		local fineOuter : match bodyType
			[Just FORM-CURLY]             : AdviceStroke CwFineOuter           df.adws
			[Just FORM-STRAIGHT]          : AdviceStroke CwFineOuterStraight : Math.sqrt df.adws
			[Just FORM-DOUBLE-V]          : AdviceStroke CwDoubleV           : Math.sqrt df.adws
			[Just FORM-ASYMMETRIC]        : AdviceStroke CwDoubleV           : Math.sqrt df.adws
			[Just FORM-CYRL-OMEGA]        : AdviceStroke CwCyrlOmega         : Math.sqrt df.adws
		local fineInner : match bodyType
			[Just FORM-CURLY]             : AdviceStroke CwFineInner           df.adws
			[Just FORM-STRAIGHT]          : AdviceStroke CwFineInnerStraight : Math.sqrt df.adws
			[Just FORM-DOUBLE-V]          : AdviceStroke CwFineInnerDoubleV  : Math.sqrt df.adws
			[Just FORM-ASYMMETRIC]        : AdviceStroke CwDoubleV           : Math.sqrt df.adws
			[Just FORM-CYRL-OMEGA]        : AdviceStroke CwCyrlOmega         : Math.sqrt df.adws
		local fineHeight : (fineOuter + fineInner) / 2

		local wCo : match bodyType
			[Just FORM-CURLY]             : AdviceStroke CwWCoCurly    df.adws
			[Just FORM-STRAIGHT]          : AdviceStroke CwWCoStraight df.adws
			[Just FORM-DOUBLE-V]          : AdviceStroke CwWCoDoubleV  df.adws
			[Just FORM-ASYMMETRIC]        : AdviceStroke CwWCoDoubleV  df.adws
			[Just FORM-CYRL-OMEGA]        : AdviceStroke CwWCoDoubleV  df.adws
		local wCo2 : match bodyType
			[Just FORM-CYRL-OMEGA] : AdviceStroke CwCyrlOmega   df.adws
			_                        wCo

		local kWCoShrink CThin
		local pxBot1 : match bodyType
			[Just FORM-CURLY]               0.25
			[Just FORM-STRAIGHT]            0.235
			[Just FORM-DOUBLE-V]            0.315
			[Just FORM-ASYMMETRIC]          0.3
			[Just FORM-CYRL-OMEGA]          0.265

		local botMixOffset : HSwToV : 0.5 * wCo2
		local xBot1 : [if bodyType O 0] + [mix (df.leftSB + botMixOffset) (df.rightSB - botMixOffset) pxBot1]
		local xBot2 : df.width - xBot1
		local wMidHeight : WMidHeight df top bodyType midHClass
		local wMidHeightExt : WMidHeightExt wMidHeight top bodyType midHClass

		local xRight1 : match bodyType
			([Just FORM-DOUBLE-V] || [Just FORM-ASYMMETRIC] || [Just FORM-CYRL-OMEGA])
				mix (df.leftSB + botMixOffset) (df.rightSB - botMixOffset) (2 * pxBot1)
			__
				if (bodyType < FORM-DOUBLE-V) df.middle
		local xLeft2  : df.width - xRight1

		local corWCo : DiagCorDs wMidHeight (xRight1 - xBot1) wCo
		local wCoCr : corWCo * wCo

		local corFOuter : DiagCorDs top (xBot1 - df.leftSB) fineOuter
		local fineOuterCr : Math.min (kWCoShrink * wCoCr) : corFOuter * fineOuter
		local strokeOuterCr : corFOuter * strokeOuter

		local corFInner : DiagCorDs wMidHeight (xRight1 - xBot1) fineInner
		local fineInnerCr : Math.min wCoCr : corFInner * fineInner
		local fineInnerCrTop : match bodyType
			[Just FORM-DOUBLE-V]     fineInnerCr
			[Just FORM-ASYMMETRIC]   fineInnerCr
			[Just FORM-CYRL-OMEGA]   fineInnerCr
			__                     : kWCoShrink * wCoCr

		local curlyStraightSegLength : match bodyType
			[Just FORM-CURLY]  0.25
			__                 0.05

		return : object xBot1 xBot2 strokeOuter strokeOuterCr fineOuter fineOuterCr fineInner fineInnerCr fineInnerCrTop fineHeight wMidHeight wMidHeightExt xRight1 xLeft2 wCoCr curlyStraightSegLength

	define [WSerifs df top bodyType slabType dim] : glyph-proc
		local oSlabPos : match bodyType
			[Just FORM-CURLY]      0
			[Just FORM-VERTICAL]   0
			[Just FORM-CYRL-OMEGA] 0
			__                   : O * 2

		local sf  : SerifFrame top 0 df.leftSB df.rightSB (hSplit -- 3)
		local sfm : SerifFrame top 0 (df.leftSB + oSlabPos) (df.rightSB - oSlabPos) (hSplit -- 3)

		include : match slabType
			[Just SERIFS-NONE]           : glyph-proc
			[Just SERIFS-AUTO]           : NeedSlab SLAB : composite-proc sf.lt.full sf.rt.full
			[Just SERIFS-ALL]            : composite-proc sf.lt.full sf.rt.full
			[Just SERIFS-ALL-OUTER]      : composite-proc sfm.lt.outer sfm.rt.outer
			[Just SERIFS-ALL-ASYMMETRIC] : composite-proc sfm.lt.outer sfm.rt.full
			[Just SERIFS-MOTION]         : begin sfm.lt.outer
			[Just SERIFS-DOUBLE-V]       : NeedSlab SLAB : composite-proc sfm.lt.outer sfm.rt.outer
			[Just SERIFS-ASYMMETRIC]     : NeedSlab SLAB : composite-proc sfm.lt.outer sfm.rt.full
			[Just SERIFS-CURSIVE]        : NeedSlab SLAB sf.lt.outer
			[Just SERIFS-CYRL-OMEGA]     : begin
				local jut : Math.min Jut : [HSwToV : 0.5 * dim.strokeOuter] + 0.375 * (dim.xLeft2 - df.leftSB - [HSwToV : 1.5 * dim.strokeOuter])
				NeedSlab SLAB : composite-proc
					HSerif.mtAsymmetric (df.leftSB + [HSwToV : 0.5 * dim.strokeOuter]) dim.wMidHeight jut jut
					HSerif.mtAsymmetric dim.xLeft2 dim.wMidHeight jut jut

	### W and w
	define [WShapeImpl df top bodyType slabType midHClass] : glyph-proc
		local dim : WDim df top bodyType slabType midHClass

		include : tagged 'strokeDown1' : match bodyType
			([Just FORM-CURLY] || [Just FORM-CYRL-OMEGA]) : dispiro
				widths.lhs dim.strokeOuter
				flat df.leftSB top [heading Downward]
				curl df.leftSB (top * (1 - dim.curlyStraightSegLength)) [heading Downward]
				quadControls 0 0.3 6 unimportant
				g4   (dim.xBot1 - [HSwToV : 0.5 * dim.wCoCr]) 0 [widths.lhs.heading dim.fineOuterCr Downward]
			_ : dispiro
				widths.lhs dim.strokeOuterCr
				flat (df.leftSB + O * 2) top [heading Downward]
				g4   (dim.xBot1 - [HSwToV : 0.5 * dim.wCoCr]) 0 [widths.lhs.heading dim.fineOuterCr Downward]

		include : tagged 'strokeUp2' : match bodyType
			([Just FORM-CURLY] || [Just FORM-CYRL-OMEGA]) : dispiro
				widths.rhs dim.strokeOuter
				flat df.rightSB top [heading Downward]
				curl df.rightSB (top * (1 - dim.curlyStraightSegLength)) [heading Downward]
				quadControls 0 0.3 6 unimportant
				g4   (dim.xBot2 + [HSwToV : 0.5 * dim.wCoCr]) 0 [widths.rhs.heading dim.fineOuterCr Downward]
			_ : dispiro
				widths.rhs dim.strokeOuterCr
				flat (df.rightSB - O * 2) top [heading Downward]
				g4   (dim.xBot2 + [HSwToV : 0.5 * dim.wCoCr]) 0 [widths.rhs.heading dim.fineOuterCr Downward]

		local kTopShift : match bodyType
			[Just FORM-DOUBLE-V]     0
			[Just FORM-ASYMMETRIC]   0
			[Just FORM-CYRL-OMEGA]   0
			__                       1
		local k1 0.5
		local k2 : 1 - k1
		local shiftT  : HSwToV : kTopShift * (0.5 * dim.wCoCr - 0.5 * dim.fineInnerCrTop)
		local shiftB  : HSwToV               (0.5 * dim.wCoCr - 0.5 * dim.fineOuterCr   )

		include : tagged 'strokeUp1' : difference
			dispiro
				flat (dim.xRight1 - shiftT) dim.wMidHeight [widths.center.heading dim.fineInnerCrTop Downward]
				curl (dim.xBot1   + shiftB) 0              [widths.center.heading dim.fineOuterCr    Downward]
			match bodyType
				[Just FORM-CYRL-OMEGA] : spiro-outline
					corner df.width   (dim.wMidHeight + 1)
					corner dim.xLeft2 (dim.wMidHeight + 1)
					flat dim.xLeft2    dim.wMidHeight
					curl dim.xLeft2   (dim.wMidHeight * (1 - dim.curlyStraightSegLength))
					quadControls 0 0.3 6 unimportant
					corner (dim.xBot2 - shiftB)   0
					corner df.width 0
				[Just FORM-ASYMMETRIC] : spiro-outline
					corner dim.xLeft2 dim.wMidHeight
					corner dim.xBot2  0
					corner df.width  0
					corner df.width  dim.wMidHeight
				_ : no-shape

		include : tagged 'strokeDown2' : match bodyType
			[Just FORM-CYRL-OMEGA] : dispiro
				flat (dim.xLeft2 - [HSwToV : 0.5 * dim.strokeOuter]) dim.wMidHeight [widths.lhs.heading dim.strokeOuter Downward]
				curl (dim.xLeft2 - [HSwToV : 0.5 * dim.strokeOuter]) (dim.wMidHeight * (1 - dim.curlyStraightSegLength)) [heading Downward]
				quadControls 0 0.3 6 unimportant
				g4   (dim.xBot2  - shiftB) 0              [widths.center.heading dim.fineOuterCr    Downward]
			_ : dispiro
				flat (dim.xLeft2 + shiftT) dim.wMidHeight [widths.center.heading dim.fineInnerCrTop Downward]
				curl (dim.xBot2  - shiftB) 0              [widths.center.heading dim.fineOuterCr    Downward]

		if (dim.wMidHeightExt > dim.wMidHeight) : include : tagged 'strokeExtension' : VBar.m df.middle dim.wMidHeight dim.wMidHeightExt (dim.fineInnerCrTop + [VSwToH : shiftT * 2])

		include : WSerifs df top bodyType slabType dim

	define [WHooktopShape df top bodyType slabType midHClass] : glyph-proc
		include : WShapeImpl df top bodyType slabType midHClass

		local dim : WDim df top bodyType slabType midHClass

		# Eject unnecessary contours
		eject-contour 'strokeUp2'
		eject-contour 'serifRT'

		include : dispiro
			widths.rhs dim.strokeOuter
			straight.down.start df.rightSB (top - TailY - 0.5 * dim.strokeOuter - O) [heading Downward]
			quadControls 0 0.3 6 unimportant
			g4 (dim.xBot2 + [HSwToV : 0.5 * dim.wCoCr]) 0 [widths.rhs.heading dim.fineOuterCr Downward]

		include : VerticalHook.r
			x -- df.rightSB
			y -- (top - TailY - 0.5 * dim.strokeOuter - O)
			xDepth -- TailX
			yDepth -- (-TailY)
			sw -- dim.strokeOuter

	define [WVertSides df top bodyType slabType midHClass] : glyph-proc
		local wMidHeight : WMidHeight df top bodyType midHClass
		local wMidHeightExt : WMidHeightExt wMidHeight top bodyType midHClass

		include : new-glyph : glyph-proc
			include : MShape top df (form -- 2) (slabType -- 0) (middleYExt -- (top - wMidHeightExt))
			include : FlipAround (df.width / 2) (top / 2)

		include : WSerifs df top bodyType slabType

	define [WVSHookTopShape df top bodyType slabType midHClass] : glyph-proc
		include : WVertSides df top bodyType slabType midHClass

		# Eject unnecessary contours
		eject-contour 'strokeLeftBar'
		eject-contour 'serifRT'

		define sideSw : df.adviceStroke 3
		include : dispiro
			widths.rhs sideSw
			flat df.rightSB (top - TailY - HalfStroke - O) [heading Downward]
			curl df.rightSB [Math.min (0.8 * top) (top - TailY - HalfStroke - TINY)] [heading Downward]
			straight.down.end df.rightSB 0 [widths.rhs.heading [df.adviceStroke 4] Downward]

		include : VerticalHook.r df.rightSB (top - TailY - HalfStroke - O) TailX (-TailY) sideSw

	define [WRounded df top bodyType slabType midHClass] : glyph-proc
		local wMidHeight : WMidHeight df top bodyType midHClass
		local wMidHeightExt : WMidHeightExt wMidHeight top bodyType midHClass

		include : new-glyph : glyph-proc
			include : EarlessRoundedDoubleArchSmallMShape df top 0 (top - wMidHeightExt) 0
			include : FlipAround (df.width / 2) (top / 2)

		include : WSerifs df top bodyType slabType

	define [WHookTopRounded df top bodyType slabType midHClass] : glyph-proc
		local wMidHeight : WMidHeight df top bodyType midHClass
		local wMidHeightExt : WMidHeightExt wMidHeight top bodyType midHClass

		include : new-glyph : glyph-proc
			include : EarlessRoundedDoubleArchSmallMShape df top (TailY + HalfStroke + O) (top - wMidHeightExt) 0
			include : FlipAround (df.width / 2) (top / 2)

		include : WSerifs df top bodyType slabType
		eject-contour 'serifRT'

		include : VerticalHook.r df.rightSB (top - TailY - HalfStroke - O) TailX (-TailY) (sw -- df.mvs)

	define [WCursiveImplImpl fHookTop df top bodyType slabType midHClass] : glyph-proc
		define fine : df.adviceStroke 3.25
		define mfine : fine * CThin
		define x0 : mix df.leftSB df.rightSB 0.1
		define y0 : top - O
		define y1 : mix 0 top 0.8
		define x1 : df.leftSB + 0 * OX
		define y3 : mix fine top 0.375
		define y4 : WMidHeight df top bodyType midHClass
		define rInY : 1 * [DiagTail.DefaultInnerRadius]

		include : dispiro
			widths.lhs fine
			flat x1 top [heading Downward]
			curl x1 (fine + rInY) [heading Downward]
			arcvh 16
			g4 [Math.min ([mix (x1 + [HSwToV fine]) (df.middle - [HSwToV : 0.5 * fine]) 0.5] - [HSwToV : fine - mfine]) (x1 + [HSwToV fine] + rInY)] O [heading {.x (TanSlope + (0.5 * (fine - mfine) / fine)) .y 1}]
			archv 16
			flat (df.middle + [HSwToV : mfine - fine / 2]) y3 [widths.heading mfine 0 Upward]
			curl (df.middle + [HSwToV : mfine - fine / 2]) y4 [heading Upward]

		if fHookTop
		: then : begin
			include : VerticalHook.r df.rightSB (top - TailY - 0.5 * fine - O) TailX (-TailY) fine
			include : dispiro
				widths.rhs fine
				flat (df.width - x1) (top - TailY - 0.5 * fine - O) [heading Downward]
				curl (df.width - x1) y3 [heading Downward]
				arch.rhs 0 (sw -- fine) (swAfter -- mfine)
				flat (df.middle - [HSwToV : mfine - fine / 2]) y3 [widths.heading 0 mfine Upward]
				curl (df.middle - [HSwToV : mfine - fine / 2]) y4 [heading Upward]
		: else : begin
			include : dispiro
				widths.rhs fine
				g4 (df.width - x0) y0
				g4 (df.width - x1 - OX) (top / 2)
				arch.rhs 0 (sw -- fine) (swAfter -- mfine)
				flat (df.middle - [HSwToV : mfine - fine / 2]) y3 [widths.heading 0 mfine Upward]
				curl (df.middle - [HSwToV : mfine - fine / 2]) y4 [heading Upward]

		local sf : SerifFrame top 0 x1 df.rightSB
		include : match slabType
			[Just SERIFS-CURSIVE] : NeedSlab SLAB sf.lt.outer
			[Just SERIFS-MOTION]  : begin sf.lt.outer
			___                   : glyph-proc

	define [WCursiveImpl    df top bodyType slabType midHClass] : WCursiveImplImpl false df top bodyType slabType midHClass
	define [WHookTopCursive df top bodyType slabType midHClass] : WCursiveImplImpl true  df top bodyType slabType midHClass

	define WConfig : SuffixCfg.weave
		# Body
		object
			straight                           { WShapeImpl   WHooktopShape   FORM-STRAIGHT   MIDH-OTHER      para.advanceScaleM  para.advanceScaleM  }
			straightAsymmetric                 { WShapeImpl   WHooktopShape   FORM-ASYMMETRIC MIDH-TOP        para.advanceScaleM  para.advanceScaleT  }
			straightDoubleV                    { WShapeImpl   WHooktopShape   FORM-DOUBLE-V   MIDH-TOP        para.advanceScaleM  para.advanceScaleT  }
			straightAlmostFlatTop              { WShapeImpl   WHooktopShape   FORM-STRAIGHT   MIDH-ALMOST-TOP para.advanceScaleMM para.advanceScaleM  }
			straightFlatTop                    { WShapeImpl   WHooktopShape   FORM-STRAIGHT   MIDH-TOP        para.advanceScaleMM para.advanceScaleM  }
			straightVerticalSides              { WVertSides   WVSHookTopShape FORM-VERTICAL   MIDH-OTHER      para.advanceScaleM  para.advanceScaleT  }
			straightVerticalSidesFlatTop       { WVertSides   WVSHookTopShape FORM-VERTICAL   MIDH-TOP        para.advanceScaleM  para.advanceScaleT  }
			roundedVerticalSides               { WRounded     WHookTopRounded FORM-CURLY      MIDH-OTHER      para.advanceScaleMM para.advanceScaleMM }
			roundedVerticalSidesFlatTop        { WRounded     WHookTopRounded FORM-CURLY      MIDH-TOP        para.advanceScaleMM para.advanceScaleMM }
			curly                              { WShapeImpl   WHooktopShape   FORM-CURLY      MIDH-OTHER      para.advanceScaleM  para.advanceScaleM  }
			curlyAlmostFlatTop                 { WShapeImpl   WHooktopShape   FORM-CURLY      MIDH-ALMOST-TOP para.advanceScaleMM para.advanceScaleM  }
			curlyFlatTop                       { WShapeImpl   WHooktopShape   FORM-CURLY      MIDH-TOP        para.advanceScaleMM para.advanceScaleM  }
			cursive                            { WCursiveImpl WHookTopCursive FORM-CURSIVE    MIDH-OTHER      para.advanceScaleMM para.advanceScaleM  }
			cyrlOmega                          { WShapeImpl   WHooktopShape   FORM-CYRL-OMEGA MIDH-OTHER      para.advanceScaleMM para.advanceScaleM  }

		# Serifs
		function [body] : if (body == 'cyrlOmega')
			then : object [""  SERIFS-CYRL-OMEGA]
			else : object
				serifless     SERIFS-NONE
				motionSerifed SERIFS-MOTION
				serifed     : match body
					[Just 'straightAsymmetric']           SERIFS-ALL-ASYMMETRIC
					[Just 'straightDoubleV']              SERIFS-ALL-OUTER
					[Just 'straightFlatTop']              SERIFS-ALL-OUTER
					[Just 'straightVerticalSidesFlatTop'] SERIFS-ALL-OUTER
					[Just 'roundedVerticalSidesFlatTop']  SERIFS-ALL-OUTER
					[Just 'curlyFlatTop']                 SERIFS-ALL-OUTER
					[Just 'cursive']                      SERIFS-MOTION
					__                                    SERIFS-ALL

	foreach { suffix { {implT hookTopImplT bodyType midHClass Udiv Ldiv} slabType } } [pairs-of WConfig] : do
		create-glyph "W.\(suffix)" : glyph-proc
			local df : include : DivFrame Udiv 3
			include : df.markSet.capital
			include : implT df CAP bodyType slabType midHClass

		create-glyph "smcpW.\(suffix)" : glyph-proc
			local df : include : DivFrame [if (Udiv < para.advanceScaleMM) para.advanceScaleT para.advanceScaleM] 3
			include : df.markSet.e
			include : implT df XH bodyType slabType midHClass

		create-glyph "w.\(suffix)" : glyph-proc
			local df : include : DivFrame Ldiv 3
			include : df.markSet.e
			include : implT df XH bodyType slabType midHClass

		create-glyph "ww.\(suffix)": glyph-proc
			local df : include : DivFrame [if (Ldiv < para.advanceScaleM) para.advanceScaleF 1] 3
			include : df.markSet.capital

			local gap : CAP * 0.05
			include : implT df (CAP / 2 - gap / 2) bodyType slabType midHClass
			include : ApparentTranslate 0 (CAP / 2 + gap)
			include : implT df (CAP / 2 - gap / 2) bodyType slabType midHClass

		if hookTopImplT : create-glyph "WHookTop.\(suffix)" : glyph-proc
			local df : include : DivFrame Udiv 3
			include : df.markSet.capital
			include : hookTopImplT df CAP bodyType slabType midHClass

		if hookTopImplT : create-glyph "wHookTop.\(suffix)" : glyph-proc
			local df : include : DivFrame Ldiv 3
			include : df.markSet.e
			include : hookTopImplT df XH bodyType slabType midHClass

		create-glyph "currency/wonSign.\(suffix)" : glyph-proc
			local df : DivFrame Udiv 3
			include [refer-glyph "W.\(suffix)"] AS_BASE ALSO_METRICS
			include : HOverlayBar [mix df.leftSB 0 0.7] [mix df.rightSB df.width 0.7] (CAP * 0.60)
			include : HOverlayBar [mix df.leftSB 0 0.7] [mix df.rightSB df.width 0.7] (CAP * 0.35)

	select-variant 'W' 'W'
	link-reduced-variant 'W/sansSerif' 'W' MathSansSerif
	select-variant 'WHookTop' 0x2C72
	select-variant 'w' 'w'
	link-reduced-variant 'w/sansSerif' 'w' MathSansSerif
	select-variant 'smcpW' 0x1D21 (follow -- 'W')
	select-variant 'ww' 0x2AC (follow -- 'w')
	select-variant 'wHookTop' 0x2C73
	select-variant 'currency/wonSign' 0x20A9 (follow -- 'W')

	alias 'cyrl/We' 0x51C 'W'
	alias 'cyrl/we' 0x51D 'w'
	CreateTurnedLetter 'turnw' 0x28D 'w' HalfAdvance (XH / 2)

	alias 'cyrl/Omega' 0x460 'W.cyrlOmega'
	alias 'cyrl/omega' 0x461 'w.cyrlOmega'

	glyph-block-import Letter-Blackboard : BBS BBD
	glyph-block-import Letter-Latin-V : BBVShape BBVOuterMaskShape

	define [BBWShape top] : begin
		local offset : BBD * 2
		local ksW : [AdviceStroke2 8 2 top] / BBS
		local kdW : Math.min ksW 0.75
		return : union
			difference
				BBVShape SB (RightSB - offset) kdW ksW top
				BBVOuterMaskShape (SB + offset) RightSB kdW ksW top
			BBVShape (SB + offset) RightSB kdW ksW top

	create-glyph 'mathbb/W' 0x1D54E : composite-proc [MarkSet.capital] [BBWShape CAP]
	create-glyph 'mathbb/w' 0x1D568 : composite-proc [MarkSet.e]       [BBWShape XH]
