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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. * This class streams glyphs from the "glyf" table in a True Type font.
  23. */
  24. public class PSTTFGlyphOutputStream implements TTFGlyphOutputStream {
  25. /** This counts the total number of bytes written that have been streamed. */
  26. private int byteCounter = 0;
  27. /** This is a place-holder for the offset of the last string boundary. */
  28. private int lastStringBoundary = 0;
  29. private PSTTFGenerator ttfGen;
  30. /**
  31. * Constructor
  32. * @param ttfGen PSTTFGenerator
  33. */
  34. public PSTTFGlyphOutputStream(PSTTFGenerator ttfGen) {
  35. this.ttfGen = ttfGen;
  36. }
  37. /** {@inheritDoc} */
  38. public void startGlyphStream() throws IOException {
  39. ttfGen.startString();
  40. }
  41. /** {@inheritDoc} */
  42. public void streamGlyph(byte[] byteArray, int offset, int length) throws IOException {
  43. if (length > PSTTFGenerator.MAX_BUFFER_SIZE) {
  44. throw new UnsupportedOperationException("The glyph is " + length + " there may be an "
  45. + "error in the font file.");
  46. }
  47. if (length + (byteCounter - lastStringBoundary) < PSTTFGenerator.MAX_BUFFER_SIZE) {
  48. ttfGen.streamBytes(byteArray, offset, length);
  49. } else {
  50. ttfGen.endString();
  51. lastStringBoundary = byteCounter;
  52. ttfGen.startString();
  53. ttfGen.streamBytes(byteArray, offset, length);
  54. }
  55. byteCounter += length;
  56. }
  57. /** {@inheritDoc} */
  58. public void endGlyphStream() throws IOException {
  59. ttfGen.endString();
  60. }
  61. }