property.go 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // Copyright 2014 Richard Lehane. All rights reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package msoleps
  15. import (
  16. "encoding/binary"
  17. "github.com/richardlehane/msoleps/types"
  18. )
  19. type Property struct {
  20. Name string
  21. T types.Type
  22. }
  23. func (p *Property) String() string {
  24. return p.T.String()
  25. }
  26. func (p *Property) Type() string {
  27. return p.T.Type()
  28. }
  29. type propertySetStream struct {
  30. byteOrder uint16
  31. version uint16
  32. SystemID uint32
  33. CLSID types.Guid
  34. numPropertySets uint32
  35. fmtidA types.Guid
  36. offsetA uint32
  37. fmtidB types.Guid // This can be absent (i.e. not null)
  38. offsetB uint32
  39. }
  40. func makePropertySetStream(b []byte) (*propertySetStream, error) {
  41. if len(b) < 48 {
  42. return nil, ErrFormat
  43. }
  44. ps := &propertySetStream{}
  45. ps.byteOrder = binary.LittleEndian.Uint16(b[:2])
  46. ps.version = binary.LittleEndian.Uint16(b[2:4])
  47. ps.SystemID = binary.LittleEndian.Uint32(b[4:8])
  48. g, _ := types.MakeGuid(b[8:])
  49. ps.CLSID = g.(types.Guid)
  50. ps.numPropertySets = binary.LittleEndian.Uint32(b[24:28])
  51. g, _ = types.MakeGuid(b[28:])
  52. ps.fmtidA, _ = g.(types.Guid)
  53. ps.offsetA = binary.LittleEndian.Uint32(b[44:48])
  54. if ps.numPropertySets != 2 {
  55. return ps, nil
  56. }
  57. if len(b) < 68 {
  58. return nil, ErrFormat
  59. }
  60. g, _ = types.MakeGuid(b[48:])
  61. ps.fmtidB = g.(types.Guid)
  62. ps.offsetB = binary.LittleEndian.Uint32(b[64:68])
  63. return ps, nil
  64. }
  65. type propertySet struct {
  66. size uint32
  67. numProperties uint32
  68. idsOffs []propertyIDandOffset
  69. dict map[uint32]string
  70. code types.CodePageID
  71. }
  72. type propertyIDandOffset struct {
  73. id uint32
  74. offset uint32
  75. }