Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

PDFWArray.java 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /*-- $Id$ --
  2. ============================================================================
  3. The Apache Software License, Version 1.1
  4. ============================================================================
  5. Copyright (C) 1999 The Apache Software Foundation. All rights reserved.
  6. Redistribution and use in source and binary forms, with or without modifica-
  7. tion, are permitted provided that the following conditions are met:
  8. 1. Redistributions of source code must retain the above copyright notice,
  9. this list of conditions and the following disclaimer.
  10. 2. Redistributions in binary form must reproduce the above copyright notice,
  11. this list of conditions and the following disclaimer in the documentation
  12. and/or other materials provided with the distribution.
  13. 3. The end-user documentation included with the redistribution, if any, must
  14. include the following acknowledgment: "This product includes software
  15. developed by the Apache Software Foundation (http://www.apache.org/)."
  16. Alternately, this acknowledgment may appear in the software itself, if
  17. and wherever such third-party acknowledgments normally appear.
  18. 4. The names "Fop" and "Apache Software Foundation" must not be used to
  19. endorse or promote products derived from this software without prior
  20. written permission. For written permission, please contact
  21. apache@apache.org.
  22. 5. Products derived from this software may not be called "Apache", nor may
  23. "Apache" appear in their name, without prior written permission of the
  24. Apache Software Foundation.
  25. THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  26. INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  27. FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  28. APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  29. INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
  30. DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  31. OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  32. ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  33. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  34. THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  35. This software consists of voluntary contributions made by many individuals
  36. on behalf of the Apache Software Foundation and was originally created by
  37. James Tauber <jtauber@jtauber.com>. For more information on the Apache
  38. Software Foundation, please see <http://www.apache.org/>.
  39. */
  40. package org.apache.fop.pdf;
  41. import java.util.Vector;
  42. /**
  43. * class representing a <b>W</b> array for CID fonts.
  44. */
  45. public class PDFWArray {
  46. /** the metrics */
  47. private Vector entries;
  48. public PDFWArray() {
  49. entries = new Vector();
  50. }
  51. /**
  52. * add an entry for single starting CID.
  53. * i.e. in the form "c [w ...]"
  54. *
  55. * @param start the starting CID value.
  56. * @param metrics the metrics array.
  57. */
  58. public void addEntry(int start, int[] metrics) {
  59. entries.addElement(new Entry(start, metrics));
  60. }
  61. /**
  62. * add an entry for a range of CIDs (/W element on p 213)
  63. *
  64. * @param first the first CID in the range
  65. * @param last the last CID in the range
  66. * @param width the width for all CIDs in the range
  67. */
  68. public void addEntry(int first, int last, int width) {
  69. entries.addElement(new int[] {first, last, width});
  70. }
  71. /**
  72. * add an entry for a range of CIDs (/W2 element on p 210)
  73. *
  74. * @param first the first CID in the range
  75. * @param last the last CID in the range
  76. * @param width the width for all CIDs in the range
  77. * @param posX the x component for the vertical position vector
  78. * @param posY the y component for the vertical position vector
  79. */
  80. public void addEntry(int first, int last, int width, int posX, int posY) {
  81. entries.addElement(new int[] {first, last, width, posX, posY});
  82. }
  83. public byte[] toPDF() {
  84. return toPDFString().getBytes();
  85. }
  86. public String toPDFString() {
  87. StringBuffer p = new StringBuffer();
  88. p.append("[ ");
  89. int len = entries.size();
  90. for (int i = 0; i<len; i++) {
  91. Object entry = entries.elementAt(i);
  92. if (entry instanceof int[]) {
  93. int[] line = (int[])entry;
  94. for (int j = 0; j<line.length; j++) {
  95. p.append(line[j]); p.append(" ");
  96. }
  97. } else {
  98. ((Entry)entry).fillInPDF(p);
  99. }
  100. }
  101. p.append("]");
  102. return p.toString();
  103. }
  104. /** inner class for entries in the form "c [w ...]" */
  105. private static class Entry {
  106. private static final StringBuffer p = new StringBuffer();
  107. private int start;
  108. private int[] metrics;
  109. public Entry (int s, int[] m) {
  110. start = s;
  111. metrics = m;
  112. }
  113. public void fillInPDF(StringBuffer p) {
  114. //p.setLength(0);
  115. p.append(start); p.append(" [");
  116. for (int i = 0; i < metrics.length; i++) {
  117. p.append(this.metrics[i]);
  118. p.append(" ");
  119. }
  120. p.append("] ");
  121. }
  122. }
  123. }