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.

AFPRendererContext.java 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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.render.afp;
  19. import java.util.Map;
  20. import org.apache.avalon.framework.configuration.Configuration;
  21. import org.apache.fop.afp.AFPPaintingState;
  22. import org.apache.fop.afp.AFPResourceInfo;
  23. import org.apache.fop.afp.AFPResourceManager;
  24. import org.apache.fop.afp.modca.ResourceObject;
  25. import org.apache.fop.render.AbstractRenderer;
  26. import org.apache.fop.render.RendererContext;
  27. import org.apache.fop.render.RendererContextConstants;
  28. public class AFPRendererContext extends RendererContext {
  29. /**
  30. * Main constructor
  31. *
  32. * @param renderer the current renderer
  33. * @param mime the MIME type of the output that's generated.
  34. */
  35. public AFPRendererContext(AbstractRenderer renderer, String mime) {
  36. super(renderer, mime);
  37. }
  38. /**
  39. * Returns a new AFPInfo for this renderer context
  40. *
  41. * @return an AFPInfo for this renderer context
  42. */
  43. public AFPInfo getInfo() {
  44. AFPInfo info = new AFPInfo();
  45. info.setWidth(((Integer)getProperty(RendererContextConstants.WIDTH)).intValue());
  46. info.setHeight(((Integer)getProperty(RendererContextConstants.HEIGHT)).intValue());
  47. info.setX(((Integer)getProperty(RendererContextConstants.XPOS)).intValue());
  48. info.setY(((Integer)getProperty(RendererContextConstants.YPOS)).intValue());
  49. info.setHandlerConfiguration((Configuration)getProperty(
  50. RendererContextConstants.HANDLER_CONFIGURATION));
  51. info.setFontInfo((org.apache.fop.fonts.FontInfo)getProperty(
  52. AFPRendererContextConstants.AFP_FONT_INFO));
  53. info.setPaintingState((AFPPaintingState)getProperty(
  54. AFPRendererContextConstants.AFP_PAINTING_STATE));
  55. info.setResourceManager(((AFPResourceManager)getProperty(
  56. AFPRendererContextConstants.AFP_RESOURCE_MANAGER)));
  57. Map foreignAttributes = (Map)getProperty(RendererContextConstants.FOREIGN_ATTRIBUTES);
  58. if (foreignAttributes != null) {
  59. String conversionMode = (String)foreignAttributes.get(CONVERSION_MODE);
  60. boolean paintAsBitmap = BITMAP.equalsIgnoreCase(conversionMode);
  61. info.setPaintAsBitmap(paintAsBitmap);
  62. AFPForeignAttributeReader foreignAttributeReader
  63. = new AFPForeignAttributeReader();
  64. AFPResourceInfo resourceInfo
  65. = foreignAttributeReader.getResourceInfo(foreignAttributes);
  66. // set default resource level if an explicit one hasn't been set
  67. if (!resourceInfo.levelChanged()) {
  68. byte resourceType = paintAsBitmap
  69. ? ResourceObject.TYPE_IMAGE : ResourceObject.TYPE_GRAPHIC;
  70. resourceInfo.setLevel(info.getResourceManager().getResourceLevelDefaults()
  71. .getDefaultResourceLevel(resourceType));
  72. }
  73. info.setResourceInfo(resourceInfo);
  74. }
  75. return info;
  76. }
  77. }