org.jpedal.fonts.EncodingUCS2 Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of OpenViewerFX Show documentation
Show all versions of OpenViewerFX Show documentation
Open Source (LGPL) JavaFX PDF Viewer for NetBeans plugin
/*
* ===========================================
* 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@
*
* ---------------
* EncodingUCS2.java
* ---------------
*/
package org.jpedal.fonts;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import org.jpedal.utils.LogWriter;
public class EncodingUCS2 implements CmapEncoding {
private final int[] uniMap = new int[65536];
public EncodingUCS2(final String ucsName) {
final ClassLoader loader = this.getClass().getClassLoader();
String line;
final BufferedReader input_stream;
try {
if (ucsName.equals("Adobe-Japan1-UCS2")) {
input_stream = new BufferedReader(
new InputStreamReader(loader.getResourceAsStream("org/jpedal/res/pdf/ADOBE_JAPAN_UCS2.cfg")));
} else if (ucsName.equals("Adobe-GB1-UCS2")) {
input_stream = new BufferedReader(
new InputStreamReader(loader.getResourceAsStream("org/jpedal/res/pdf/ADOBE_GB_UCS2.cfg")));
} else if (ucsName.equals("Adobe-Korea1-UCS2")) {
input_stream = new BufferedReader(
new InputStreamReader(loader.getResourceAsStream("org/jpedal/res/pdf/ADOBE_KOREA_UCS2.cfg")));
} else if (ucsName.equals("Adobe-CNS1-UCS2")) {
input_stream = new BufferedReader(
new InputStreamReader(loader.getResourceAsStream("org/jpedal/res/pdf/ADOBE_CNS_UCS2.cfg")));
} else {
input_stream = new BufferedReader(
new InputStreamReader(loader.getResourceAsStream("org/jpedal/res/pdf/GBKtoUNI.cfg")));
}
String ss, ee, uu;
int si, ei, ui;
while (true) {
line = input_stream.readLine();
if (line == null) {
break;
}
if (!line.startsWith("#")) {
final StringTokenizer values = new StringTokenizer(line);
ss = values.nextToken();
ee = values.nextToken();
uu = values.nextToken();
si = Integer.parseInt(ss, 16);
ei = Integer.parseInt(ee, 16);
ui = Integer.parseInt(uu, 16);
int p = 0;
for (int i = si; i <= ei; i++) {
final long vv = ui + p;
if (vv >= 0 && vv < 65536) {
uniMap[i] = (int) vv;
}
p++;
}
}
}
input_stream.close();
} catch (final Exception e) {
LogWriter.writeLog("Exception: " + e.getMessage());
}
}
@Override
public int getUnicodeValue(final int cid) {
return uniMap[cid];
}
}