switch two glyphs

31 views
Skip to first unread message

ale.be...@gmail.com

unread,
Apr 12, 2015, 5:47:16 PM4/12/15
to sfntly...@googlegroups.com
Hi all,

in the last week I've done some experiments with the SFNTLY library, but without having success ;)

I'm trying to switch two glyphs: let's say that I would like the glyph for the X char looks like an Y, and on the other hand that the Y looks like an X.


What I've done till now is:

Font.Builder fontBuilder = fontFactory.loadFontsForBuilding(new FileInputStream("myfont.ttf"))[0];
LocaTable.Builder locaTableBuilder = (LocaTable.Builder) fontBuilder.getTableBuilder(Tag.loca);
GlyphTable.Builder glyphTableBuilder = (GlyphTable.Builder) fontBuilder.getTableBuilder(Tag.glyf);

String x = "X";
String y = "Y";

int xI = new String(x).codePointAt(0); // 88
int yI = new String(y).codePointAt(0); // 89

ReadableFontData gRFD = glyphTableBuilder.data();
WritableFontData gWFD = WritableFontData.createWritableFontData(gRFD);

List<Integer> newLocaList = new ArrayList<Integer>();
int currOffset = 0;
for (int i = 0; i < locaTableBuilder.numGlyphs(); i++) {
newLocaList.add(currOffset);
int j = i;
if (i == xI) {
j = yI;
} else if (i == yI) {
j = xI;
}
int glyphLength = locaTableBuilder.glyphLength(j);
currOffset += glyphLength;
byte[] tmpBs = new byte[glyphLength];
gRFD.readBytes(j, tmpBs, 0, glyphLength);
gWFD.writeBytes(i, tmpBs);
}

locaTableBuilder.setLocaList(newLocaList);
glyphTableBuilder.setLoca(newLocaList);
fontBuilder.getTableBuilder(Tag.glyf).setData(gWFD);
fontBuilder.getTableBuilder(Tag.loca).setData(locaTableBuilder.data());

Font font = fontBuilder.build();

I'm sure to miss something ;)

Is there anybody can give me some hints on how to solve this issue?

Thanks,
AB




Reply all
Reply to author
Forward
0 new messages