document: add support for controlling paragraph indentation

Fixes #123
This commit is contained in:
Todd 2017-11-29 17:25:19 -06:00
parent 96b01f8d98
commit 2dfd95bb54
3 changed files with 55 additions and 0 deletions

View File

@ -4,6 +4,7 @@ package main
import (
"baliance.com/gooxml/color"
"baliance.com/gooxml/document"
"baliance.com/gooxml/measurement"
"baliance.com/gooxml/schema/soo/wml"
)
@ -31,6 +32,8 @@ func main() {
run.AddText("Some Heading Text")
para = doc.AddParagraph()
para.Properties().SetFirstLineIndent(0.5 * measurement.Inch)
run = para.AddRun()
run.AddText("A run is a string of characters with the same formatting. ")

View File

@ -138,3 +138,55 @@ func (p ParagraphProperties) SetWindowControl(b bool) {
p.x.WidowControl = wml.NewCT_OnOff()
}
}
// SetFirstLineIndent controls the indentation of the first line in a paragraph.
func (p ParagraphProperties) SetFirstLineIndent(m measurement.Distance) {
if p.x.Ind == nil {
p.x.Ind = wml.NewCT_Ind()
}
if m == measurement.Zero {
p.x.Ind.FirstLineAttr = nil
} else {
p.x.Ind.FirstLineAttr = &sharedTypes.ST_TwipsMeasure{}
p.x.Ind.FirstLineAttr.ST_UnsignedDecimalNumber = gooxml.Uint64(uint64(m / measurement.Twips))
}
}
// SetStartIndent controls the start indentation.
func (p ParagraphProperties) SetStartIndent(m measurement.Distance) {
if p.x.Ind == nil {
p.x.Ind = wml.NewCT_Ind()
}
if m == measurement.Zero {
p.x.Ind.StartAttr = nil
} else {
p.x.Ind.StartAttr = &wml.ST_SignedTwipsMeasure{}
p.x.Ind.StartAttr.Int64 = gooxml.Int64(int64(m / measurement.Twips))
}
}
// SetEndIdent controls the end indentation.
func (p ParagraphProperties) SetEndIndent(m measurement.Distance) {
if p.x.Ind == nil {
p.x.Ind = wml.NewCT_Ind()
}
if m == measurement.Zero {
p.x.Ind.EndAttr = nil
} else {
p.x.Ind.EndAttr = &wml.ST_SignedTwipsMeasure{}
p.x.Ind.EndAttr.Int64 = gooxml.Int64(int64(m / measurement.Twips))
}
}
// SetHangingIndent controls the indentation of the non-first lines in a paragraph.
func (p ParagraphProperties) SetHangingIndent(m measurement.Distance) {
if p.x.Ind == nil {
p.x.Ind = wml.NewCT_Ind()
}
if m == measurement.Zero {
p.x.Ind.HangingAttr = nil
} else {
p.x.Ind.HangingAttr = &sharedTypes.ST_TwipsMeasure{}
p.x.Ind.HangingAttr.ST_UnsignedDecimalNumber = gooxml.Uint64(uint64(m / measurement.Twips))
}
}