update title
This commit is contained in:
parent
2976c9b0a2
commit
ace4715f04
3 changed files with 23 additions and 10 deletions
|
|
@ -795,7 +795,7 @@ func renderPPTX(ctx context.Context, ms *xmain.State, presentation *ppt.Presenta
|
|||
return err
|
||||
}
|
||||
|
||||
err = presentation.AddSlide(strings.Join(boardPath, " / "), pngImg)
|
||||
err = presentation.AddSlide(pngImg, currBoardPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -61,11 +61,21 @@ func getRelsSlideXml(imageId string) string {
|
|||
return fmt.Sprintf(RELS_SLIDE_XML, imageId, imageId)
|
||||
}
|
||||
|
||||
const SLIDE_XML = `<?xml version='1.0' encoding='UTF-8' standalone='yes'?><p:sld xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"><p:cSld><p:spTree><p:nvGrpSpPr><p:cNvPr id="1" name="" /><p:cNvGrpSpPr /><p:nvPr /></p:nvGrpSpPr><p:grpSpPr /><p:pic><p:nvPicPr><p:cNvPr id="2" name="%s" descr="%s" /><p:cNvPicPr><a:picLocks noChangeAspect="1" /></p:cNvPicPr><p:nvPr /></p:nvPicPr><p:blipFill><a:blip r:embed="%s" /><a:stretch><a:fillRect /></a:stretch></p:blipFill><p:spPr><a:xfrm><a:off x="%d" y="%d" /><a:ext cx="%d" cy="%d" /></a:xfrm><a:prstGeom prst="rect"><a:avLst /></a:prstGeom></p:spPr></p:pic><p:sp><p:nvSpPr><p:cNvPr id="95" name="%s" /><p:cNvSpPr txBox="1" /><p:nvPr /></p:nvSpPr><p:spPr><a:xfrm><a:off x="4001" y="6239" /><a:ext cx="9135998" cy="%d" /></a:xfrm><a:prstGeom prst="rect"><a:avLst /></a:prstGeom><a:ln w="12700"><a:miter lim="400000" /></a:ln><a:extLst><a:ext uri="{C572A759-6A51-4108-AA02-DFA0A04FC94B}"><ma14:wrappingTextBoxFlag val="1" xmlns:ma14="http://schemas.microsoft.com/office/mac/drawingml/2011/main" /></a:ext></a:extLst></p:spPr><p:txBody><a:bodyPr lIns="45719" rIns="45719"><a:spAutoFit /></a:bodyPr><a:lstStyle><a:lvl1pPr><a:defRPr sz="2400" /></a:lvl1pPr></a:lstStyle><a:p><a:pPr /><a:r><a:t>%s</a:t></a:r></a:p></p:txBody></p:sp></p:spTree></p:cSld><p:clrMapOvr><a:masterClrMapping /></p:clrMapOvr></p:sld>`
|
||||
const SLIDE_XML = `<?xml version='1.0' encoding='UTF-8' standalone='yes'?><p:sld xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"><p:cSld><p:spTree><p:nvGrpSpPr><p:cNvPr id="1" name="" /><p:cNvGrpSpPr /><p:nvPr /></p:nvGrpSpPr><p:grpSpPr /><p:pic><p:nvPicPr><p:cNvPr id="2" name="%s" descr="%s" /><p:cNvPicPr><a:picLocks noChangeAspect="1" /></p:cNvPicPr><p:nvPr /></p:nvPicPr><p:blipFill><a:blip r:embed="%s" /><a:stretch><a:fillRect /></a:stretch></p:blipFill><p:spPr><a:xfrm><a:off x="%d" y="%d" /><a:ext cx="%d" cy="%d" /></a:xfrm><a:prstGeom prst="rect"><a:avLst /></a:prstGeom></p:spPr></p:pic><p:sp><p:nvSpPr><p:cNvPr id="95" name="%s" /><p:cNvSpPr txBox="1" /><p:nvPr /></p:nvSpPr><p:spPr><a:xfrm><a:off x="4001" y="6239" /><a:ext cx="9135998" cy="%d" /></a:xfrm><a:prstGeom prst="rect"><a:avLst /></a:prstGeom><a:ln w="12700"><a:miter lim="400000" /></a:ln><a:extLst><a:ext uri="{C572A759-6A51-4108-AA02-DFA0A04FC94B}"><ma14:wrappingTextBoxFlag val="1" xmlns:ma14="http://schemas.microsoft.com/office/mac/drawingml/2011/main" /></a:ext></a:extLst></p:spPr><p:txBody><a:bodyPr lIns="45719" rIns="45719"><a:spAutoFit /></a:bodyPr><a:lstStyle><a:lvl1pPr><a:defRPr sz="2400" /></a:lvl1pPr></a:lstStyle><a:p><a:pPr />%s</a:p></p:txBody></p:sp></p:spTree></p:cSld><p:clrMapOvr><a:masterClrMapping /></p:clrMapOvr></p:sld>`
|
||||
|
||||
func getSlideXml(slideTitle, imageId string, top, left, width, height int) string {
|
||||
func getSlideXml(boardPath []string, imageId string, top, left, width, height int) string {
|
||||
var slideTitle string
|
||||
boardName := boardPath[len(boardPath)-1]
|
||||
prefixPath := boardPath[:len(boardPath)-1]
|
||||
if len(prefixPath) > 0 {
|
||||
prefix := strings.Join(prefixPath, " / ") + " / "
|
||||
slideTitle = fmt.Sprintf(`<a:r><a:t>%s</a:t></a:r><a:r><a:rPr b="1" /><a:t>%s</a:t></a:r>`, prefix, boardName)
|
||||
} else {
|
||||
slideTitle = fmt.Sprintf(`<a:r><a:rPr b="1" /><a:t>%s</a:t></a:r>`, boardName)
|
||||
}
|
||||
slideDescription := strings.Join(boardPath, " / ")
|
||||
top += HEADER_HEIGHT
|
||||
return fmt.Sprintf(SLIDE_XML, slideTitle, slideTitle, imageId, left, top, width, height, slideTitle, HEADER_HEIGHT, slideTitle)
|
||||
return fmt.Sprintf(SLIDE_XML, slideDescription, slideDescription, imageId, left, top, width, height, slideDescription, HEADER_HEIGHT, slideTitle)
|
||||
}
|
||||
|
||||
func getPresentationXmlRels(slideFileNames []string) string {
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ type Presentation struct {
|
|||
}
|
||||
|
||||
type Slide struct {
|
||||
Title string
|
||||
BoardPath []string
|
||||
Image []byte
|
||||
ImageWidth int
|
||||
ImageHeight int
|
||||
|
|
@ -33,7 +33,7 @@ func NewPresentation() *Presentation {
|
|||
return &Presentation{}
|
||||
}
|
||||
|
||||
func (p *Presentation) AddSlide(title string, pngContent []byte) error {
|
||||
func (p *Presentation) AddSlide(pngContent []byte, boardPath []string) error {
|
||||
src, err := png.Decode(bytes.NewReader(pngContent))
|
||||
if err != nil {
|
||||
return fmt.Errorf("error decoding PNG image: %v", err)
|
||||
|
|
@ -55,15 +55,18 @@ func (p *Presentation) AddSlide(title string, pngContent []byte) error {
|
|||
left = (IMAGE_WIDTH - width) / 2
|
||||
}
|
||||
|
||||
p.Slides = append(p.Slides, &Slide{
|
||||
Title: title,
|
||||
slide := &Slide{
|
||||
BoardPath: make([]string, len(boardPath)),
|
||||
Image: pngContent,
|
||||
ImageWidth: width,
|
||||
ImageHeight: height,
|
||||
ImageTop: top,
|
||||
ImageLeft: left,
|
||||
})
|
||||
}
|
||||
// it must copy the board path to avoid slice reference issues
|
||||
copy(slide.BoardPath, boardPath)
|
||||
|
||||
p.Slides = append(p.Slides, slide)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
@ -101,7 +104,7 @@ func (p *Presentation) SaveTo(filePath string) error {
|
|||
err = addFile(
|
||||
zipFile,
|
||||
fmt.Sprintf("ppt/slides/%s.xml", slideFileName),
|
||||
getSlideXml(slide.Title, imageId, slide.ImageTop, slide.ImageLeft, slide.ImageWidth, slide.ImageHeight),
|
||||
getSlideXml(slide.BoardPath, imageId, slide.ImageTop, slide.ImageLeft, slide.ImageWidth, slide.ImageHeight),
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
|
|||
Loading…
Reference in a new issue