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.

TXTRenderer.java 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /*
  2. * $Id$
  3. * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
  4. * For details on use and redistribution please refer to the
  5. * LICENSE file included with these sources.
  6. */
  7. // package com.eastpoint.chrysalis;
  8. package org.apache.fop.render.txt;
  9. // FOP
  10. import org.apache.fop.render.PrintRenderer;
  11. import org.apache.fop.render.pcl.*;
  12. import org.apache.fop.apps.FOPException;
  13. import org.apache.fop.fo.properties.*;
  14. import org.apache.fop.layout.*;
  15. import org.apache.fop.layout.inline.*;
  16. import org.apache.fop.datatypes.*;
  17. import org.apache.fop.pdf.PDFPathPaint;
  18. import org.apache.fop.pdf.PDFColor;
  19. import org.apache.fop.image.*;
  20. import org.apache.fop.svg.SVGArea;
  21. import org.w3c.dom.svg.SVGSVGElement;
  22. import org.w3c.dom.svg.SVGDocument;
  23. // Java
  24. import java.io.IOException;
  25. import java.io.OutputStream;
  26. import java.util.Enumeration;
  27. import java.util.Vector;
  28. import java.util.Hashtable;
  29. /**
  30. * Renderer that renders areas to plain text
  31. *
  32. * Modified by Mark Lillywhite mark-fop@inomial.com to use the new
  33. * Renderer interface.
  34. */
  35. public class TXTRenderer extends PrintRenderer {
  36. /**
  37. * the current stream to add Text commands to
  38. */
  39. PCLStream currentStream;
  40. private int pageHeight = 7920;
  41. // These variables control the virtual paggination functionality.
  42. public int curdiv = 0;
  43. private int divisions = -1;
  44. private int paperheight = -1; // Paper height in decipoints?
  45. public int orientation =
  46. -1; // -1=default/unknown, 0=portrait, 1=landscape.
  47. public int topmargin = -1; // Top margin in decipoints?
  48. public int leftmargin = -1; // Left margin in decipoints?
  49. private int fullmargin = 0;
  50. final boolean debug = false;
  51. // Variables for rendering text.
  52. StringBuffer charData[];
  53. StringBuffer decoData[];
  54. public float textCPI = 16.67f;
  55. public float textLPI = 8;
  56. int maxX = (int)(8.5f * textCPI + 1);
  57. int maxY = (int)(11f * textLPI + 1);
  58. float xFactor;
  59. float yFactor;
  60. public String lineEnding =
  61. "\r\n"; // Every line except the last line on a page (which will end with pageEnding) will be terminated with this string.
  62. public String pageEnding =
  63. "\f"; // Every page except the last one will end with this string.
  64. public boolean suppressGraphics =
  65. false; // If true then graphics/decorations will not be rendered - text only.
  66. boolean firstPage = false;
  67. public TXTRenderer() {}
  68. /**
  69. * set the TXT document's producer
  70. *
  71. * @param producer string indicating application producing PDF
  72. */
  73. public void setProducer(String producer) {}
  74. void addStr(int row, int col, String str, boolean ischar) {
  75. if (debug)
  76. System.out.println("TXTRenderer.addStr(" + row + ", " + col
  77. + ", \"" + str + "\", " + ischar + ")");
  78. if (suppressGraphics &&!ischar)
  79. return;
  80. StringBuffer sb;
  81. if (row < 0)
  82. row = 0;
  83. if (ischar)
  84. sb = charData[row];
  85. else
  86. sb = decoData[row];
  87. if (sb == null)
  88. sb = new StringBuffer();
  89. if ((col + str.length()) > maxX)
  90. col = maxX - str.length();
  91. if (col < 0) {
  92. col = 0;
  93. if (str.length() > maxX)
  94. str = str.substring(0, maxX);
  95. }
  96. // Pad to col
  97. for (int countr = sb.length(); countr < col; countr++)
  98. sb.append(' ');
  99. if (debug)
  100. System.out.println("TXTRenderer.addStr() sb.length()="
  101. + sb.length());
  102. for (int countr = col; countr < (col + str.length()); countr++) {
  103. if (countr >= sb.length())
  104. sb.append(str.charAt(countr - col));
  105. else {
  106. if (debug)
  107. System.out.println("TXTRenderer.addStr() sb.length()="
  108. + sb.length() + " countr=" + countr);
  109. sb.setCharAt(countr, str.charAt(countr - col));
  110. }
  111. }
  112. if (ischar)
  113. charData[row] = sb;
  114. else
  115. decoData[row] = sb;
  116. }
  117. }