All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jpedal.fonts.EncodingEUCJP Maven / Gradle / Ivy

There is a newer version: 7.15.25
Show newest version
/*
 * ===========================================
 * Java Pdf Extraction Decoding Access Library
 * ===========================================
 *
 * Project Info:  http://www.idrsolutions.com
 * Help section for developers at http://www.idrsolutions.com/support/
 *
 * (C) Copyright 1997-2017 IDRsolutions and Contributors.
 *
 * This file is part of JPedal/JPDF2HTML5
 *
 @LICENSE@
 *
 * ---------------
 * EncodingEUCJP.java
 * ---------------
 */
package org.jpedal.fonts;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import org.jpedal.utils.LogWriter;

public class EncodingEUCJP implements CmapEncoding {

	private final int[] uniMap = new int[65536];

	public EncodingEUCJP() {
		final ClassLoader loader = this.getClass().getClassLoader();
		String line;
		int gbkVal, unicodeVal;
		String xx, yy;
		final BufferedReader input_stream;

		try {
			input_stream = new BufferedReader(
					new InputStreamReader(loader.getResourceAsStream("org/jpedal/res/pdf/EUCJPtoUNI.cfg")));
			while (true) {
				line = input_stream.readLine();
				if (line == null) {
					break;
				}
				if (line.startsWith("0x")) {
					final StringTokenizer values = new StringTokenizer(line);
					xx = values.nextToken().substring(2);
					yy = values.nextToken().substring(2);

					unicodeVal = Integer.parseInt(yy, 16);
					gbkVal = Integer.parseInt(xx, 16);
					uniMap[gbkVal] = unicodeVal;

				}
			}
			input_stream.close();
		} catch (final Exception e) {
			LogWriter.writeLog("Exception: " + e.getMessage());
		}
	}

	@Override
	public int getUnicodeValue(final int cid) {
		if (cid >= 0 && cid <= 0x7f) {
			return cid;
		}
		return uniMap[cid];
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy