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.

CIDFull.java 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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.fonts;
  19. import java.util.BitSet;
  20. import java.util.Collections;
  21. import java.util.HashMap;
  22. import java.util.Map;
  23. import org.apache.fop.util.CharUtilities;
  24. /**
  25. * Provides methods to get font information.
  26. * Naming:
  27. * glyph index: original index of the glyph in the non-subset font (!= unicode index)
  28. * character selector: index into a set of glyphs. For subset CID fonts, this starts at 0. For non-subset
  29. * fonts, this is the same as the glyph index.
  30. * Unicode index: The Unicode codepoint of a character.
  31. * Glyph name: the Adobe glyph name (as found in Glyphs.java)
  32. */
  33. public class CIDFull implements CIDSet {
  34. private BitSet glyphIndices;
  35. private final MultiByteFont font;
  36. public CIDFull(MultiByteFont mbf) {
  37. font = mbf;
  38. }
  39. private void initGlyphIndices() {
  40. // this cannot be called in the constructor since the font is not ready...
  41. if (glyphIndices == null) {
  42. glyphIndices = font.getGlyphIndices();
  43. }
  44. }
  45. /** {@inheritDoc} */
  46. public int getOriginalGlyphIndex(int index) {
  47. return index;
  48. }
  49. /** {@inheritDoc} */
  50. @Override
  51. public char getUnicodeFromGID(int glyphIndex) {
  52. return ' ';
  53. }
  54. /** {@inheritDoc} */
  55. @Override
  56. public int getGIDFromChar(char ch) {
  57. return ch;
  58. }
  59. /** {@inheritDoc} */
  60. public int getUnicode(int index) {
  61. initGlyphIndices();
  62. if (glyphIndices.get(index)) {
  63. return index;
  64. } else {
  65. return CharUtilities.NOT_A_CHARACTER;
  66. }
  67. }
  68. /** {@inheritDoc} */
  69. public int mapChar(int glyphIndex, char unicode) {
  70. return glyphIndex;
  71. }
  72. /** {@inheritDoc} */
  73. public int mapCodePoint(int glyphIndex, int codePoint) {
  74. return glyphIndex;
  75. }
  76. /** {@inheritDoc} */
  77. public Map<Integer, Integer> getGlyphs() {
  78. // this is never really called for full embedded fonts but the equivalent map would be the identity
  79. initGlyphIndices();
  80. Map<Integer, Integer> glyphs = new HashMap<Integer, Integer>();
  81. int nextBitSet = 0;
  82. for (int j = 0; j < glyphIndices.cardinality(); j++) {
  83. nextBitSet = glyphIndices.nextSetBit(nextBitSet);
  84. glyphs.put(nextBitSet, nextBitSet);
  85. nextBitSet++;
  86. }
  87. return Collections.unmodifiableMap(glyphs);
  88. }
  89. /** {@inheritDoc} */
  90. public char[] getChars() {
  91. return font.getChars();
  92. }
  93. /** {@inheritDoc} */
  94. public int getNumberOfGlyphs() {
  95. initGlyphIndices();
  96. // note: the real number of glyphs is given by the cardinality() method (not the length()) but since
  97. // we will pad gaps in the indices with zeros we really want the length() here. this method is only
  98. // called when embedding a font in PostScript and this will be the value of the CIDCount entry
  99. return glyphIndices.length();
  100. }
  101. /** {@inheritDoc} */
  102. public BitSet getGlyphIndices() {
  103. initGlyphIndices();
  104. return glyphIndices;
  105. }
  106. /** {@inheritDoc} */
  107. public int[] getWidths() {
  108. return font.getWidths();
  109. }
  110. }