// Copyright 2017-2022 The MathJax Consortium
// SPDX-License-Identifier: Apache-2.0
//
// This file is a Go translation and modification of MathJax 3.2.2.
// Sources: ts/output/common/FontData.ts and
// ts/output/common/fonts/tex.ts and fonts/tex/delimiters.ts.

package font

// Direction is MathJax FontData.DIRECTION.
type Direction uint8

const (
	DirectionNone Direction = iota
	DirectionVertical
	DirectionHorizontal
)

// Delimiter is a source-shaped copy of MathJax DelimiterData. Optional-field
// flags distinguish absent data from zero values. Returned slice fields are
// cloned and may be modified by callers.
type Delimiter struct {
	Direction Direction

	Sizes           []float64
	SizeVariants    []int
	SizeChars       []rune
	Stretch         []rune
	StretchVariants []int

	HDW    [3]float64
	HasHDW bool

	Min    float64
	HasMin bool

	Alias    rune
	HasAlias bool

	FullExt    [2]float64
	HasFullExt bool
}

func cloneDelimiter( Delimiter) Delimiter {
	.Sizes = append([]float64(nil), .Sizes...)
	.SizeVariants = append([]int(nil), .SizeVariants...)
	.SizeChars = append([]rune(nil), .SizeChars...)
	.Stretch = append([]rune(nil), .Stretch...)
	.StretchVariants = append([]int(nil), .StretchVariants...)
	return 
}

// LookupDelimiter returns the exact MathJax delimiter-table entry.
func ( rune) (Delimiter, bool) {
	,  := delimiterTable[]
	if ! {
		return Delimiter{}, false
	}
	return cloneDelimiter(), true
}

// DelimiterCount returns the number of entries in the upstream table.
func () int { return len(delimiterTable) }

var sizeVariants = [...]Variant{Normal, SmallOp, LargeOp, Size3, Size4, TeXVariant}
var stretchVariants = [...]Variant{Size4}

// SizeVariant returns the font variant for the delimiter's i-th fixed size.
func ( Delimiter) ( int) (Variant, bool) {
	if  < 0 {
		return "", false
	}
	 := 
	if len(.SizeVariants) != 0 {
		if  >= len(.SizeVariants) {
			return "", false
		}
		 = .SizeVariants[]
	}
	if  < 0 ||  >= len(sizeVariants) {
		return "", false
	}
	return sizeVariants[], true
}

// StretchVariant returns the font variant for the delimiter's i-th assembly
// part.
func ( Delimiter) ( int) (Variant, bool) {
	if  < 0 {
		return "", false
	}
	 := 0
	if len(.StretchVariants) != 0 {
		if  >= len(.StretchVariants) {
			return "", false
		}
		 = .StretchVariants[]
	}
	if  < 0 ||  >= len(stretchVariants) {
		return "", false
	}
	return stretchVariants[], true
}