2019-07-25 19:43:46 +03:00
|
|
|
// Copyright 2018 FoxyUtils ehf. All rights reserved.
|
2018-09-26 20:01:52 -05:00
|
|
|
//
|
2020-08-08 01:01:05 +00:00
|
|
|
// Use of this software package and source code is governed by the terms of the
|
|
|
|
// UniDoc End User License Agreement (EULA) that is available at:
|
|
|
|
// https://unidoc.io/eula/
|
|
|
|
// A trial license code for evaluation can be obtained at https://unidoc.io.
|
2018-09-26 20:01:52 -05:00
|
|
|
|
|
|
|
package document
|
|
|
|
|
|
|
|
import (
|
2019-05-04 11:18:06 +03:00
|
|
|
"github.com/unidoc/unioffice"
|
|
|
|
"github.com/unidoc/unioffice/measurement"
|
|
|
|
"github.com/unidoc/unioffice/schema/soo/wml"
|
2018-09-26 20:01:52 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
// CellMargins are the margins for an individual cell.
|
|
|
|
type CellMargins struct {
|
|
|
|
x *wml.CT_TcMar
|
|
|
|
}
|
|
|
|
|
|
|
|
func setCellMarginPercent(w *wml.CT_TblWidth, pct float64) {
|
|
|
|
w.TypeAttr = wml.ST_TblWidthPct
|
|
|
|
w.WAttr = &wml.ST_MeasurementOrPercent{}
|
|
|
|
w.WAttr.ST_DecimalNumberOrPercent = &wml.ST_DecimalNumberOrPercent{}
|
2019-05-04 13:54:29 +00:00
|
|
|
w.WAttr.ST_DecimalNumberOrPercent.ST_UnqualifiedPercentage = unioffice.Int64(int64(pct * 50))
|
2018-09-26 20:01:52 -05:00
|
|
|
}
|
|
|
|
func setCellMargin(w *wml.CT_TblWidth, d measurement.Distance) {
|
|
|
|
w.TypeAttr = wml.ST_TblWidthDxa
|
|
|
|
w.WAttr = &wml.ST_MeasurementOrPercent{}
|
|
|
|
w.WAttr.ST_DecimalNumberOrPercent = &wml.ST_DecimalNumberOrPercent{}
|
2019-05-04 13:54:29 +00:00
|
|
|
w.WAttr.ST_DecimalNumberOrPercent.ST_UnqualifiedPercentage = unioffice.Int64(int64(d / measurement.Dxa))
|
2018-09-26 20:01:52 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// SetTopPct sets the cell top margin
|
|
|
|
func (c CellMargins) SetTopPct(pct float64) {
|
|
|
|
c.x.Top = wml.NewCT_TblWidth()
|
|
|
|
setCellMarginPercent(c.x.Top, pct)
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetTop sets the cell top margin
|
|
|
|
func (c CellMargins) SetTop(d measurement.Distance) {
|
|
|
|
c.x.Top = wml.NewCT_TblWidth()
|
|
|
|
setCellMargin(c.x.Top, d)
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetLeftPct sets the cell left margin
|
|
|
|
func (c CellMargins) SetLeftPct(pct float64) {
|
|
|
|
c.x.Left = wml.NewCT_TblWidth()
|
|
|
|
setCellMarginPercent(c.x.Left, pct)
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetLeft sets the cell left margin
|
|
|
|
func (c CellMargins) SetLeft(d measurement.Distance) {
|
|
|
|
c.x.Left = wml.NewCT_TblWidth()
|
|
|
|
setCellMargin(c.x.Left, d)
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetRightPct sets the cell right margin
|
|
|
|
func (c CellMargins) SetRightPct(pct float64) {
|
|
|
|
c.x.Right = wml.NewCT_TblWidth()
|
|
|
|
setCellMarginPercent(c.x.Right, pct)
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetRight sets the cell right margin
|
|
|
|
func (c CellMargins) SetRight(d measurement.Distance) {
|
|
|
|
c.x.Right = wml.NewCT_TblWidth()
|
|
|
|
setCellMargin(c.x.Right, d)
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetBottomPct sets the cell bottom margin
|
|
|
|
func (c CellMargins) SetBottomPct(pct float64) {
|
|
|
|
c.x.Bottom = wml.NewCT_TblWidth()
|
|
|
|
setCellMarginPercent(c.x.Bottom, pct)
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetBottom sets the cell bottom margin
|
|
|
|
func (c CellMargins) SetBottom(d measurement.Distance) {
|
|
|
|
c.x.Bottom = wml.NewCT_TblWidth()
|
|
|
|
setCellMargin(c.x.Bottom, d)
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetStartPct sets the cell start margin
|
|
|
|
func (c CellMargins) SetStartPct(pct float64) {
|
|
|
|
c.x.Start = wml.NewCT_TblWidth()
|
|
|
|
setCellMarginPercent(c.x.Start, pct)
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetStart sets the cell start margin
|
|
|
|
func (c CellMargins) SetStart(d measurement.Distance) {
|
|
|
|
c.x.Start = wml.NewCT_TblWidth()
|
|
|
|
setCellMargin(c.x.Start, d)
|
|
|
|
}
|