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.

PDFCFFStreamType0C.java 2.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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.pdf;
  19. import java.io.IOException;
  20. import java.io.OutputStream;
  21. import org.apache.fop.fonts.CustomFont;
  22. import org.apache.fop.fonts.EmbeddingMode;
  23. import org.apache.fop.fonts.FontType;
  24. /**
  25. * PDFStream for embeddable OpenType CFF fonts.
  26. */
  27. public class PDFCFFStreamType0C extends AbstractPDFFontStream {
  28. private byte[] cffData;
  29. private String type;
  30. /**
  31. * Main constructor
  32. */
  33. public PDFCFFStreamType0C(CustomFont font) {
  34. super();
  35. if (font.getEmbeddingMode() == EmbeddingMode.FULL) {
  36. type = "OpenType";
  37. } else if (font.getFontType() == FontType.TYPE0) {
  38. type = "CIDFontType0C";
  39. } else {
  40. type = font.getFontType().getName();
  41. }
  42. }
  43. protected int getSizeHint() throws IOException {
  44. if (this.cffData != null) {
  45. return cffData.length;
  46. } else {
  47. return 0; //no hint available
  48. }
  49. }
  50. /** {@inheritDoc} */
  51. protected void outputRawStreamData(OutputStream out) throws IOException {
  52. out.write(this.cffData);
  53. }
  54. /** {@inheritDoc} */
  55. protected void populateStreamDict(Object lengthEntry) {
  56. put("Subtype", new PDFName(type));
  57. super.populateStreamDict(lengthEntry);
  58. }
  59. /**
  60. * Sets the CFF font data.
  61. * @param data the font payload
  62. * @param size size of the payload
  63. * @throws IOException in case of an I/O problem
  64. */
  65. public void setData(byte[] data, int size) throws IOException {
  66. this.cffData = new byte[size];
  67. System.arraycopy(data, 0, this.cffData, 0, size);
  68. }
  69. }