You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

PDFLayer.java 2.3KB

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