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

org.jpedal.io.types.StringValue Maven / Gradle / Ivy

/*
 * ===========================================
 * Java Pdf Extraction Decoding Access Library
 * ===========================================
 *
 * Project Info:  http://www.idrsolutions.com
 * Help section for developers at http://www.idrsolutions.com/support/
 *
 * (C) Copyright 1997-2017 IDRsolutions and Contributors.
 *
 * This file is part of JPedal/JPDF2HTML5
 *
 @LICENSE@
 *
 * ---------------
 * StringValue.java
 * ---------------
 */
package org.jpedal.io.types;

import static org.jpedal.io.ObjectDecoder.debugFastCode;
import static org.jpedal.io.ObjectDecoder.padding;

import org.jpedal.objects.raw.PdfDictionary;
import org.jpedal.objects.raw.PdfObject;

/**
 *
 */
public class StringValue {


    public static int setStringConstantValue(final PdfObject pdfObject, int i, final byte[] raw, final int PDFkeyInt) {

        i = StreamReaderUtils.skipSpacesOrOtherCharacter(raw, i + 1, 47);

        final int keyStart = i;

        //move cursor to end of text
        while (raw[i] != 10 && raw[i] != 13 && raw[i] != 32 && raw[i] != 47 && raw[i] != 60 && raw[i] != 62) {
            i++;
        }

        //store value
        pdfObject.setConstant(PDFkeyInt, keyStart, i - keyStart, raw);

        if (debugFastCode) {
            System.out.println(padding + "Set constant in " + pdfObject + " to " + pdfObject.setConstant(PDFkeyInt, keyStart, i - keyStart, raw));
        }

        return i - 1;   // move back so loop works
    }


    public static int setStringKeyValue(final PdfObject pdfObject, int i, final byte[] raw, final int PDFkeyInt) {

        i = StreamReaderUtils.skipSpacesOrOtherCharacter(raw, i + 1, 47);

        final int keyStart = i;

        boolean isNull = false;

        //move cursor to end of text (allow for null)
        while (raw[i] != 'R' && !isNull) {

            //allow for null for Parent
            if (PDFkeyInt == PdfDictionary.Parent && StreamReaderUtils.isNull(raw, i)) {
                isNull = true;
            }

            i++;
        }

        if (!isNull) {
            setValue(pdfObject, 1 + i - keyStart, raw, PDFkeyInt, keyStart);
        }

        return i - 1; // move back so loop works
    }

    static void setValue(final PdfObject pdfObject, final int keyLength, final byte[] raw, final int PDFkeyInt, final int keyStart) {

        //set value
        final byte[] stringBytes = new byte[keyLength];
        System.arraycopy(raw, keyStart, stringBytes, 0, keyLength);

        //store value
        pdfObject.setStringKey(PDFkeyInt, stringBytes);

        if (debugFastCode) {
            System.out.println(padding + "Set constant in " + pdfObject + " to " + new String(stringBytes));
        }
    }

}






© 2015 - 2024 Weber Informatics LLC | Privacy Policy