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/subdictionaries 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 getDictionaryName() {
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 (+150 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
    public static final int TYPE_NUMBER = 0;
43
    public static final int TYPE_BOOLEAN = 1;
44
    public static final int TYPE_NAME = 2;
45
    public static final int TYPE_ARRAY = 3;
46
    
47
    static final String[] TYPES = { 
48
            "number", "boolean", "name", "array" };
49
    
50
    private String entryName;
51
    private int entryType;
52
    private CharBuffer entryValue;
53
    
54
    /**
55
     * Construct a new PDFEntryExtension instance that is a child
56
     * of the given {@link org.apache.fop.fo.FONode}
57
     * 
58
     * @param parent    the parent {@link org.apache.fop.fo.FONode}
59
     */
60
    public PDFEntryExtension(FONode parent) {
61
        super(parent);
62
    }
63
    
64
    private static int getType(String typeName) {
65
        for (int i = TYPES.length; --i >= 0;) {
66
            if (TYPES[i].equals(typeName)) {
67
                return i;
68
            }
69
        }
70
        assert false;
71
        return -1;
72
    }
73
    
74
    /** {@inheritDoc} */
75
    protected void validateChildNode(Locator loc, String namespaceURI, String localName) throws ValidationException {
76
        //TODO: Replace by extension-specific event (?)
77
        this.invalidChildError(loc, namespaceURI, localName);
78
    }
79
80
    /** {@inheritDoc} */
81
    public void processNode(String elementName, Locator locator, Attributes attlist, PropertyList pList) throws FOPException {
82
        this.entryName = attlist.getValue("name");
83
        if (this.entryName == null || "".equals(this.entryName)) {
84
            this.missingPropertyError("name");
85
        }
86
        
87
        this.entryType = getType(attlist.getValue("type"));
88
        
89
        super.processNode(elementName, locator, attlist, pList);
90
    }
91
92
    /** {@inheritDoc} */
93
    protected void addCharacters(char[] data, int start, int length, PropertyList pList, Locator locator) throws FOPException {
94
        if (this.entryValue == null) {
95
            this.entryValue = CharBuffer.allocate(length);
96
        } else {
97
            CharBuffer newExpr = CharBuffer.allocate(
98
                                    this.entryValue.length() + length);
99
            this.entryValue.position(0);
100
            newExpr.put(this.entryValue);
101
            this.entryValue = newExpr;
102
        }
103
        this.entryValue.put(data, start, length);
104
    }
105
106
    /**
107
     * Return the name of the PDF entry.
108
     * 
109
     * @return the name of the entry
110
     */
111
    public String getEntryName() {
112
        return this.entryName;
113
    }
114
115
    /**
116
     * Return the value of the PDF entry (= the #PCDATA 
117
     * content of the node in the source document)
118
     * 
119
     * @return the value of the entry
120
     */
121
    public String getEntryValue() {
122
        this.entryValue.rewind();
123
        return this.entryValue.toString();
124
    }
125
126
    /**
127
     * Return the type of this entry.
128
     * 
129
     * @return one of {@link #TYPE_NUMBER}, {@link #TYPE_BOOLEAN}, 
130
     *         {@link #TYPE_NAME}, or {@link#TYPE_ARRAY}
131
     */
132
    public int getEntryType() {
133
        return this.entryType;
134
    }
135
136
    /**
137
     * Return the type of this entry as a String.
138
     * 
139
     * @return the type name of this entry
140
     */
141
    public String getEntryTypeName() {
142
        return TYPES[this.entryType];
143
    }
144
    
145
    /** {@inheritDoc} */
146
    public String getLocalName() {
147
        return "entry";
148
    }
149
    
150
}
0
  + Id
151
  + Id
1
  + native
152
  + 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 (+73 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 renderPDFEntryExtension(PDFEntryExtension entry, PDFDictionary dict) {
634
        
635
        switch (entry.getEntryType()) {
636
        case PDFEntryExtension.TYPE_BOOLEAN:
637
            dict.put(
638
                    entry.getEntryName(), 
639
                    ("true".equals(entry.getEntryValue())));
640
            break;
641
        case PDFEntryExtension.TYPE_NAME:
642
            dict.put(
643
                    entry.getEntryName(), 
644
                    new PDFName(entry.getEntryValue()));
645
            break;
646
        case PDFEntryExtension.TYPE_NUMBER:
647
        case PDFEntryExtension.TYPE_ARRAY:
648
            //TODO: Implement
649
        default:
650
            assert false;
651
        }
652
        
653
    }
654
    
655
    private void renderPDFDictionaryExtension(PDFDictionaryExtension dict, PDFDictionary parent) {
656
        AbstractPDFExtension entry;
657
        PDFExtensionAttachment att;
658
        PDFDictionary pdfDict = null;
659
        
660
        if (parent == null) {
661
            //add entries to document catalog
662
            pdfDict = pdfDoc.getRoot();
663
        } else {
664
            pdfDict = new PDFDictionary(parent);
665
        }
666
        
667
        for (Iterator entryIter = dict.getExtensionAttachments().iterator(); entryIter.hasNext();) {
668
            att = (PDFExtensionAttachment)entryIter.next();
669
            entry = att.getExtensionObject();
670
            if (entry instanceof PDFEntryExtension) {
671
                //atomic entry
672
                renderPDFEntryExtension((PDFEntryExtension)entry, pdfDict);
673
            } else if (entry instanceof PDFDictionaryExtension) {
674
                //subdictionary
675
                renderPDFDictionaryExtension((PDFDictionaryExtension)entry, pdfDict);
676
            }
677
        }
678
        
679
        if (parent != null) {
680
            parent.put(dict.getDictionaryName(), pdfDict);
681
        }
682
    }
683
    
684
    private void renderPDFExtension(PDFExtensionAttachment ext) {
685
        AbstractPDFExtension extNode = ext.getExtensionObject();
686
        if (extNode instanceof PDFDictionaryExtension) {
687
            PDFDictionaryExtension dict = (PDFDictionaryExtension)extNode;
688
            if (dict.getType() == PDFDictionaryExtension.TYPE_CATALOG) {
689
                //add the entries/subdictionaries to pdfDoc.getRoot()
690
                renderPDFDictionaryExtension(dict, null);
691
            } else {
692
                //TODO??
693
            }
694
        }
695
    }
696
    
624
    /** {@inheritDoc} */
697
    /** {@inheritDoc} */
625
    public Graphics2DAdapter getGraphics2DAdapter() {
698
    public Graphics2DAdapter getGraphics2DAdapter() {
626
        return new PDFGraphics2DAdapter(this);
699
        return new PDFGraphics2DAdapter(this);
(-)src/java/org/apache/fop/pdf/PDFDictionary.java (+12 lines)
Lines 88-93 Link Here
88
        }
88
        }
89
        this.entries.put(name, new Integer(value));
89
        this.entries.put(name, new Integer(value));
90
    }
90
    }
91
92
    /**
93
     * Puts a new name/value pair.
94
     * @param name the name
95
     * @param value the value
96
     */
97
    public void put(String name, boolean value) {
98
        if (!entries.containsKey(name)) {
99
            this.order.add(name);
100
        }
101
        this.entries.put(name, value ? Boolean.TRUE : Boolean.FALSE);
102
    }
91
    
103
    
92
    /**
104
    /**
93
     * Returns the value given a name.
105
     * Returns the value given a name.

Return to bug 45390