2019-07-25 19:43:46 +03:00
|
|
|
// Copyright 2017 FoxyUtils ehf. All rights reserved.
|
2017-10-03 09:55:27 -05:00
|
|
|
//
|
|
|
|
// Use of this source code is governed by the terms of the Affero GNU General
|
|
|
|
// Public License version 3.0 as published by the Free Software Foundation and
|
|
|
|
// appearing in the file LICENSE included in the packaging of this file. A
|
Functions2 (#348)
* MATCH, IFS, MAXA, MINA
* OFFSET fixed
* ISBLANK, ISERR, ISERROR, ISEVEN ,ISFORMULA, ISNONTEXT, ISNUMBER, ISODD, ISTEXT
* ISLEAPYEAR, ISLOGICAL, ISNA, ISREF
* FIND, FINDB
* SEARCH, SEARCHB
* CONCAT, CONCATENATE
* YEAR, YEARFRAC
* CONCAT is fixed, now TRUE and FALSE are concatenated instead of 1 and 0 in case of boolean results
* NOW, TODAY, TIME, TIMEVALUE
* DATE
* DATEDIF
2019-11-21 02:21:00 +03:00
|
|
|
// commercial license can be purchased on https://unidoc.io.
|
2017-10-03 09:55:27 -05:00
|
|
|
|
|
|
|
package presentation
|
|
|
|
|
|
|
|
import (
|
|
|
|
"archive/zip"
|
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
|
2019-05-04 11:18:06 +03:00
|
|
|
"github.com/unidoc/unioffice"
|
2020-04-24 15:01:19 +03:00
|
|
|
"github.com/unidoc/unioffice/common/tempstorage"
|
2019-05-04 11:18:06 +03:00
|
|
|
"github.com/unidoc/unioffice/zippkg"
|
2017-10-03 09:55:27 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
// Read reads a document from an io.Reader.
|
|
|
|
func Read(r io.ReaderAt, size int64) (*Presentation, error) {
|
2018-03-13 07:46:34 -05:00
|
|
|
doc := newEmpty()
|
2017-10-03 09:55:27 -05:00
|
|
|
|
2020-04-24 15:01:19 +03:00
|
|
|
tmpPath, err := tempstorage.TempDir("gooxml-pptx")
|
2017-10-03 09:55:27 -05:00
|
|
|
if err != nil {
|
2020-04-24 15:01:19 +03:00
|
|
|
return nil, fmt.Errorf("creating zip: %s", err)
|
2017-10-03 09:55:27 -05:00
|
|
|
}
|
2020-04-24 15:01:19 +03:00
|
|
|
doc.TmpPath = tmpPath
|
2017-10-03 09:55:27 -05:00
|
|
|
|
|
|
|
zr, err := zip.NewReader(r, size)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("parsing zip: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
files := []*zip.File{}
|
|
|
|
files = append(files, zr.File...)
|
|
|
|
|
2020-04-24 15:01:19 +03:00
|
|
|
addCustom := false
|
|
|
|
for _, f := range files {
|
|
|
|
if f.FileHeader.Name == "docProps/custom.xml" {
|
|
|
|
addCustom = true
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if addCustom {
|
|
|
|
doc.createCustomProperties()
|
|
|
|
}
|
|
|
|
|
2017-10-03 09:55:27 -05:00
|
|
|
decMap := zippkg.DecodeMap{}
|
|
|
|
decMap.SetOnNewRelationshipFunc(doc.onNewRelationship)
|
|
|
|
// we should discover all contents by starting with these two files
|
2019-05-04 13:54:29 +00:00
|
|
|
decMap.AddTarget(unioffice.ContentTypesFilename, doc.ContentTypes.X(), "", 0)
|
|
|
|
decMap.AddTarget(unioffice.BaseRelsFilename, doc.Rels.X(), "", 0)
|
2017-10-03 09:55:27 -05:00
|
|
|
if err := decMap.Decode(files); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, f := range files {
|
|
|
|
if f == nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if err := doc.AddExtraFileFromZip(f); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
2020-04-24 15:01:19 +03:00
|
|
|
|
|
|
|
if addCustom {
|
|
|
|
customPropertiesExist := false
|
|
|
|
for _, rel := range doc.Rels.X().Relationship {
|
|
|
|
if rel.TargetAttr == "docProps/custom.xml" {
|
|
|
|
customPropertiesExist = true
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if !customPropertiesExist {
|
|
|
|
doc.addCustomRelationships()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-03 09:55:27 -05:00
|
|
|
return doc, nil
|
|
|
|
}
|