Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

AFPTextElementBridge.java 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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 org.apache.batik.bridge.SVGTextElementBridge;
  20. import org.apache.batik.bridge.BridgeContext;
  21. import org.apache.batik.gvt.GraphicsNode;
  22. import org.apache.batik.gvt.TextNode;
  23. import org.apache.batik.gvt.TextPainter;
  24. import org.w3c.dom.Element;
  25. import org.w3c.dom.Node;
  26. /**
  27. * Bridge class for the <text> element.
  28. * This bridge will use the direct text painter if the text
  29. * for the element is simple.
  30. */
  31. public class AFPTextElementBridge extends SVGTextElementBridge {
  32. private AFPTextPainter textPainter;
  33. /**
  34. * Constructs a new bridge for the <text> element.
  35. * @param textPainter the text painter to use
  36. */
  37. public AFPTextElementBridge(AFPTextPainter textPainter) {
  38. this.textPainter = textPainter;
  39. }
  40. /**
  41. * Create a text element bridge.
  42. * This set the text painter on the node if the text is simple.
  43. * @param ctx the bridge context
  44. * @param e the svg element
  45. * @return the text graphics node created by the super class
  46. */
  47. public GraphicsNode createGraphicsNode(BridgeContext ctx, Element e) {
  48. GraphicsNode node = super.createGraphicsNode(ctx, e);
  49. if (node != null && isSimple(ctx, e, node)) {
  50. ((TextNode)node).setTextPainter(getTextPainter());
  51. }
  52. return node;
  53. }
  54. private TextPainter getTextPainter() {
  55. return this.textPainter;
  56. }
  57. /**
  58. * Check if text element contains simple text.
  59. * This checks the children of the text element to determine
  60. * if the text is simple. The text is simple if it can be rendered
  61. * with basic text drawing algorithms. This means there are no
  62. * alternate characters, the font is known and there are no effects
  63. * applied to the text.
  64. *
  65. * @param ctx the bridge context
  66. * @param element the svg text element
  67. * @param node the graphics node
  68. * @return true if this text is simple of false if it cannot be
  69. * easily rendered using normal drawString on the PDFGraphics2D
  70. */
  71. private boolean isSimple(BridgeContext ctx, Element element, GraphicsNode node) {
  72. for (Node n = element.getFirstChild();
  73. n != null;
  74. n = n.getNextSibling()) {
  75. switch (n.getNodeType()) {
  76. case Node.ELEMENT_NODE:
  77. if (n.getLocalName().equals(SVG_TSPAN_TAG)
  78. || n.getLocalName().equals(SVG_ALT_GLYPH_TAG)) {
  79. return false;
  80. } else if (n.getLocalName().equals(SVG_TEXT_PATH_TAG)) {
  81. return false;
  82. } else if (n.getLocalName().equals(SVG_TREF_TAG)) {
  83. return false;
  84. }
  85. break;
  86. case Node.TEXT_NODE:
  87. case Node.CDATA_SECTION_NODE:
  88. default:
  89. }
  90. }
  91. /*if (CSSUtilities.convertFilter(element, node, ctx) != null) {
  92. return false;
  93. }*/
  94. return true;
  95. }
  96. }