Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

SingleByteFont.java 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. * Copyright 1999-2004 The Apache Software Foundation.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /* $Id$ */
  17. package org.apache.fop.fonts;
  18. /**
  19. * Generic SingleByte font
  20. */
  21. public class SingleByteFont extends CustomFont {
  22. private final CodePointMapping mapping
  23. = CodePointMapping.getMapping("WinAnsiEncoding");
  24. private String encoding = "WinAnsiEncoding";
  25. private int width[] = null;
  26. /**
  27. * @see org.apache.fop.fonts.FontDescriptor#isEmbeddable()
  28. */
  29. public boolean isEmbeddable() {
  30. return (getEmbedFileName() == null && getEmbedResourceName() == null) ? false
  31. : true;
  32. }
  33. /**
  34. * @see org.apache.fop.fonts.Typeface#getEncoding()
  35. */
  36. public String getEncoding() {
  37. return encoding;
  38. }
  39. /**
  40. * @see org.apache.fop.fonts.FontMetrics#getWidth(int, int)
  41. */
  42. public int getWidth(int i, int size) {
  43. return size * width[i];
  44. }
  45. /**
  46. * @see org.apache.fop.fonts.FontMetrics#getWidths()
  47. */
  48. public int[] getWidths() {
  49. int[] arr = new int[width.length];
  50. System.arraycopy(width, 0, arr, 0, width.length - 1);
  51. /*
  52. for (int i = 0; i < arr.length; i++)
  53. arr[i] *= size;
  54. */
  55. return arr;
  56. }
  57. /**
  58. * @see org.apache.fop.fonts.Font#mapChar(char)
  59. */
  60. public char mapChar(char c) {
  61. char d = mapping.mapChar(c);
  62. if (d != 0) {
  63. return d;
  64. } else {
  65. return '#';
  66. }
  67. }
  68. /* ---- single byte font specific setters --- */
  69. /**
  70. * Sets a width for a character.
  71. * @param index index of the character
  72. * @param width the width of the character
  73. */
  74. public void setWidth(int index, int width) {
  75. if (this.width == null) {
  76. this.width = new int[256];
  77. }
  78. this.width[index] = width;
  79. }
  80. }