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.

PSTTFGlyphOutputStream.java 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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.render.ps.fonts;
  19. import java.io.IOException;
  20. import org.apache.fop.fonts.truetype.TTFGlyphOutputStream;
  21. /**
  22. * Streams glyphs in accordance with the constraints of the PostScript file format.
  23. * Mainly, PostScript strings have a limited capacity and the font data may have to be
  24. * broken down into several strings; however, this must occur at well-defined places like
  25. * table or glyph boundaries. See also Adobe Technical Note #5012, <em>The Type 42 Font
  26. * Format Specification</em>.
  27. */
  28. public class PSTTFGlyphOutputStream implements TTFGlyphOutputStream {
  29. /** Total number of bytes written so far. */
  30. private int byteCounter;
  31. private int lastStringBoundary;
  32. private PSTTFGenerator ttfGen;
  33. /**
  34. * Constructor
  35. * @param ttfGen PSTTFGenerator
  36. */
  37. public PSTTFGlyphOutputStream(PSTTFGenerator ttfGen) {
  38. this.ttfGen = ttfGen;
  39. }
  40. public void startGlyphStream() throws IOException {
  41. ttfGen.startString();
  42. }
  43. public void streamGlyph(byte[] glyphData, int offset, int size) throws IOException {
  44. if (size > PSTTFGenerator.MAX_BUFFER_SIZE) {
  45. throw new UnsupportedOperationException("The glyph is " + size
  46. + " bytes. There may be an error in the font file.");
  47. }
  48. if (size + (byteCounter - lastStringBoundary) < PSTTFGenerator.MAX_BUFFER_SIZE) {
  49. ttfGen.streamBytes(glyphData, offset, size);
  50. } else {
  51. ttfGen.endString();
  52. lastStringBoundary = byteCounter;
  53. ttfGen.startString();
  54. ttfGen.streamBytes(glyphData, offset, size);
  55. }
  56. byteCounter += size;
  57. }
  58. public void endGlyphStream() throws IOException {
  59. ttfGen.endString();
  60. }
  61. }