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.

PCLSoftFont.java 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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.pcl.fonts;
  19. import java.io.InputStream;
  20. import java.util.HashMap;
  21. import java.util.Map;
  22. import org.apache.fop.fonts.MultiByteFont;
  23. import org.apache.fop.fonts.Typeface;
  24. import org.apache.fop.fonts.truetype.FontFileReader;
  25. import org.apache.fop.fonts.truetype.OpenFont;
  26. import org.apache.fop.render.java2d.CustomFontMetricsMapper;
  27. public class PCLSoftFont {
  28. private int fontID;
  29. private Typeface font;
  30. private Map<Integer, int[]> charOffsets;
  31. private OpenFont openFont;
  32. private InputStream fontStream;
  33. private FontFileReader reader;
  34. /** Map containing unicode character and it's soft font codepoint **/
  35. private Map<Integer, Integer> charsWritten;
  36. private Map<Character, Integer> mappedChars;
  37. private Map<Integer, Integer> charMtxPositions;
  38. private boolean multiByteFont;
  39. private int charCount = 32;
  40. public PCLSoftFont(int fontID, Typeface font, boolean multiByteFont) {
  41. this.fontID = fontID;
  42. this.font = font;
  43. charsWritten = new HashMap<Integer, Integer>();
  44. mappedChars = new HashMap<Character, Integer>();
  45. this.multiByteFont = multiByteFont;
  46. }
  47. public Typeface getTypeface() {
  48. return font;
  49. }
  50. public int getFontID() {
  51. return fontID;
  52. }
  53. public void setCharacterOffsets(Map<Integer, int[]> charOffsets) {
  54. this.charOffsets = charOffsets;
  55. }
  56. public Map<Integer, int[]> getCharacterOffsets() {
  57. return charOffsets;
  58. }
  59. public OpenFont getOpenFont() {
  60. return openFont;
  61. }
  62. public void setOpenFont(OpenFont openFont) {
  63. this.openFont = openFont;
  64. }
  65. public InputStream getFontStream() {
  66. return fontStream;
  67. }
  68. public void setFontStream(InputStream fontStream) {
  69. this.fontStream = fontStream;
  70. }
  71. public FontFileReader getReader() {
  72. return reader;
  73. }
  74. public void setReader(FontFileReader reader) {
  75. this.reader = reader;
  76. }
  77. public void writeCharacter(int unicode) {
  78. charsWritten.put(unicode, charCount++);
  79. }
  80. public int getUnicodeCodePoint(int unicode) {
  81. if (charsWritten.containsKey(unicode)) {
  82. return charsWritten.get(unicode);
  83. } else {
  84. return -1;
  85. }
  86. }
  87. public boolean hasPreviouslyWritten(int unicode) {
  88. return charsWritten.containsKey(unicode);
  89. }
  90. public int getMtxCharIndex(int unicode) {
  91. if (charMtxPositions.get(unicode) != null) {
  92. return charMtxPositions.get(unicode);
  93. }
  94. return 0;
  95. }
  96. public int getCmapGlyphIndex(int unicode) {
  97. if (font instanceof CustomFontMetricsMapper) {
  98. CustomFontMetricsMapper customFont = (CustomFontMetricsMapper) font;
  99. Typeface realFont = customFont.getRealFont();
  100. if (realFont instanceof MultiByteFont) {
  101. MultiByteFont mbFont = (MultiByteFont) realFont;
  102. return mbFont.findGlyphIndex(unicode);
  103. }
  104. }
  105. return 0;
  106. }
  107. public void setMtxCharIndexes(Map<Integer, Integer> charMtxPositions) {
  108. this.charMtxPositions = charMtxPositions;
  109. }
  110. public int getCharCount() {
  111. return charCount;
  112. }
  113. public void setMappedChars(Map<Character, Integer> mappedChars) {
  114. this.mappedChars = mappedChars;
  115. }
  116. public Map<Character, Integer> getMappedChars() {
  117. return mappedChars;
  118. }
  119. public int getCharIndex(char ch) {
  120. if (mappedChars.containsKey(ch)) {
  121. return mappedChars.get(ch);
  122. } else {
  123. return -1;
  124. }
  125. }
  126. public int getCharCode(char ch) {
  127. if (multiByteFont) {
  128. return getCharIndex(ch);
  129. } else {
  130. return getUnicodeCodePoint(ch);
  131. }
  132. }
  133. }