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.

LineDataInfoProducer.java 2.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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.afp.ptoca;
  19. import java.io.IOException;
  20. import org.apache.commons.logging.Log;
  21. import org.apache.commons.logging.LogFactory;
  22. import org.apache.fop.afp.AFPLineDataInfo;
  23. /**
  24. * {@link PtocaProducer} implementation that interprets {@link AFPLineDataInfo} objects.
  25. */
  26. public class LineDataInfoProducer implements PtocaProducer, PtocaConstants {
  27. /** Static logging instance */
  28. private static final Log log = LogFactory.getLog(LineDataInfoProducer.class);
  29. private AFPLineDataInfo lineDataInfo;
  30. /**
  31. * Main constructor.
  32. * @param lineDataInfo the info object
  33. */
  34. public LineDataInfoProducer(AFPLineDataInfo lineDataInfo) {
  35. this.lineDataInfo = lineDataInfo;
  36. }
  37. /** {@inheritDoc} */
  38. public void produce(PtocaBuilder builder) throws IOException {
  39. builder.setTextOrientation(lineDataInfo.getRotation());
  40. int x1 = ensurePositive(lineDataInfo.getX1());
  41. int y1 = ensurePositive(lineDataInfo.getY1());
  42. builder.absoluteMoveBaseline(y1);
  43. builder.absoluteMoveInline(x1);
  44. builder.setExtendedTextColor(lineDataInfo.getColor());
  45. int x2 = ensurePositive(lineDataInfo.getX2());
  46. int y2 = ensurePositive(lineDataInfo.getY2());
  47. int thickness = lineDataInfo.getThickness();
  48. if (y1 == y2) {
  49. builder.drawIaxisRule(x2 - x1, thickness);
  50. } else if (x1 == x2) {
  51. builder.drawBaxisRule(y2 - y1, thickness);
  52. } else {
  53. log.error("Invalid axis rule: unable to draw line");
  54. return;
  55. }
  56. }
  57. private static int ensurePositive(int value) {
  58. if (value < 0) {
  59. return 0;
  60. }
  61. return value;
  62. }
  63. }