View | Details | Raw Unified | Return to bug 45390
Collapse All | Expand All

(-)src/java/META-INF/services/org.apache.fop.fo.ElementMapping (+1 lines)
Lines 1-4 Link Here
1
org.apache.fop.fo.FOElementMapping
1
org.apache.fop.fo.FOElementMapping
2
org.apache.fop.fo.extensions.pdf.PDFExtensionElementMapping
2
org.apache.fop.fo.extensions.svg.SVGElementMapping
3
org.apache.fop.fo.extensions.svg.SVGElementMapping
3
org.apache.fop.fo.extensions.svg.BatikExtensionElementMapping
4
org.apache.fop.fo.extensions.svg.BatikExtensionElementMapping
4
org.apache.fop.fo.extensions.ExtensionElementMapping
5
org.apache.fop.fo.extensions.ExtensionElementMapping
(-)src/java/org/apache/fop/fo/extensions/pdf/AbstractPDFExtension.java (+57 lines)
Line 0 Link Here
1
/*
2
 * Licensed to the Apache Software Foundation (ASF) under one or more
3
 * contributor license agreements.  See the NOTICE file distributed with
4
 * this work for additional information regarding copyright ownership.
5
 * The ASF licenses this file to You under the Apache License, Version 2.0
6
 * (the "License"); you may not use this file except in compliance with
7
 * the License.  You may obtain a copy of the License at
8
 
9
 *      http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 */
17
/* $Id$ */
18
package org.apache.fop.fo.extensions.pdf;
19
20
import org.apache.fop.fo.extensions.ExtensionObj;
21
import org.apache.fop.fo.extensions.ExtensionAttachment;
22
import org.apache.fop.fo.FONode;
23
24
public abstract class AbstractPDFExtension extends ExtensionObj {
25
26
    /**
27
     * Create a new AbstractPDFExtension that is a child of the given
28
     * {@link FONode}
29
     * 
30
     * @param parent    the parent {@link FONode}
31
     */
32
    public AbstractPDFExtension(FONode parent) {
33
        super(parent);
34
    }
35
36
    /** {@inheritDoc} */
37
    public ExtensionAttachment getExtensionAttachment() {
38
        return new PDFExtensionAttachment(this);
39
    }
40
41
    /**
42
     * {@inheritDoc}
43
     * @return  {@link PDFExtensionElementMapping#URI}
44
     */
45
    public String getNamespaceURI() {
46
        return PDFExtensionElementMapping.URI;
47
    }
48
49
    /**
50
     * {@inheritDoc}
51
     * @return  {@link PDFExtensionElementMapping#PREFIX}
52
     */
53
    public String getNormalNamespacePrefix() {
54
        return PDFExtensionElementMapping.PREFIX;
55
    }
56
57
}
0
  + Id
58
  + Id
1
  + native
59
  + native
(-)src/java/org/apache/fop/fo/extensions/pdf/PDFDictionaryExtension.java (+127 lines)
Line 0 Link Here
1
/*
2
 * Licensed to the Apache Software Foundation (ASF) under one or more
3
 * contributor license agreements.  See the NOTICE file distributed with
4
 * this work for additional information regarding copyright ownership.
5
 * The ASF licenses this file to You under the Apache License, Version 2.0
6
 * (the "License"); you may not use this file except in compliance with
7
 * the License.  You may obtain a copy of the License at
8
 *
9
 *      http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 */
17
18
/* $Id$ */
19
20
package org.apache.fop.fo.extensions.pdf;
21
22
import org.apache.fop.fo.FONode;
23
import org.apache.fop.fo.ValidationException;
24
import org.apache.fop.fo.PropertyList;
25
import org.apache.fop.fo.extensions.ExtensionObj;
26
import org.apache.fop.apps.FOPException;
27
import org.apache.xmlgraphics.util.QName;
28
import org.xml.sax.Locator;
29
import org.xml.sax.Attributes;
30
31
import java.nio.CharBuffer;
32
import java.util.ListIterator;
33
34
/**
35
 * Class modelling the pdf:dictionary extension object.
36
 *
37
 * This extension, in co-operation with {@link PDFEntryExtension} allows 
38
 * the user to build dictionaries that will be injected into the 
39
 * PDF document.
40
 * If the type is specified as "catalog", the entries will be added to
41
 * the document catalog.
42
 */
