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.pdf; 21 22 import java.io.IOException; 23 import java.io.OutputStream; 24 25 /** 26 * Optional Content Group Dictionary, which we will call a 'layer'. 27 */ 28 public class PDFLayer extends PDFIdentifiedDictionary { 29 30 public abstract static class Resolver { 31 private boolean resolved; 32 private PDFLayer layer; 33 private Object extension; Resolver(PDFLayer layer, Object extension)34 public Resolver(PDFLayer layer, Object extension) { 35 this.layer = layer; 36 this.extension = extension; 37 } getLayer()38 public PDFLayer getLayer() { 39 return layer; 40 } getExtension()41 public Object getExtension() { 42 return extension; 43 } resolve()44 public void resolve() { 45 if (!resolved) { 46 performResolution(); 47 resolved = true; 48 } 49 } performResolution()50 protected void performResolution() { 51 } 52 } 53 54 private Resolver resolver; 55 PDFLayer(String id)56 public PDFLayer(String id) { 57 super(id); 58 put("Type", new PDFName("OCG")); 59 } 60 61 @Override output(OutputStream stream)62 public int output(OutputStream stream) throws IOException { 63 if (resolver != null) { 64 resolver.resolve(); 65 } 66 return super.output(stream); 67 } 68 setResolver(Resolver resolver)69 public void setResolver(Resolver resolver) { 70 this.resolver = resolver; 71 } 72 populate(Object name, Object intent, Object usage)73 public void populate(Object name, Object intent, Object usage) { 74 if (name != null) { 75 put("Name", name); 76 } 77 if (intent != null) { 78 put("Intent", intent); 79 } 80 if (usage != null) { 81 put("Usage", usage); 82 } 83 } 84 85 } 86 87