// 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.

package svg

import (
	
	

	
)

type paddedDimensions struct {
	contentH float64
	contentD float64
	contentW float64
	deltaH   float64
	deltaD   float64
	deltaW   float64
	x        float64
	y        float64
	dx       float64
}

func ( *wrapper) () paddedDimensions {
	 := layout.ZeroBBox()
	if len(.children) != 0 {
		 = .children[0].getBBox()
	}
	, ,  := .H, .D, .W
	, ,  := , , 
	if  := stringAttribute(.node, "width", "");  != "" {
		 = .paddedDimension(, , "w", true)
	}
	if  := stringAttribute(.node, "height", "");  != "" {
		 = .paddedDimension(, , "h", true)
	}
	if  := stringAttribute(.node, "depth", "");  != "" {
		 = .paddedDimension(, , "d", true)
	}
	,  := 0.0, 0.0
	if  := stringAttribute(.node, "voffset", "");  != "" {
		 = .paddedDimension(, , "", false)
	}
	if  := stringAttribute(.node, "lspace", "");  != "" {
		 = .paddedDimension(, , "", false)
	}
	 := 0.0
	if  := stringAttribute(.node, "data-align", "");  != "" {
		 = paddedAlignX(, , )
	}
	return paddedDimensions{
		contentH: , contentD: , contentW: ,
		deltaH:  - , deltaD:  - , deltaW:  - ,
		x: , y: , dx: ,
	}
}

func ( *wrapper) ( string,  *layout.BBox,  string,  bool) float64 {
	 := 0.0
	if strings.Contains(, "width") {
		 = .W
	} else if strings.Contains(, "height") {
		 = .H
	} else if strings.Contains(, "depth") {
		 = .D
	} else {
		switch  {
		case "w":
			 = .W
		case "h":
			 = .H
		case "d":
			 = .D
		}
	}
	 := layout.Length2Em(, , .Scale, .renderer.pxPerEm)
	if  != "" && (strings.HasPrefix(, "+") || strings.HasPrefix(, "-")) {
		 += 
	}
	if  {
		 = math.Max(0, )
	}
	return 
}

func paddedAlignX( float64,  *layout.BBox,  string) float64 {
	switch  {
	case "right":
		return  - (.W+.R)*.RScale
	case "left":
		return .L * .RScale
	default:
		return ( - .W*.RScale) / 2
	}
}

func ( *wrapper) ( *layout.BBox) {
	 := .getPaddedDimensions()
	.W = .contentW + .deltaW
	.H = .contentH + .deltaH
	.D = .contentD + .deltaD
	// CommonMpadded resolves percentage children against its authored width
	// before an enclosing wrapper can cache their dimensions.
	.setChildPWidths(.W, true)
}

func ( *wrapper) ( *Element) {
	 := .standardSVG()
	 := .getPaddedDimensions()
	 := stringAttribute(.node, "data-align", "left")
	 := .x + .dx
	if .deltaW < 0 &&  != "left" {
		if  == "center" {
			 -= .deltaW / 2
		} else {
			 -= .deltaW
		}
	}
	 := 
	if  != 0 || .y != 0 {
		 = NewElement("g")
		.Append()
		.place(, .y, )
	}
	.addChildren()
}