43
public class PDFDictionaryExtension extends AbstractPDFExtension {
44
45
    public static final int TYPE_CATALOG = 0;
46
    public static final int TYPE_NORMAL = 1;
47
    
48
    static final String[] TYPES = { "catalog", "normal" };
49
    
50
    private int type;
51
    private String name;
52
53
    /**
54
     * Create a new PDFDictionaryExtension instance that is
55
     * a child of the given {@link FONode}.
56
     *
57
     * @param parent the parent {@link FONode}
58
     */
59
    public PDFDictionaryExtension(FONode parent) {
60
        super(parent);
61
    }
62
63
    private static int getType(String typeString) {
64
        for (int i = TYPES.length; --i >= 0;) {
65
            if (TYPES[i].equals(typeString)) {
66
                return i;
67
            }
68
        }
69
        assert false;
70
        return -1;
71
    }
72
    
73
    /** {@inheritDoc} */
74
    public void processNode(String elementName, Locator locator, Attributes attlist, PropertyList pList) throws FOPException {
75
        String dictType = attlist.getValue("type");
76
        if (dictType == null || "".equals(dictType)) {
77
            //assume "normal" if absent
78
            dictType = TYPES[TYPE_NORMAL];
79
        }
80
        this.type = getType(dictType);
81
        this.name = attlist.getValue("name");
82
    }
83
84
    /** {@inheritDoc} */
85
    protected void validateChildNode(Locator loc, String namespaceURI, String localName) throws ValidationException {
86
        if (PDFExtensionElementMapping.URI.equals(namespaceURI)) {
87
            if ("entry".equals(localName) || "dictionary".equals(localName)) {
88
                return; //no problem
89
            }
90
        }
91
        //TODO: Replace by extension-specific event (?)
92
        this.invalidChildError(loc, namespaceURI, localName);
93
    }
94
95
    /**
96
     * Return an <code>int</code> identifying the type of PDF dictionary.
97
     *
98
     * @return  one of {@link #TYPE_CATALOG}, or {@link #TYPE_NORMAL}
99
     */
100
    public int getType() {
101
        return this.type;
102
    }
103
104
    /**
105
     * Return a <code>java.lang.String</code> naming the type of PDF dictionary.
106
     * 
107
     * @return one of "catalog" or "normal"
108
     */
109
    public String getTypeName() {
110
        return TYPES[this.type];
111
    }
112
113
    /**
114
     * Return the name of this dictionary
115
     * 
116
     * @return the name of the dictionary
117
     */
118
    public String getName() {
119
        return this.name;
120
    }
121
    
122
    /** {@inheritDoc} */
123
    public String getLocalName() {
124
        return "dictionary";
125
    }
126
    
127
}
(-)src/java/org/apache/fop/fo/extensions/pdf/PDFEntryExtension.java (+109 lines)
Line 0 Link Here
1
/*
2
 * Licensed to the Apache Software Foundation (ASF) under one or more
3
 * contributor license agreements.  See the NOTICE file distributed with
4
 * this work for additional information regarding copyright ownership.
5
 * The ASF licenses this file to You under the Apache License, Version 2.0
6
 * (the "License"); you may not use this file except in compliance with
7
 * the License.  You may obtain a copy of the License at
8
 
9
 *      http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 */
