// SPDX-License-Identifier: Unlicense OR BSD-3-Clause

package font

import (
	
	

	
)

type os2 struct {
	version       uint16
	xAvgCharWidth uint16

	*os2Desc

	useTypoMetrics bool // true if the field sTypoAscender, sTypoDescender and sTypoLineGap are valid.

	ySubscriptXSize     float32
	ySubscriptYSize     float32
	ySubscriptXOffset   float32
	ySubscriptYOffset   float32
	ySuperscriptXSize   float32
	ySuperscriptYSize   float32
	ySuperscriptXOffset float32
	yStrikeoutSize      float32
	yStrikeoutPosition  float32
	sTypoAscender       float32
	sTypoDescender      float32
	sTypoLineGap        float32
	sxHeigh             float32
	sCapHeight          float32
}

func newOs2( tables.Os2) (os2, error) {
	 := os2{
		version:             .Version,
		xAvgCharWidth:       .XAvgCharWidth,
		os2Desc:             newOS2Desc(),
		ySubscriptXSize:     float32(.YSubscriptXSize),
		ySubscriptYSize:     float32(.YSubscriptYSize),
		ySubscriptXOffset:   float32(.YSubscriptXOffset),
		ySubscriptYOffset:   float32(.YSubscriptYOffset),
		ySuperscriptXSize:   float32(.YSuperscriptXSize),
		ySuperscriptYSize:   float32(.YSuperscriptYSize),
		ySuperscriptXOffset: float32(.YSuperscriptXOffset),
		yStrikeoutSize:      float32(.YStrikeoutSize),
		yStrikeoutPosition:  float32(.YStrikeoutPosition),
		sTypoAscender:       float32(.STypoAscender),
		sTypoDescender:      float32(.STypoDescender),
		sTypoLineGap:        float32(.STypoLineGap),
	}
	// add addition info for version >= 2
	if .Version >= 2 {
		if len(.HigherVersionData) < 12 {
			return os2{}, errors.New("invalid table os2")
		}
		.sxHeigh = float32(binary.BigEndian.Uint16(.HigherVersionData[8:]))
		.sCapHeight = float32(binary.BigEndian.Uint16(.HigherVersionData[10:]))
	}

	const  = 1 << 7
	 := .FsSelection& != 0
	 := .USWeightClass != 0 || .USWidthClass != 0 || .USFirstCharIndex != 0 || .USLastCharIndex != 0
	.useTypoMetrics =  && 

	return , nil
}