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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 // CSOK: ConstantName
  29. = LogFactory.getLog(LineDataInfoProducer.class);
  30. private AFPLineDataInfo lineDataInfo;
  31. /**
  32. * Main constructor.
  33. * @param lineDataInfo the info object
  34. */
  35. public LineDataInfoProducer(AFPLineDataInfo lineDataInfo) {
  36. this.lineDataInfo = lineDataInfo;
  37. }
  38. /** {@inheritDoc} */
  39. public void produce(PtocaBuilder builder) throws IOException {
  40. builder.setTextOrientation(lineDataInfo.getRotation());
  41. int x1 = ensurePositive(lineDataInfo.getX1());
  42. int y1 = ensurePositive(lineDataInfo.getY1());
  43. builder.absoluteMoveBaseline(y1);
  44. builder.absoluteMoveInline(x1);
  45. builder.setExtendedTextColor(lineDataInfo.getColor());
  46. int x2 = ensurePositive(lineDataInfo.getX2());
  47. int y2 = ensurePositive(lineDataInfo.getY2());
  48. int thickness = lineDataInfo.getThickness();
  49. if (y1 == y2) {
  50. builder.drawIaxisRule(x2 - x1, thickness);
  51. } else if (x1 == x2) {
  52. builder.drawBaxisRule(y2 - y1, thickness);
  53. } else {
  54. log.error("Invalid axis rule: unable to draw line");
  55. return;
  56. }
  57. }
  58. private static int ensurePositive(int value) {
  59. if (value < 0) {
  60. return 0;
  61. }
  62. return value;
  63. }
  64. }