17
/* $Id$ */
18
package org.apache.fop.fo.extensions.pdf;
19
20
import org.apache.fop.fo.FONode;
21
import org.apache.fop.fo.PropertyList;
22
import org.apache.fop.fo.ValidationException;
23
import org.apache.fop.apps.FOPException;
24
import org.xml.sax.Locator;
25
import org.xml.sax.Attributes;
26
27
import java.nio.CharBuffer;
28
29
/**
30
 * Class modelling the <code>pdf:entry</code> extension object.
31
 * This extension can be used to create PDF entries in a
32
 * <code>pdf:dictionary</code> object.
33
 * The object is mapped virtually one-on-one to PDF.
34
 * <br/><br/>
35
 * <code>&lt;pdf:entry name="PageMode">FullScreen&lt;/pdf:entry></code>
36
 * <br/><br/>
37
 * will result in "/PageMode FullScreen" being added as an entry
38
 * to the dictionary.
39
 */
40
public class PDFEntryExtension extends AbstractPDFExtension {
41
42
    private String entryName;
43
    private CharBuffer entryValue;
44
    
45
    /**
46
     * Construct a new PDFEntryExtension instance that is a child
47
     * of the given {@link org.apache.fop.fo.FONode}
48
     * 
49
     * @param parent    the parent {@link org.apache.fop.fo.FONode}
50
     */
51
    public PDFEntryExtension(FONode parent) {
52
        super(parent);
53
    }
54
    
55
    /** {@inheritDoc} */
56
    protected void validateChildNode(Locator loc, String namespaceURI, String localName) throws ValidationException {
57
        //TODO: Replace by extension-specific event (?)
58
        this.invalidChildError(loc, namespaceURI, localName);
59
    }
60
61
    /** {@inheritDoc} */
62
    public void processNode(String elementName, Locator locator, Attributes attlist, PropertyList pList) throws FOPException {
63
        this.entryName = attlist.getValue("name");
64
        if (this.entryName == null || "".equals(this.entryName)) {
65
            this.missingPropertyError("name");
66
        }
67
        super.processNode(elementName, locator, attlist, pList);
68
    }
69
70
    /** {@inheritDoc} */
71
    protected void addCharacters(char[] data, int start, int length, PropertyList pList, Locator locator) throws FOPException {
72
        if (this.entryValue == null) {
73
            this.entryValue = CharBuffer.allocate(length);
74
        } else {
75
            CharBuffer newExpr = CharBuffer.allocate(
76
                                    this.entryValue.length() + length);
77
            this.entryValue.position(0);
78
            newExpr.put(this.entryValue);
79
            this.entryValue = newExpr;
80
        }
81
        this.entryValue.put(data, start, length);
82
    }
83
84
    /**
85
     * Return the name of the PDF entry.
86
     * 
87
     * @return the name of the entry
88
     */
89
    public String getEntryName() {
90
        return this.entryName;
91
    }
92
93
    /**
94
     * Return the value of the PDF entry (= the #PCDATA 
95
     * content of the node in the source document)
96
     * 
97
     * @return the value of the entry
98
     */
99
    public String getEntryValue() {
100
        this.entryValue.rewind();
101
        return this.entryValue.toString();
102
    }
103
    
104
    /** {@inheritDoc} */
105
    public String getLocalName() {
106
        return "entry";
107
    }
108
    
109
}
0
  + Id
110
  + Id
1
  + native
111
  + native
(-)src/java/org/apache/fop/fo/extensions/pdf/PDFExtensionAttachment.java (+47 lines)
Line 0 Link Here
1
/*
2
 * Licensed to the Apache Software Foundation (ASF) under one or more
3
 * contributor license agreements.  See the NOTICE file distributed with
4
 * this work for additional information regarding copyright ownership.
5
 * The ASF licenses this file to You under the Apache License, Version 2.0
6
 * (the "License"); you may not use this file except in compliance with
7
 * the License.  You may obtain a copy of the License at
8
 
9
 *      http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 */
