Skip to content

Commit

Permalink
document: add support for controlling paragraph indentation
Browse files Browse the repository at this point in the history
  • Loading branch information
tbaliance committed Nov 29, 2017
1 parent 96b01f8 commit 2dfd95b
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
3 changes: 3 additions & 0 deletions _examples/document/simple/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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. ")

Expand Down
Binary file modified _examples/document/simple/simple.docx
Binary file not shown.
52 changes: 52 additions & 0 deletions document/paragraphproperties.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}

0 comments on commit 2dfd95b

Please sign in to comment.