2
* ===========================================
3
* LibFonts : a free Java font reading library
4
* ===========================================
6
* Project Info: http://reporting.pentaho.org/libfonts/
8
* (C) Copyright 2006-2007, by Pentaho Corporation and Contributors.
10
* This library is free software; you can redistribute it and/or modify it under the terms
11
* of the GNU Lesser General Public License as published by the Free Software Foundation;
12
* either version 2.1 of the License, or (at your option) any later version.
14
* This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
15
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
* See the GNU Lesser General Public License for more details.
18
* You should have received a copy of the GNU Lesser General Public License along with this
19
* library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20
* Boston, MA 02111-1307, USA.
22
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
23
* in the United States and other countries.]
26
* $Id: Iso8859_1.java 3523 2007-10-16 11:03:09Z tmorgner $
28
* (C) Copyright 2006-2007, by Pentaho Corporation.
30
package org.jfree.fonts.encoding.manual;
32
import java.util.Locale;
34
import org.jfree.fonts.encoding.ByteBuffer;
35
import org.jfree.fonts.encoding.CodePointBuffer;
36
import org.jfree.fonts.encoding.Encoding;
37
import org.jfree.fonts.encoding.EncodingErrorType;
38
import org.jfree.fonts.encoding.EncodingException;
41
* This is a lucky case, as ISO-8859-1 can be transformed directly. There is no
44
* @author Thomas Morgner
46
public final class Iso8859_1 implements Encoding
52
public String getName()
57
public String getName(final Locale locale)
62
public boolean isUnicodeCharacterSupported(final int c)
64
return (c & 0xFFFFFF00) == 0;
68
* Encode, but ignore errors.
74
public ByteBuffer encode(final CodePointBuffer text, ByteBuffer buffer)
76
final int textLength = text.getLength();
79
buffer = new ByteBuffer(textLength);
81
else if (buffer.getLength() < textLength)
83
buffer.ensureSize(textLength);
86
final byte[] targetArray = buffer.getData();
87
final int[] sourceArray = text.getData();
89
int targetIdx = buffer.getOffset();
90
final int endPos = text.getCursor();
91
for (int i = text.getOffset(); i < endPos; i++)
93
final int sourceItem = sourceArray[i];
94
if (isUnicodeCharacterSupported(sourceItem))
96
targetArray[targetIdx] = (byte) (sourceItem & 0xff);
101
buffer.setCursor(targetIdx);
105
public CodePointBuffer decode(final ByteBuffer text, CodePointBuffer buffer)
107
final int textLength = text.getLength();
110
buffer = new CodePointBuffer(textLength);
112
else if (buffer.getLength() < textLength)
114
buffer.ensureSize(textLength);
117
final int[] targetArray = buffer.getData();
118
final byte[] sourceArray = text.getData();
120
int targetIdx = buffer.getOffset();
121
final int endPos = text.getCursor();
122
for (int i = text.getOffset(); i < endPos; i++)
124
targetArray[targetIdx] = (sourceArray[i] & 0xff);
128
buffer.setCursor(targetIdx);
132
public ByteBuffer encode(final CodePointBuffer text,
134
final EncodingErrorType errorHandling)
135
throws EncodingException
137
final int textLength = text.getLength();
140
buffer = new ByteBuffer(textLength);
142
else if (buffer.getLength() < textLength)
144
buffer.ensureSize(textLength);
147
final byte[] targetArray = buffer.getData();
148
final int[] sourceArray = text.getData();
150
int targetIdx = buffer.getOffset();
151
final int endPos = text.getCursor();
152
for (int i = text.getOffset(); i < endPos; i++)
154
final int sourceItem = sourceArray[i];
155
if (isUnicodeCharacterSupported(sourceItem))
157
targetArray[targetIdx] = (byte) (sourceItem & 0xff);
162
if (errorHandling == EncodingErrorType.REPLACE)
164
targetArray[targetIdx] = (byte) ('?' & 0xff);
167
else if (errorHandling == EncodingErrorType.FAIL)
169
throw new EncodingException();
174
buffer.setCursor(targetIdx);
178
public CodePointBuffer decode(final ByteBuffer text,
179
CodePointBuffer buffer,
180
final EncodingErrorType errorHandling)
181
throws EncodingException
183
final int textLength = text.getLength();
186
buffer = new CodePointBuffer(textLength);
188
else if (buffer.getLength() < textLength)
190
buffer.ensureSize(textLength);
193
final int[] targetArray = buffer.getData();
194
final byte[] sourceArray = text.getData();
196
int targetIdx = buffer.getOffset();
197
final int endPos = text.getCursor();
198
for (int i = text.getOffset(); i < endPos; i++)
200
targetArray[targetIdx] = (sourceArray[i] & 0xff);
204
buffer.setCursor(targetIdx);