17
/* $Id$ */
18
package org.apache.fop.fo.extensions.pdf;
19
20
import org.apache.fop.fo.extensions.ExtensionAttachment;
21
22
import java.io.Serializable;
23
24
public class PDFExtensionAttachment implements ExtensionAttachment, Serializable {
25
26
    private AbstractPDFExtension ext;
27
    
28
    public PDFExtensionAttachment() {
29
        //nop
30
    }
31
    
32
    public PDFExtensionAttachment(AbstractPDFExtension ext) {
33
        this.ext = ext;
34
    }
35
    
36
    public AbstractPDFExtension getExtensionObject() {
37
        return this.ext;
38
    }
39
    
40
    /**
41
     * {@inheritDoc}
42
     * @return  {@link PDFExtensionElementMapping#URI}
43
     */
44
    public String getCategory() {
45
        return PDFExtensionElementMapping.URI;
46
    }
47
}
0
  + Id
48
  + Id
1
  + native
49
  + native
(-)src/java/org/apache/fop/fo/extensions/pdf/PDFExtensionElementMapping.java (+70 lines)
Line 0 Link Here
1
/*
2
 * Licensed to the Apache Software Foundation (ASF) under one or more
3
 * contributor license agreements.  See the NOTICE file distributed with
4
 * this work for additional information regarding copyright ownership.
5
 * The ASF licenses this file to You under the Apache License, Version 2.0
6
 * (the "License"); you may not use this file except in compliance with
7
 * the License.  You may obtain a copy of the License at
8
 
9
 *      http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 */
17
/* $Id$ */
18
package org.apache.fop.fo.extensions.pdf;
19
20
import org.apache.fop.fo.extensions.ExtensionElementMapping;
21
import org.apache.fop.fo.ElementMapping;
22
import org.apache.fop.fo.FONode;
23
24
import java.util.HashMap;
25
26
public class PDFExtensionElementMapping extends ExtensionElementMapping {
27
    
28
    /** The FOP PDF extension namespace URI */
29
    public static final String URI = "http://xmlgraphics.apache.org/fop/extensions/pdf";
30
    
31
    /** The standard namespace prefix */
32
    public static final String PREFIX = "pdf";
33
    /**
34
     * Constructor.
35
     */
36
    public PDFExtensionElementMapping() {
37
        namespaceURI = URI;
38
    }
39
40
    /**
41
     * Initialize the data structures.
42
     */
43
    protected void initialize() {
44
        if (foObjs == null) {
45
            foObjs = new HashMap();
46
            foObjs.put("dictionary", new PDFDictionaryExtensionMaker());
47
            foObjs.put("entry", new PDFEntryExtensionMaker());
48
        }
49
    }
50
51
    /** Inner class for making instances of {@link PDFDictionaryExtension} */
52
    static class PDFDictionaryExtensionMaker extends ElementMapping.Maker {
53
        public FONode make(FONode parent) {
54
            return new PDFDictionaryExtension(parent);
55
        }
56
    }
57
58
    /** Inner class for making instances of {@link PDFEntryExtension} */
59
    static class PDFEntryExtensionMaker extends ElementMapping.Maker {
60
        public FONode make(FONode parent) {
61
            return new PDFEntryExtension(parent);
62
        }
63
    }
64
65
    /** {@inheritDoc} */
66
    public String getStandardPrefix() {
67
        return PREFIX;
68
    }
69
70
}
0
  + Id
71
  + Id
1
  + native
72
  + native
