zhao
2021-07-09 0821715ebc11d3934d0594a1cc2c39686d808906
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
/* ====================================================================
   Licensed to the Apache Software Foundation (ASF) Under one or more
   contributor license agreements.  See the NOTICE file distributed with
   this work for Additional information regarding copyright ownership.
   The ASF licenses this file to You Under the Apache License, Version 2.0
   (the "License"); you may not use this file except in compliance with
   the License.  You may obtain a copy of the License at
 
       http://www.apache.org/licenses/LICENSE-2.0
 
   Unless required by applicable law or agreed to in writing, software
   distributed Under the License is distributed on an "AS Is" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations Under the License.
==================================================================== */
 
namespace HH.WMS.Utils.NPOI.HSSF.Record
{
    using System.Text;
    using System;
    using HH.WMS.Utils.NPOI.Util;
    using System.Globalization;
 
 
    /**
     * NOTE: Comment Associated with a Cell (1Ch)
     *
     * @author Yegor Kozlov
     */
    public class NoteRecord : StandardRecord
    {
        public static NoteRecord[] EMPTY_ARRAY = { };
        public const short sid = 0x1C;
 
        /**
         * Flag indicating that the comment Is hidden (default)
         */
        public static short NOTE_HIDDEN = 0x0;
 
        /**
         * Flag indicating that the comment Is visible
         */
        public static short NOTE_VISIBLE = 0x2;
 
        private int field_1_row;
        private int field_2_col;
        private short field_3_flags;
        private int field_4_shapeid;
        private bool field_5_hasMultibyte;
        private String field_6_author;
        private const Byte DEFAULT_PADDING = (byte)0;
 
        /**
 * Saves padding byte value to reduce delta during round-trip serialization.<br/>
 *
 * The documentation is not clear about how padding should work.  In any case
 * Excel(2007) does something different.
 */
        private Byte? field_7_padding;
        /**
         * Construct a new <c>NoteRecord</c> and
         * Fill its data with the default values
         */
        public NoteRecord()
        {
            field_6_author = "";
            field_3_flags = 0;
            field_7_padding = DEFAULT_PADDING; // seems to be always present regardless of author text  
        }
 
        /**
         * Constructs a <c>NoteRecord</c> and Fills its fields
         * from the supplied <c>RecordInputStream</c>.
         *
         * @param in the stream to Read from
         */
        public NoteRecord(RecordInputStream in1)
        {
            field_1_row = in1.ReadShort();
            field_2_col = in1.ReadUShort();
            field_3_flags = in1.ReadShort();
            field_4_shapeid = in1.ReadUShort();
            int length = in1.ReadShort();
            field_5_hasMultibyte = in1.ReadByte() != 0x00;
            if (field_5_hasMultibyte) {
                field_6_author = StringUtil.ReadUnicodeLE(in1, length);
            } else {
                field_6_author = StringUtil.ReadCompressedUnicode(in1, length);
            }
             if (in1.Available() == 1) {
                field_7_padding = (byte)in1.ReadByte();
            }
        }
 
        /**
         * @return id of this record.
         */
        public override short Sid
        {
            get { return sid; }
        }
 
        /**
         * Serialize the record data into the supplied array of bytes
         *
         * @param offset offset in the <c>data</c>
         * @param data the data to Serialize into
         *
         * @return size of the record
         */
        public override void Serialize(ILittleEndianOutput out1)
        {
            out1.WriteShort(field_1_row);
            out1.WriteShort(field_2_col);
            out1.WriteShort(field_3_flags);
            out1.WriteShort(field_4_shapeid);
            out1.WriteShort(field_6_author.Length);
            out1.WriteByte(field_5_hasMultibyte ? 0x01 : 0x00);
            if (field_5_hasMultibyte) {
                StringUtil.PutUnicodeLE(field_6_author, out1);
            } else {
                StringUtil.PutCompressedUnicode(field_6_author, out1);
            }
            if (field_7_padding != null) {
                out1.WriteByte(Convert.ToInt32(field_7_padding, CultureInfo.InvariantCulture));
            }
 
        }
 
        /**
         * Size of record
         */
        protected override int DataSize
        {
            get
            {
                return 11 // 5 shorts + 1 byte
                    + field_6_author.Length * (field_5_hasMultibyte ? 2 : 1)
                    + (field_7_padding == null ? 0 : 1);
            }
        }
 
        /**
         * Convert this record to string.
         * Used by BiffViewer and other utulities.
         */
        public override String ToString()
        {
            StringBuilder buffer = new StringBuilder();
 
            buffer.Append("[NOTE]\n");
            buffer.Append("    .recordid = 0x" + StringUtil.ToHexString(Sid) + ", size = " + RecordSize + "\n");
            buffer.Append("    .row =     " + field_1_row + "\n");
            buffer.Append("    .col =     " + field_2_col + "\n");
            buffer.Append("    .flags =   " + field_3_flags + "\n");
            buffer.Append("    .shapeid = " + field_4_shapeid + "\n");
            buffer.Append("    .author =  " + field_6_author + "\n");
            buffer.Append("[/NOTE]\n");
            return buffer.ToString();
        }
 
        /**
         * Return the row that Contains the comment
         *
         * @return the row that Contains the comment
         */
        public int Row
        {
            get{return field_1_row;}
            set{ field_1_row = value;}
        }
 
        /**
         * Return the column that Contains the comment
         *
         * @return the column that Contains the comment
         */
        public int Column
        {
            get { return field_2_col; }
            set { field_2_col = value; }
        }
 
        /**
         * Options flags.
         *
         * @return the options flag
         * @see #NOTE_VISIBLE
         * @see #NOTE_HIDDEN
         */
        public short Flags
        {
            get { return field_3_flags; }
            set { field_3_flags = value; }
        }
 
        /**
         * Object id for OBJ record that Contains the comment
         */
        public int ShapeId
        {
            get { return field_4_shapeid; }
            set { field_4_shapeid = value; }
        }
 
 
        /**
         * Name of the original comment author
         *
         * @return the name of the original author of the comment
         */
        public String Author
        {
            get { return field_6_author; }
            set
            {
                field_6_author = value;
                field_5_hasMultibyte = StringUtil.HasMultibyte(value);
            }
        }
 
        /**
 * For unit testing only!
 */
        internal bool AuthorIsMultibyte
        {
            get
            {
                return field_5_hasMultibyte;
            }
        }
 
        public override Object Clone()
        {
            NoteRecord rec = new NoteRecord();
            rec.field_1_row = field_1_row;
            rec.field_2_col = field_2_col;
            rec.field_3_flags = field_3_flags;
            rec.field_4_shapeid = field_4_shapeid;
            rec.field_6_author = field_6_author;
            return rec;
        }
 
    }
}