Skip to content

Commit

Permalink
Merge pull request #722 from bstell/master
Browse files Browse the repository at this point in the history
Get the glyph id and build the cmap mapping.
  • Loading branch information
bstell committed Jun 23, 2015
2 parents 637f670 + 844b493 commit 80f2986
Showing 1 changed file with 31 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,52 @@
import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.zip.GZIPOutputStream;

import javax.servlet.http.*;

@SuppressWarnings("serial")
public class GetCharData extends HttpServlet {
@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
resp.setContentType("text/plain");
// Get the codepoints.
String jarFilename = "fonts/noto/sans/NotoSansJP-Thin_subset_smp.TachyFont.jar";
JarFile jarFile = new JarFile("WEB-INF/" + jarFilename);
Map<Integer, Integer> cmapMap = getCmapMap(jarFile);
Iterator<Entry<Integer, Integer>> cmapIterator = cmapMap.entrySet().iterator();
while (cmapIterator.hasNext()) {
Entry<Integer, Integer> pair = cmapIterator.next();
resp.getWriter().println(pair.getKey() + " = " + pair.getValue());
}

// TODO(bstell): look in the closure file for other gids to include.
for (Integer value : cmapMap.values()) {
System.out.println("look for the closure of gid = " + value);
}
// TODO(bstell): create and return the glyph bundle.
jarFile.close();
}
private HashMap<Integer, Integer> getCmapMap(JarFile jarFile) throws IOException {
JarEntry codePointsJarEntry = jarFile.getJarEntry("codepoints");
InputStream codePointsStream = jarFile.getInputStream(codePointsJarEntry);
DataInputStream codePointsDataStream = new DataInputStream(codePointsStream);
List<Integer> codePoints = new ArrayList<Integer>();
Integer codePoint;
while ((codePoint = codePointsDataStream.readInt()) != null) {
// TODO(bstell): get the gids and make a codepoint->gid map
System.out.println(codePoint);

JarEntry gidsJarEntry = jarFile.getJarEntry("gids");
InputStream gidsStream = jarFile.getInputStream(gidsJarEntry);
DataInputStream gidsDataStream = new DataInputStream(gidsStream);

HashMap<Integer, Integer> cmapMap = new HashMap<Integer, Integer>();
while (codePointsDataStream.available() > 0) {
Integer codePoint = codePointsDataStream.readInt();
Integer gid = gidsDataStream.readUnsignedShort();
cmapMap.put(codePoint, gid);
}
// TODO(bstell): look in the closure file for other gids to include.
// TODO(bstell): create and return the glyph bundle.
jarFile.close();
return cmapMap;
}
}

0 comments on commit 80f2986

Please sign in to comment.