選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

PDFWArray.java 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /*
  2. * Copyright 1999-2004 The Apache Software Foundation.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /* $Id$ */
  17. package org.apache.fop.pdf;
  18. import java.util.List;
  19. /**
  20. * Class representing a <b>W</b> array for CID fonts.
  21. */
  22. public class PDFWArray {
  23. /**
  24. * The metrics
  25. */
  26. private List entries = new java.util.ArrayList();
  27. /**
  28. * Default constructor
  29. */
  30. public PDFWArray() {
  31. }
  32. /**
  33. * Convenience constructor
  34. * @param metrics the metrics array to initially add
  35. */
  36. public PDFWArray(int[] metrics) {
  37. addEntry(0, metrics);
  38. }
  39. /**
  40. * Add an entry for single starting CID.
  41. * i.e. in the form "c [w ...]"
  42. *
  43. * @param start the starting CID value.
  44. * @param metrics the metrics array.
  45. */
  46. public void addEntry(int start, int[] metrics) {
  47. entries.add(new Entry(start, metrics));
  48. }
  49. /**
  50. * Add an entry for a range of CIDs (/W element on p 213)
  51. *
  52. * @param first the first CID in the range
  53. * @param last the last CID in the range
  54. * @param width the width for all CIDs in the range
  55. */
  56. public void addEntry(int first, int last, int width) {
  57. entries.add(new int[] {
  58. first, last, width
  59. });
  60. }
  61. /**
  62. * Add an entry for a range of CIDs (/W2 element on p 210)
  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. * @param posX the x component for the vertical position vector
  68. * @param posY the y component for the vertical position vector
  69. */
  70. public void addEntry(int first, int last, int width, int posX, int posY) {
  71. entries.add(new int[] {
  72. first, last, width, posX, posY
  73. });
  74. }
  75. /**
  76. * Convert this object to PDF code.
  77. * @return byte[] the PDF code
  78. */
  79. public byte[] toPDF() {
  80. return PDFDocument.encode(toPDFString());
  81. }
  82. /**
  83. * Convert this object to PDF code.
  84. * @return String the PDF code
  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.get(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]);
  96. p.append(" ");
  97. }
  98. } else {
  99. ((Entry)entry).fillInPDF(p);
  100. }
  101. }
  102. p.append("]");
  103. return p.toString();
  104. }
  105. /**
  106. * Inner class for entries in the form "c [w ...]"
  107. */
  108. private static class Entry {
  109. private int start;
  110. private int[] metrics;
  111. public Entry(int s, int[] m) {
  112. start = s;
  113. metrics = m;
  114. }
  115. public void fillInPDF(StringBuffer p) {
  116. // p.setLength(0);
  117. p.append(start);
  118. p.append(" [");
  119. for (int i = 0; i < metrics.length; i++) {
  120. p.append(this.metrics[i]);
  121. p.append(" ");
  122. }
  123. p.append("] ");
  124. }
  125. }
  126. }