// 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 layout implements MathJax's common TeX layout rules.
package layoutimport// BigDimen is MathJax's sentinel for an unset or effectively infinite// dimension.constBigDimen = 1_000_000// FullWidth is the percentage-width marker used by MathJax tables.constFullWidth = "100%"// BBox is MathJax's common-output bounding box. Dimensions are in ems.// L and R are space outside W, RScale is relative to the parent, IC is the// italic correction, Skew is the accent skew, and DX is the combining-accent// offset.typeBBoxstruct { W, H, D float64 Scale float64 RScale float64 L, R float64 PWidth string IC float64 Skew float64 DX float64}// NewBBox returns the initialized zero-width box used by MathJax. An omitted// height or depth is represented by -BigDimen.func (, , float64) *BBox {return &BBox{W: , H: , D: , Scale: 1, RScale: 1}}// ZeroBBox returns a fully specified zero box.func () *BBox { returnNewBBox(0, 0, 0) }// EmptyBBox returns a box whose height and depth have not been set.func () *BBox { returnNewBBox(0, -BigDimen, -BigDimen) }// Empty prepares b for Append and Combine operations.func ( *BBox) () *BBox { .W = 0 .H = -BigDimen .D = -BigDimenreturn}// Clean replaces unset dimensions with zero.func ( *BBox) () {if .W == -BigDimen { .W = 0 }if .H == -BigDimen { .H = 0 }if .D == -BigDimen { .D = 0 }}// Rescale multiplies the three geometric dimensions. It intentionally does// not modify spaces or scale metadata, matching MathJax 3.2.2.func ( *BBox) ( float64) { .W *= .H *= .D *= }// Combine expands b to include child at offset (x,y).func ( *BBox) ( *BBox, , float64) { := .RScale// JavaScript rounds each product before adding the offset. Keep those // rounding points when Go may otherwise fuse the multiply and addition. := + jscompat.NumberStep(*(.W+.L+.R)) := + jscompat.NumberStep(*.H) := jscompat.NumberStep(*.D) - if > .W { .W = }if > .H { .H = }if > .D { .D = }}// Append places child after the current width and expands height and depth.func ( *BBox) ( *BBox) { := .RScale// The source's width increment also rounds before the compound addition. .W += jscompat.NumberStep( * (.W + .L + .R))if *.H > .H { .H = * .H }if *.D > .D { .D = * .D }}// UpdateFrom overwrites b's geometric dimensions and copies a non-empty// percentage width.func ( *BBox) ( *BBox) { .H = .H .D = .D .W = .Wif .PWidth != "" { .PWidth = .PWidth }}// Clone returns an independent copy.func ( *BBox) () *BBox {if == nil {returnnil } := *return &}
The pages are generated with Goldsv0.8.7. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds.