aboutsummaryrefslogtreecommitdiffstats
path: root/src/lua/lua_shingles.cxx
Commit message (Expand)AuthorAgeFilesLines
* [Fix] Use bundled libfmt everywherevstakhov-fmt-embeddingVsevolod Stakhov2025-03-101-1/+1
* [Minor] Deal with packed structure member properlyVsevolod Stakhov2025-01-251-1/+1
* [Minor] Slightly rework lua shingles to simplify storageVsevolod Stakhov2025-01-081-3/+16
* [Feature] Pass shingles to Lua scriptsvstakhov-lua-shinglesVsevolod Stakhov2025-01-061-5/+3
* [Feature] Allow to store shingles as opaque Lua dataVsevolod Stakhov2025-01-061-0/+122
#n12'>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
/*
 * 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.
 */

/* $Id$ */

package org.apache.fop.pdf;

import java.io.IOException;

import org.apache.commons.io.IOUtils;
import org.apache.commons.io.output.ByteArrayOutputStream;

/**
 * Represents the OutputIntent dictionary.
 * @since PDF 1.4
 */
public class PDFOutputIntent extends PDFObject {

    /** Subtype for PDF/X output intents */
    public static final String GTS_PDFX = "GTS_PDFX";
    /** Subtype for PDF/A-1 output intents */
    public static final String GTS_PDFA1 = "GTS_PDFA1";

    private String subtype; //S in the PDF spec
    private String outputCondition;
    private String outputConditionIdentifier;
    private String registryName;
    private String info;
    private PDFICCStream destOutputProfile;


    /** @return the output intent subtype. */
    public String getSubtype() {
        return subtype;
    }

    /**
     * Sets the output intent subtype.
     * @param subtype the subtype (usually "GTS_PDFX")
     */
    public void setSubtype(String subtype) {
        this.subtype = subtype;
    }

    /** @return the OutputCondition field */
    public String getOutputCondition() {
        return outputCondition;
    }

    /**
     * Sets the human-readable form of the output condition.
     * @param outputCondition A text string concisely identifying the intended output
     *                        device or production condition in human-readable form.
     */
    public void setOutputCondition(String outputCondition) {
        this.outputCondition = outputCondition;
    }

    /** @return the OutputConditionIdentifier field */
    public String getOutputConditionIdentifier() {
        return outputConditionIdentifier;
    }

    /**
     * Sets the identifier for the output condition.
     * @param outputConditionIdentifier A string identifying the intended output device or
     *                                  production condition in human- or machine-readable form.
     */
    public void setOutputConditionIdentifier(String outputConditionIdentifier) {
        this.outputConditionIdentifier = outputConditionIdentifier;
    }

    /** @return the RegistryName field */
    public String getRegistryName() {
        return registryName;
    }

    /**
     * Sets the registry name.
     * @param registryName A string (conventionally a uniform resource identifier,
     *                     or URI) identifying the registry in which the condition designated
     *                     by OutputConditionIdentifier is defined.
     */
    public void setRegistryName(String registryName) {
        this.registryName = registryName;
    }

    /** @return the Info field */
    public String getInfo() {
        return info;
    }

    /**
     * Sets the Info field.
     * @param info A human-readable text string containing additional information or comments about
     *             the intended target device or production condition.
     */
    public void setInfo(String info) {
        this.info = info;
    }

    /** @return the DestOutputProfile */
    public PDFICCStream getDestOutputProfile() {
        return destOutputProfile;
    }

    /**
     * Sets the destination ICC profile.
     * @param destOutputProfile An ICC profile stream defining the transformation from the PDF
     *                          document's source colors to output device colorants.
     */
    public void setDestOutputProfile(PDFICCStream destOutputProfile) {
        this.destOutputProfile = destOutputProfile;
    }

    /** {@inheritDoc} */
    public byte[] toPDF() {
        ByteArrayOutputStream bout = new ByteArrayOutputStream(128);
        try {
            bout.write(encode("<<\n"));
            bout.write(encode("/Type /OutputIntent\n"));

            bout.write(encode("/S /"));
            bout.write(encode(this.subtype));
            bout.write(encode("\n"));

            if (outputCondition != null) {
                bout.write(encode("/OutputCondition "));
                bout.write(encodeText(this.outputCondition));
                bout.write(encode("\n"));
            }

            bout.write(encode("/OutputConditionIdentifier "));
            bout.write(encodeText(this.outputConditionIdentifier));
            bout.write(encode("\n"));

            if (registryName != null) {
                bout.write(encode("/RegistryName "));
                bout.write(encodeText(this.registryName));
                bout.write(encode("\n"));
            }

            if (info != null) {
                bout.write(encode("/Info "));
                bout.write(encodeText(this.info));
                bout.write(encode("\n"));
            }

            if (destOutputProfile != null) {
                bout.write(encode("/DestOutputProfile " + destOutputProfile.referencePDF() + "\n"));
            }

            bout.write(encode(">>"));
        } catch (IOException ioe) {
            log.error("Ignored I/O exception", ioe);
        }
        byte[] bytes = bout.toByteArray();
        IOUtils.closeQuietly(bout);
        return bytes;
    }


}