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.

PDFFontNonBase14.java 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 org.apache.fop.fonts.FontType;
  20. /**
  21. * A common ancestor for Type1, TrueType, MMType1 and Type3 fonts
  22. * (all except base 14 fonts).
  23. */
  24. public abstract class PDFFontNonBase14 extends PDFFont {
  25. /**
  26. * Create the /Font object
  27. *
  28. * @param fontname the internal name for the font
  29. * @param subtype the font's subtype
  30. * @param basefont the base font name
  31. * @param encoding the character encoding schema used by the font
  32. */
  33. public PDFFontNonBase14(String fontname, FontType subtype,
  34. String basefont,
  35. Object encoding) {
  36. /* generic creation of PDF object */
  37. super(fontname, subtype, basefont, encoding);
  38. }
  39. /**
  40. * Set the width metrics for the font
  41. *
  42. * @param firstChar the first character code in the font
  43. * @param lastChar the last character code in the font
  44. * @param widths an array of size (lastChar - firstChar +1)
  45. */
  46. public void setWidthMetrics(int firstChar, int lastChar,
  47. PDFArray widths) {
  48. put("FirstChar", Integer.valueOf(firstChar));
  49. put("LastChar", Integer.valueOf(lastChar));
  50. put("Widths", widths);
  51. }
  52. /**
  53. * Set the font descriptor (unused for the Type3 fonts)
  54. *
  55. * @param descriptor the descriptor for other font's metrics
  56. */
  57. public void setDescriptor(PDFFontDescriptor descriptor) {
  58. put("FontDescriptor", descriptor);
  59. }
  60. /** @return the FontDescriptor or null if there is none */
  61. public PDFFontDescriptor getDescriptor() {
  62. return (PDFFontDescriptor)get("FontDescriptor");
  63. }
  64. /** {@inheritDoc} */
  65. protected void validate() {
  66. if (getDocumentSafely().getProfile().isFontEmbeddingRequired()) {
  67. if (this.getDescriptor().getFontFile() == null) {
  68. throw new PDFConformanceException("For " + getDocumentSafely().getProfile()
  69. + ", all fonts have to be embedded! Offending font: " + getBaseFont());
  70. }
  71. }
  72. }
  73. }