All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.poi.hssf.record.common.ExtRst Maven / Gradle / Ivy

There is a newer version: 5.2.5
Show newest version
/* ====================================================================
   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.
==================================================================== */

package org.apache.poi.hssf.record.common;

import java.util.Arrays;
import java.util.stream.Stream;

import org.apache.poi.hssf.record.cont.ContinuableRecordOutput;
import org.apache.poi.util.IOUtils;
import org.apache.poi.util.Internal;
import org.apache.poi.util.LittleEndianInput;
import org.apache.poi.util.POILogFactory;
import org.apache.poi.util.POILogger;
import org.apache.poi.util.StringUtil;

@Internal
public class ExtRst implements Comparable {
    private static final POILogger _logger = POILogFactory.getLogger(ExtRst.class);
    //arbitrarily selected; may need to increase
    private static final int MAX_RECORD_LENGTH = 100_000;

    private short reserved;

    // This is a Phs (see page 881)
    private short formattingFontIndex;
    private short formattingOptions;

    // This is a RPHSSub (see page 894)
    private int numberOfRuns;
    private String phoneticText;

    // This is an array of PhRuns (see page 881)
    private PhRun[] phRuns;
    // Sometimes there's some cruft at the end
    private byte[] extraData;

    protected ExtRst() {
        populateEmpty();
    }

    protected ExtRst(ExtRst other) {
        reserved = other.reserved;
        formattingFontIndex = other.formattingFontIndex;
        formattingOptions = other.formattingOptions;
        numberOfRuns = other.numberOfRuns;
        phoneticText = other.phoneticText;
        phRuns = (other.phRuns == null) ? null : Stream.of(other.phRuns).map(PhRun::new).toArray(PhRun[]::new);
    }

    protected ExtRst(LittleEndianInput in, int expectedLength) {
        reserved = in.readShort();

        // Old style detection (Reserved = 0xFF)
        if(reserved == -1) {
            populateEmpty();
            return;
        }

        // Spot corrupt records
        if(reserved != 1) {
            _logger.log(POILogger.WARN, "Warning - ExtRst has wrong magic marker, expecting 1 but found " + reserved + " - ignoring");
            // Grab all the remaining data, and ignore it
            for(int i=0; i 0) {
            length2 = 0;
        }
        if(length1 != length2) {
            throw new IllegalStateException(
                    "The two length fields of the Phonetic Text don't agree! " +
                            length1 + " vs " + length2
            );
        }
        phoneticText = StringUtil.readUnicodeLE(in, length1);

        int runData = stringDataSize - 4 - 6 - (2*phoneticText.length());
        int numRuns = (runData / 6);
        phRuns = new PhRun[numRuns];
        for(int i=0; i




© 2015 - 2024 Weber Informatics LLC | Privacy Policy