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.0KB

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