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

package font

import (
	

	
)

type svg []svgDocument

func newSvg( tables.SVG) (svg, error) {
	 := .SVGDocumentList.SVGRawData
	 := make(svg, len(.SVGDocumentList.DocumentRecords))
	for ,  := range .SVGDocumentList.DocumentRecords {
		,  := .SvgDocOffset, .SvgDocOffset+tables.Offset32(.SvgDocLength)
		if len() < int() {
			return nil, fmt.Errorf("invalid svg table (EOF: expected %d, got %d)", , len())
		}
		[] = svgDocument{
			first: .StartGlyphID,
			last:  .EndGlyphID,
			svg:   [:],
		}
	}
	return , nil
}

type svgDocument struct {
	// svg document
	// each glyph description must be written
	// in an element with id=glyphXXX
	svg   []byte
	first gID // The first glyph ID in the range described by this index entry.
	last  gID // The last glyph ID in the range described by this index entry. Must be >= startGlyphID.
}

// rawGlyphData returns the SVG document for [gid], or false.
func ( svg) ( gID) ([]byte, bool) {
	// binary search
	for ,  := 0, len();  < ; {
		 :=  + (-)/2
		 := []
		if  < .first {
			 = 
		} else if .last <  {
			 =  + 1
		} else {
			return .svg, true
		}
	}
	return nil, false
}