(-)src/java/org/apache/fop/render/pdf/PDFRenderer.java (+32 lines)
Lines 76-81 Link Here
76
import org.apache.fop.events.ResourceEventProducer;
76
import org.apache.fop.events.ResourceEventProducer;
77
import org.apache.fop.fo.Constants;
77
import org.apache.fop.fo.Constants;
78
import org.apache.fop.fo.extensions.ExtensionAttachment;
78
import org.apache.fop.fo.extensions.ExtensionAttachment;
79
import org.apache.fop.fo.extensions.pdf.AbstractPDFExtension;
80
import org.apache.fop.fo.extensions.pdf.PDFDictionaryExtension;
81
import org.apache.fop.fo.extensions.pdf.PDFEntryExtension;
82
import org.apache.fop.fo.extensions.pdf.PDFExtensionAttachment;
83
import org.apache.fop.fo.extensions.pdf.PDFExtensionElementMapping;
79
import org.apache.fop.fo.extensions.xmp.XMPMetadata;
84
import org.apache.fop.fo.extensions.xmp.XMPMetadata;
80
import org.apache.fop.fonts.Font;
85
import org.apache.fop.fonts.Font;
81
import org.apache.fop.fonts.LazyFont;
86
import org.apache.fop.fonts.LazyFont;
Lines 98-103 Link Here
98
import org.apache.fop.pdf.PDFInfo;
103
import org.apache.fop.pdf.PDFInfo;
99
import org.apache.fop.pdf.PDFLink;
104
import org.apache.fop.pdf.PDFLink;
100
import org.apache.fop.pdf.PDFMetadata;
105
import org.apache.fop.pdf.PDFMetadata;
106
import org.apache.fop.pdf.PDFName;
101
import org.apache.fop.pdf.PDFNumber;
107
import org.apache.fop.pdf.PDFNumber;
102
import org.apache.fop.pdf.PDFNumsArray;
108
import org.apache.fop.pdf.PDFNumsArray;
103
import org.apache.fop.pdf.PDFOutline;
109
import org.apache.fop.pdf.PDFOutline;
Lines 548-553 Link Here
548
            if (XMPMetadata.CATEGORY.equals(attachment.getCategory())) {
554
            if (XMPMetadata.CATEGORY.equals(attachment.getCategory())) {
549
                renderXMPMetadata((XMPMetadata)attachment);
555
                renderXMPMetadata((XMPMetadata)attachment);
550
            }
556
            }
557
            if (PDFExtensionElementMapping.URI.equals(attachment.getCategory())) {
558
                renderPDFExtension((PDFExtensionAttachment)attachment);
559
            }
551
        }
560
        }
552
    }
561
    }
553
562
Lines 621-626 Link Here
621
        pdfDoc.getRoot().setMetadata(pdfMetadata);
630
        pdfDoc.getRoot().setMetadata(pdfMetadata);
622
    }
631
    }
623
632
633
    private void renderPDFExtension(PDFExtensionAttachment ext) {
634
        AbstractPDFExtension extNode = ext.getExtensionObject();
635
        if (extNode instanceof PDFDictionaryExtension) {
636
            PDFDictionaryExtension dict = (PDFDictionaryExtension)extNode;
637
            if (dict.getType() == PDFDictionaryExtension.TYPE_CATALOG) {
638
                //add the entries/subdictionaries to pdfDoc.getRoot()
639
                AbstractPDFExtension entry;
640
                PDFExtensionAttachment att;
641
                for (Iterator entryIter = dict.getExtensionAttachments().iterator(); entryIter.hasNext();) {
642
                    att = (PDFExtensionAttachment)entryIter.next();
643
                    entry = att.getExtensionObject();
644
                    if (entry instanceof PDFEntryExtension) {
645
                        pdfDoc.getRoot().put(
646
                                ((PDFEntryExtension)entry).getEntryName(),
647
                                new PDFName(((PDFEntryExtension)entry).getEntryValue()));
648
                    }
649
                }
650
            } else {
651
                //TODO??
652
            }
653
        }
654
    }
655
    
624
    /** {@inheritDoc} */
656
    /** {@inheritDoc} */
625
    public Graphics2DAdapter getGraphics2DAdapter() {
657
    public Graphics2DAdapter getGraphics2DAdapter() {
626
        return new PDFGraphics2DAdapter(this);
658
        return new PDFGraphics2DAdapter(this);

Return to bug 45390