Skip to content

Commit

Permalink
Simplify arabic code
Browse files Browse the repository at this point in the history
  • Loading branch information
Berenz committed Jul 29, 2018
1 parent 3cd3e7c commit 674ea5f
Show file tree
Hide file tree
Showing 6 changed files with 137 additions and 527 deletions.
87 changes: 87 additions & 0 deletions ant/lib/slim-icu.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# Download icu4j source code, build using ant,
# it will generate icu4j.jar and icu4j-charset.jar
# Run slim-icu.py to generate slim version
# Currently this script will only keep Arabic and English data

# slim ICU
import zipfile
from zipfile import ZipFile

mode = zipfile.ZIP_DEFLATED


def keep_file(filename):
# skip all break iterators
if filename.endswith(".brk") \
or filename.endswith(".dict") \
or filename.endswith("unames.icu") \
or filename.endswith("ucadata.icu") \
or filename.endswith(".spp"):
return False

# keep english and arabic
if filename.startswith("en") \
or filename.startswith("ar") \
or not filename.endswith(".res"):
return True

return False


zin = ZipFile('icu4j.jar', 'r')
zout = ZipFile('icu4j-slim.jar', 'w', mode)

for item in zin.infolist():
buff = zin.read(item.filename)
print(item.filename)

if keep_file(item.filename):
print("Keep")
zout.writestr(item, buff)
else:
print("Remove")

zout.close()
zin.close()


def keep_charset_file(filename):
to_remove = [
"cns-11643-1992.cnv",
"ebcdic-xml-us.cnv",
"euc-jp-2007.cnv",
"euc-tw-2014.cnv",
"gb18030.cnv",
"ibm-1363_P11B-1998.cnv",
"ibm-1364_P110-2007.cnv",
"ibm-1371_P100-1999.cnv",
"ibm-1373_P100-2002.cnv",
"ibm-1375_P100-2008.cnv",
"ibm-1383_P110-1999.cnv",
"ibm-1386_P100-2001.cnv",
"ibm-1388_P103-2001.cnv",
"ibm-1390_P110-2003.cnv"
]

for i in to_remove:
if i in filename:
return False

return True


zin = ZipFile('icu4j-charset.jar', 'r')
zout = ZipFile('icu4j-charset-slim.jar', 'w', mode)

for item in zin.infolist():
buff = zin.read(item.filename)
print(item.filename, end=' ')

if keep_charset_file(item.filename):
print("Keep")
zout.writestr(item, buff)
else:
print("Remove")

zout.close()
zin.close()
8 changes: 7 additions & 1 deletion build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
<java jar="${dist.jar}" fork="true" outputproperty="build.version">
<arg value="--version"/>
</java>

<!-- Fallback to a bogus version number if the above command failed -->
<property name="build.version" value="0.0.0" />
<echo>Version ${build.version}</echo>
Expand Down Expand Up @@ -170,6 +170,12 @@
</copy>
</target>

<target name="distill-icu">
<exec dir="ant/lib" executable="python">
<arg line="slim-icu.py"/>
</exec>
</target>

<!--
################################################################
# Prepackage Steps - All Platforms #
Expand Down
5 changes: 0 additions & 5 deletions script/README.txt

This file was deleted.

69 changes: 0 additions & 69 deletions script/slim-icu.py

This file was deleted.

13 changes: 4 additions & 9 deletions src/qz/printer/action/PrintRaw.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*/
package qz.printer.action;

import com.ibm.icu.text.ArabicShapingException;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.ssl.Base64;
import org.codehaus.jettison.json.JSONArray;
Expand Down Expand Up @@ -42,7 +43,6 @@
import java.util.List;
import java.util.Locale;
import java.util.concurrent.atomic.AtomicBoolean;
import com.ibm.icu.text.ArabicShapingException;

/**
* Sends raw data to the printer, overriding your operating system's print
Expand All @@ -56,7 +56,7 @@ public class PrintRaw implements PrintProcessor {

private ByteArrayBuilder commands;

String encoding = null;
private String encoding = null;


public PrintRaw() {
Expand All @@ -69,16 +69,11 @@ public PrintingUtilities.Type getType() {
}

private byte[] getBytes(String str, String encoding) throws ArabicShapingException, IOException {
String enc = encoding.toLowerCase();
switch (encoding.toLowerCase()) {
switch(encoding.toLowerCase()) {
case "ibm864":
case "cp864":
case "csibm864":
return ArabicConversionUtilities.convertUTF8ToIBM864MixedWithESCP(str);
case "raw/ibm864":
case "raw/cp864":
case "raw/csibm864":
return ArabicConversionUtilities.convertUTF8OrESCPToIBM864(str);
return ArabicConversionUtilities.convertToIBM864(str);
default:
return str.getBytes(encoding);
}
Expand Down
Loading

0 comments on commit 674ea5f

Please sign in to comment.