diff --git a/lib/ttf.jar b/lib/ttf.jar index 9f4e7edcc..c3719aacf 100644 Binary files a/lib/ttf.jar and b/lib/ttf.jar differ diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/FontExporter.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/FontExporter.java index 7bc93147a..5be9e3e76 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/FontExporter.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/FontExporter.java @@ -153,7 +153,7 @@ public class FontExporter { if (ascent != -1) { f.setAscender(Math.round(ascent / divider)); } - + int descent = t.getDescent(); if (descent != -1) { f.setDescender(Math.round(descent / divider)); @@ -247,7 +247,7 @@ public class FontExporter { if (mode == FontExportMode.WOFF) { FontFactory fontFactory = FontFactory.getInstance(); - byte[] fontBytes = new byte[0]; + byte[] fontBytes; try (FileInputStream fis = new FileInputStream(ttfFile)) { fontBytes = new byte[(int) ttfFile.length()]; fis.read(fontBytes); diff --git a/libsrc/ttf/src/org/doubletype/ossa/truetype/CmapWriter.java b/libsrc/ttf/src/org/doubletype/ossa/truetype/CmapWriter.java index eb1640bf3..c752b193c 100644 --- a/libsrc/ttf/src/org/doubletype/ossa/truetype/CmapWriter.java +++ b/libsrc/ttf/src/org/doubletype/ossa/truetype/CmapWriter.java @@ -1,316 +1,315 @@ -/* - * $Id: CmapWriter.java,v 1.8 2004/01/27 00:35:08 eed3si9n Exp $ - * - * $Copyright: copyright (c) 2003, e.e d3si9n $ - * $License: - * This source code is part of DoubleType. - * DoubleType is a graphical typeface designer. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This Program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * In addition, as a special exception, e.e d3si9n gives permission to - * link the code of this program with any Java Platform that is available - * to public with free of charge, including but not limited to - * Sun Microsystem's JAVA(TM) 2 RUNTIME ENVIRONMENT (J2RE), - * and distribute linked combinations including the two. - * You must obey the GNU General Public License in all respects for all - * of the code used other than Java Platform. If you modify this file, - * you may extend this exception to your version of the file, but you are not - * obligated to do so. If you do not wish to do so, delete this exception - * statement from your version. - * $ - */ - -package org.doubletype.ossa.truetype; - -import java.io.*; -import java.util.*; - -/** - * @author e.e - */ -public class CmapWriter extends FontFormatWriter { - final long k_basicLatinStart = 0x20; - final long k_basicLatinEnd = 0x7e; - final long k_tableEnd = 0xffff; - final int k_unmappedChar = 0x0; - - private OS2Writer m_os2; - private List m_unicodes = new ArrayList<>(); - private List m_startCodes = new ArrayList<>(); - private List m_endCodes = new ArrayList<>(); - private Hashtable m_unicode2glyph = new Hashtable<>(); - private List m_unicodeRanges = new ArrayList<>(); - private List m_idDeltas = new ArrayList<>(); - private List m_idRangeOffsets = new ArrayList<>(); - private boolean m_isIncludeVersion0; - private byte [] m_version0; - private byte [] m_version4; - private byte [] m_version12; - - public CmapWriter(OS2Writer a_os2) { - super(); - - m_os2 = a_os2; - m_isIncludeVersion0 = false; - } - - @SuppressWarnings("unchecked") - private void prepare() { - Collections.sort(m_unicodeRanges); - - TTUnicodeRange range = (TTUnicodeRange) m_unicodeRanges.get(0); - m_os2.m_usFirstCharIndex = (int) range.getStartCode(); - m_os2.m_usLastCharIndex = (int) range.getEndCode(); - - int i; - for (i = 0; i < m_unicodeRanges.size(); i++) { - range = m_unicodeRanges.get(i); - - m_startCodes.add(range.getStartCode()); - m_endCodes.add(range.getEndCode()); - m_idDeltas.add(0L); - m_idRangeOffsets.add( - 2L * (m_unicodeRanges.size() - i) + 2L - + 2L * (m_unicodes.size())); - - m_os2.m_usLastCharIndex = (int) range.getEndCode(); - m_os2.setUnicodeRangeFlag(range.getOsTwoFlag()); - - for (long unicode = range.getStartCode(); - unicode <= range.getEndCode(); unicode++) - { - m_unicodes.add(unicode); - } // for unicode - } // for i - - m_startCodes.add(k_tableEnd); - m_endCodes.add(k_tableEnd); - m_idDeltas.add(1L); - m_idRangeOffsets.add(0L); - } - - public void write() throws IOException { - prepare(); - - if (m_isIncludeVersion0) { - storeVersion0(); - } // if - storeVersion4(); - - reset(); - - writeUInt16(0); // table version number - writeUInt16(getNumOfEncoding()); // num of encodings - - if (m_isIncludeVersion0) { - writeUInt16(TTName.k_macintosh); - writeUInt16(TTName.k_macRomanEncode); - writeUInt32(size() + 4 + 8); - } // if - - writeUInt16(TTName.k_microsoft); - writeUInt16(TTName.k_winUnicodeEncode); - int version4Offset = size() + 4; - if (m_isIncludeVersion0) { - version4Offset += m_version0.length; - } // if - writeUInt32(version4Offset); - - if (m_isIncludeVersion0) { - m_buffer.write(m_version0); - } // if - - m_buffer.write(m_version4); - pad(); - } - - private int getNumOfEncoding() { - if (m_isIncludeVersion0) { - return 2; - } // if - - return 1; - } - - public void addUnicodeRange(TTUnicodeRange a_range) { - m_unicodeRanges.add(a_range); - } - - public void addMapping(long a_unicode, long a_glyfIndex) { - m_unicode2glyph.put(a_unicode, a_glyfIndex); - } - - /** - * Find 'glyf' index for the given unicode. - * This method returns 0, if a_key was not found, which will be treated - * as unmapped character. - * @param a_key Long object with unicode value. - * @return 'glyf' index if a_key was found; 0 otherwise. - */ - public long getGlyfIndex(Long a_key) { - long retval = 0; - - if (m_unicode2glyph.containsKey(a_key)) { - retval = m_unicode2glyph.get(a_key); - } // if - - return retval; - } - - private void storeVersion0() throws IOException { - reset(); - writeVersion0(); - m_version0 = toByteArray(); - reset(); - } - - private void storeVersion4() throws IOException { - reset(); - writeVersion4(); - m_version4 = toByteArray(); - reset(); - } - - private void storeVersion12() throws IOException { - reset(); - writeVersion12(); - m_version12 = toByteArray(); - reset(); - } - - protected String getTag() { - return "cmap"; - } - - private void writeVersion0() throws IOException { - writeUInt16(0); - writeUInt16(262); - writeUInt16(0); - int i; - for (i = 0; i < 256; i++) { - if ((i == 0x000) || (i == 0x0008) || (i == 0x001D)) { - writeUInt8((int) getGlyfIndex(TTUnicodeRange.k_null)); // .null - } - else if ((i == 0x0009) || (i == 0x000d)) { - writeUInt8((int) getGlyfIndex(TTUnicodeRange.k_cr)); // CR - } - else { - writeUInt8((int) getGlyfIndex((long) i)); - } // if - } // for i - } - - private void writeVersion4() throws IOException { - int segCount = m_startCodes.size(); - int i; - - // endCount - for (i = 0; i < segCount; i++) { - Long n = (Long) m_endCodes.get(i); - writeUInt16(n.intValue()); - } // for i - - // reserverdPad - writeUInt16(0); - - // startCount - for (i = 0; i < segCount; i++) { - Long n = m_startCodes.get(i); - writeUInt16(n.intValue()); - } // for i - - // idDelta - for (i = 0; i < segCount; i++) { - Long n = m_idDeltas.get(i); - writeInt16(n.intValue()); - } // for i - - // idRangeOffset - for (i = 0; i < segCount; i++) { - Long n = m_idRangeOffsets.get(i); - writeInt16(n.intValue()); - } - - // glyphIdArray 2 bytes each - for (i = 0; i < m_unicodes.size(); i++) { - Long unicode = m_unicodes.get(i); - writeUInt16((int) getGlyfIndex(unicode)); - } // for i - - byte [] bytes = m_bytes.toByteArray(); - - reset(); - - writeUInt16(4); - writeUInt16(bytes.length + 14); - writeUInt16(0); - writeUInt16(segCount * 2); - - int searchRange = getSearchRange(segCount); - writeUInt16(searchRange); - writeUInt16(getEntrySelector(searchRange)); - writeUInt16(getRangeShift(segCount, searchRange)); - m_buffer.write(bytes); - } - - public void writeVersion12() throws IOException { - ArrayList startCharCode = new ArrayList<>(); - ArrayList endCharCode = new ArrayList<>(); - ArrayList startGlyphCode = new ArrayList<>(); - - // TODO: map to real one - startCharCode.add(k_basicLatinStart); - endCharCode.add(k_basicLatinEnd); - startGlyphCode.add(1L); - - long length = 16 + 12 * startCharCode.size(); - - writeFixed32(12.0); - writeUInt32(length); - writeUInt32(0); - writeUInt32(startCharCode.size()); - - int i; - for (i = 0; i < startCharCode.size(); i++) { - writeUInt32(startCharCode.get(i)); - writeUInt32(endCharCode.get(i)); - writeUInt32(startGlyphCode.get(i)); - } // for i - } - - /** - * Used for searchRange - * @param a_value - * @return - */ - private int getSearchRange(int a_value) { - int retval - = (int) Math.pow(2, Math.floor(Math.log(a_value) / Math.log(2))); - return 2 * retval; - } - - private int getEntrySelector(int a_searchRange) { - int retval - = (int) (Math.log(a_searchRange / 2) / Math.log(2)); - return retval; - } - - private int getRangeShift(int a_value, int a_searchRange) { - int retval - = 2 * a_value - a_searchRange; - return retval; - } -} +/* + * $Id: CmapWriter.java,v 1.8 2004/01/27 00:35:08 eed3si9n Exp $ + * + * $Copyright: copyright (c) 2003, e.e d3si9n $ + * $License: + * This source code is part of DoubleType. + * DoubleType is a graphical typeface designer. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This Program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * In addition, as a special exception, e.e d3si9n gives permission to + * link the code of this program with any Java Platform that is available + * to public with free of charge, including but not limited to + * Sun Microsystem's JAVA(TM) 2 RUNTIME ENVIRONMENT (J2RE), + * and distribute linked combinations including the two. + * You must obey the GNU General Public License in all respects for all + * of the code used other than Java Platform. If you modify this file, + * you may extend this exception to your version of the file, but you are not + * obligated to do so. If you do not wish to do so, delete this exception + * statement from your version. + * $ + */ + +package org.doubletype.ossa.truetype; + +import java.io.*; +import java.util.*; + +/** + * @author e.e + */ +public class CmapWriter extends FontFormatWriter { + final long k_basicLatinStart = 0x20; + final long k_basicLatinEnd = 0x7e; + final long k_tableEnd = 0xffff; + final int k_unmappedChar = 0x0; + + private OS2Writer m_os2; + private List m_unicodes = new ArrayList<>(); + private List m_startCodes = new ArrayList<>(); + private List m_endCodes = new ArrayList<>(); + private Hashtable m_unicode2glyph = new Hashtable<>(); + private List m_unicodeRanges = new ArrayList<>(); + private List m_idDeltas = new ArrayList<>(); + private List m_idRangeOffsets = new ArrayList<>(); + private boolean m_isIncludeVersion0; + private byte [] m_version0; + private byte [] m_version4; + private byte [] m_version12; + + public CmapWriter(OS2Writer a_os2) { + super(); + + m_os2 = a_os2; + m_isIncludeVersion0 = false; + } + + private void prepare() { + Collections.sort(m_unicodeRanges); + + TTUnicodeRange range = (TTUnicodeRange) m_unicodeRanges.get(0); + m_os2.m_usFirstCharIndex = (int) range.getStartCode(); + m_os2.m_usLastCharIndex = (int) range.getEndCode(); + + int i; + for (i = 0; i < m_unicodeRanges.size(); i++) { + range = m_unicodeRanges.get(i); + + m_startCodes.add(range.getStartCode()); + m_endCodes.add(range.getEndCode()); + m_idDeltas.add(0L); + m_idRangeOffsets.add( + 2L * (m_unicodeRanges.size() - i) + 2L + + 2L * (m_unicodes.size())); + + m_os2.m_usLastCharIndex = (int) range.getEndCode(); + m_os2.setUnicodeRangeFlag(range.getOsTwoFlag()); + + for (long unicode = range.getStartCode(); + unicode <= range.getEndCode(); unicode++) + { + m_unicodes.add(unicode); + } // for unicode + } // for i + + m_startCodes.add(k_tableEnd); + m_endCodes.add(k_tableEnd); + m_idDeltas.add(1L); + m_idRangeOffsets.add(0L); + } + + public void write() throws IOException { + prepare(); + + if (m_isIncludeVersion0) { + storeVersion0(); + } // if + storeVersion4(); + + reset(); + + writeUInt16(0); // table version number + writeUInt16(getNumOfEncoding()); // num of encodings + + if (m_isIncludeVersion0) { + writeUInt16(TTName.k_macintosh); + writeUInt16(TTName.k_macRomanEncode); + writeUInt32(size() + 4 + 8); + } // if + + writeUInt16(TTName.k_microsoft); + writeUInt16(TTName.k_winUnicodeEncode); + int version4Offset = size() + 4; + if (m_isIncludeVersion0) { + version4Offset += m_version0.length; + } // if + writeUInt32(version4Offset); + + if (m_isIncludeVersion0) { + m_buffer.write(m_version0); + } // if + + m_buffer.write(m_version4); + pad(); + } + + private int getNumOfEncoding() { + if (m_isIncludeVersion0) { + return 2; + } // if + + return 1; + } + + public void addUnicodeRange(TTUnicodeRange a_range) { + m_unicodeRanges.add(a_range); + } + + public void addMapping(long a_unicode, long a_glyfIndex) { + m_unicode2glyph.put(a_unicode, a_glyfIndex); + } + + /** + * Find 'glyf' index for the given unicode. + * This method returns 0, if a_key was not found, which will be treated + * as unmapped character. + * @param a_key Long object with unicode value. + * @return 'glyf' index if a_key was found; 0 otherwise. + */ + public long getGlyfIndex(Long a_key) { + long retval = 0; + + if (m_unicode2glyph.containsKey(a_key)) { + retval = m_unicode2glyph.get(a_key); + } // if + + return retval; + } + + private void storeVersion0() throws IOException { + reset(); + writeVersion0(); + m_version0 = toByteArray(); + reset(); + } + + private void storeVersion4() throws IOException { + reset(); + writeVersion4(); + m_version4 = toByteArray(); + reset(); + } + + private void storeVersion12() throws IOException { + reset(); + writeVersion12(); + m_version12 = toByteArray(); + reset(); + } + + protected String getTag() { + return "cmap"; + } + + private void writeVersion0() throws IOException { + writeUInt16(0); + writeUInt16(262); + writeUInt16(0); + int i; + for (i = 0; i < 256; i++) { + if ((i == 0x000) || (i == 0x0008) || (i == 0x001D)) { + writeUInt8((int) getGlyfIndex(TTUnicodeRange.k_null)); // .null + } + else if ((i == 0x0009) || (i == 0x000d)) { + writeUInt8((int) getGlyfIndex(TTUnicodeRange.k_cr)); // CR + } + else { + writeUInt8((int) getGlyfIndex((long) i)); + } // if + } // for i + } + + private void writeVersion4() throws IOException { + int segCount = m_startCodes.size(); + int i; + + // endCount + for (i = 0; i < segCount; i++) { + Long n = (Long) m_endCodes.get(i); + writeUInt16(n.intValue()); + } // for i + + // reserverdPad + writeUInt16(0); + + // startCount + for (i = 0; i < segCount; i++) { + Long n = m_startCodes.get(i); + writeUInt16(n.intValue()); + } // for i + + // idDelta + for (i = 0; i < segCount; i++) { + Long n = m_idDeltas.get(i); + writeInt16(n.intValue()); + } // for i + + // idRangeOffset + for (i = 0; i < segCount; i++) { + Long n = m_idRangeOffsets.get(i); + writeInt16(n.intValue()); + } + + // glyphIdArray 2 bytes each + for (i = 0; i < m_unicodes.size(); i++) { + Long unicode = m_unicodes.get(i); + writeUInt16((int) getGlyfIndex(unicode)); + } // for i + + byte [] bytes = m_bytes.toByteArray(); + + reset(); + + writeUInt16(4); + writeUInt16(bytes.length + 14); + writeUInt16(0); + writeUInt16(segCount * 2); + + int searchRange = getSearchRange(segCount); + writeUInt16(searchRange); + writeUInt16(getEntrySelector(searchRange)); + writeUInt16(getRangeShift(segCount, searchRange)); + m_buffer.write(bytes); + } + + public void writeVersion12() throws IOException { + ArrayList startCharCode = new ArrayList<>(); + ArrayList endCharCode = new ArrayList<>(); + ArrayList startGlyphCode = new ArrayList<>(); + + // TODO: map to real one + startCharCode.add(k_basicLatinStart); + endCharCode.add(k_basicLatinEnd); + startGlyphCode.add(1L); + + long length = 16 + 12 * startCharCode.size(); + + writeFixed32(12.0); + writeUInt32(length); + writeUInt32(0); + writeUInt32(startCharCode.size()); + + int i; + for (i = 0; i < startCharCode.size(); i++) { + writeUInt32(startCharCode.get(i)); + writeUInt32(endCharCode.get(i)); + writeUInt32(startGlyphCode.get(i)); + } // for i + } + + /** + * Used for searchRange + * @param a_value + * @return + */ + private int getSearchRange(int a_value) { + int retval + = (int) Math.pow(2, Math.floor(Math.log(a_value) / Math.log(2))); + return 2 * retval; + } + + private int getEntrySelector(int a_searchRange) { + int retval + = (int) (Math.log(a_searchRange / 2) / Math.log(2)); + return retval; + } + + private int getRangeShift(int a_value, int a_searchRange) { + int retval + = 2 * a_value - a_searchRange; + return retval; + } +} diff --git a/libsrc/ttf/src/org/doubletype/ossa/truetype/FontFileWriter.java b/libsrc/ttf/src/org/doubletype/ossa/truetype/FontFileWriter.java index 97ff35df3..78a4c2681 100644 --- a/libsrc/ttf/src/org/doubletype/ossa/truetype/FontFileWriter.java +++ b/libsrc/ttf/src/org/doubletype/ossa/truetype/FontFileWriter.java @@ -1,286 +1,286 @@ -/* - * $Id: FontFileWriter.java,v 1.15 2004/10/04 02:25:39 eed3si9n Exp $ - * - * $Copyright: copyright (c) 2003, e.e d3si9n $ - * $License: - * This source code is part of DoubleType. - * DoubleType is a graphical typeface designer. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This Program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * In addition, as a special exception, e.e d3si9n gives permission to - * link the code of this program with any Java Platform that is available - * to public with free of charge, including but not limited to - * Sun Microsystem's JAVA(TM) 2 RUNTIME ENVIRONMENT (J2RE), - * and distribute linked combinations including the two. - * You must obey the GNU General Public License in all respects for all - * of the code used other than Java Platform. If you modify this file, - * you may extend this exception to your version of the file, but you are not - * obligated to do so. If you do not wish to do so, delete this exception - * statement from your version. - * $ - */ - - -package org.doubletype.ossa.truetype; - -import java.io.*; -import java.util.*; - -/** - * @author e.e - */ -public class FontFileWriter extends FontFormatWriter { - private CmapWriter m_cmap; - private GlyfWriter m_glyf; - private LocaWriter m_loca; - private HeadWriter m_head; - private HdmxWriter m_hdmx; - private HheaWriter m_hhea; - private HmtxWriter m_hmtx; - private MaxpWriter m_maxp; - private NameWriter m_name; - private PostWriter m_post; - private OS2Writer m_os2; - - protected RandomAccessFile m_file; - private ArrayList m_tables = new ArrayList<>(); - - public FontFileWriter(RandomAccessFile a_file) { - super(); - - m_file = a_file; - - m_loca = new LocaWriter(); - m_maxp = new MaxpWriter(); - m_head = new HeadWriter(); - m_hdmx = new HdmxWriter(); - m_os2 = new OS2Writer(m_head); - m_cmap = new CmapWriter(m_os2); - - m_glyf = new GlyfWriter(m_loca, m_maxp, - m_head, m_hdmx); - - m_hhea = new HheaWriter(m_glyf, m_head); - m_hmtx = new HmtxWriter(m_glyf, m_hhea); - m_name = new NameWriter(); - m_post = new PostWriter(); - - // http://www.microsoft.com/typography/otspec/recom.htm - // head, hhea, maxp, OS/2, hmtx, LTSH, VDMX, hdmx, cmap, - // fpgm, prep, cvt, loca, glyf, kern, name, post, gasp, PCLT, DSIG - /* - m_tables.add(m_head); - m_tables.add(m_hhea); - m_tables.add(m_maxp); - m_tables.add(m_os2); - m_tables.add(m_hmtx); - m_tables.add(m_hdmx); - m_tables.add(m_cmap); - m_tables.add(m_loca); - m_tables.add(m_glyf); - m_tables.add(m_name); - m_tables.add(m_post); - */ - - // Verdana has head, hhea, maxp, OS/2, gasp, name, cmap, loca - // LTSH, VDMX, prep, fpgm, cvt, hmtx, hdmx, glyf, post, kern, edt0, DSIG - m_tables.add(m_head); - m_tables.add(m_hhea); - m_tables.add(m_maxp); - m_tables.add(m_os2); - m_tables.add(m_name); - m_tables.add(m_cmap); - m_tables.add(m_loca); - - m_tables.add(m_hmtx); - m_tables.add(m_hdmx); - m_tables.add(m_glyf); - m_tables.add(m_post); - } - - /** - * write TrueType file to the random access file - */ - public void write() throws IOException { - m_cmap.write(); - // hmtx must be written before hhea - m_hmtx.write(); - m_hhea.write(); - - m_glyf.write(); - m_loca.write(); - - m_head.setCheckSumAdjustment(0); - m_head.write(); - m_maxp.write(); // must be written after m_glyf - m_hdmx.write(); - m_name.write(); - m_post.write(); - m_os2.write(); - - writeTableDirectory(); - byte [] tableDir = toByteArray(); - for (FontFormatWriter table: m_tables) { - m_buffer.write(table.toByteArray()); - } // for table - - long checkSum = 0xb1b0afba - (0xffffffff & getCheckSum()); - m_head.setCheckSumAdjustment(checkSum); - m_head.reset(); - m_head.write(); - - reset(); - - m_buffer.write(tableDir); - for (FontFormatWriter table: m_tables) { - m_buffer.write(table.toByteArray()); - } // for table - - m_file.write(toByteArray()); - m_file.close(); - } - - public void setAscent(int a_value) { - m_os2.setTypoAscender(a_value); - m_os2.setCapHeight(a_value); - } - - public void setDescent(int a_value) { - m_os2.setTypoDescender(-a_value); - } - - public void setXHeight(int a_value) { - m_os2.setXHeight(a_value); - } - - public void setLineGap(int a_value) { - m_os2.setTypoLineGap(a_value); - m_hhea.setLineGap(a_value); - } - - public void setFontFamilyName(String a_name) { - m_name.m_familyName = a_name; - } - - public void setCopyrightYear(String a_year) { - m_name.m_year = a_year; - } - - public void setManufacturer(String a_manufacturer) { - m_name.m_manufacturer = a_manufacturer; - } - - public void setFontVersion(String a_version) { - m_name.m_version = a_version; - } - - public void addUnicodeRange(TTUnicodeRange a_range) { - m_cmap.addUnicodeRange(a_range); - } - - /** - * http://www.microsoft.com/typography/otspec/os2.htm - * @param a_codeRange position of the bit. For example, JIS will be 17. - */ - public void setCodeRangeFlag(int a_codeRange) { - m_os2.setCodePageRangeFlag(a_codeRange); - } - - /** - * adds glyph to the 'glyf' subtable. - * @param a_glyph the glyph to be added. - * @return 'glyf' index of the added glyph. - */ - public int addGlyph(TTGlyph a_glyph) { - return m_glyf.add(a_glyph); - } - - public TTGlyph getGlyph(int a_index) { - return m_glyf.getGlyph(a_index); - } - - /** - * adds character mapping to - * @param a_unicode unicode of the character - * @param a_glyfIndex 'glyf' index obtained from #addGlyph - */ - public void addCharacterMapping(long a_unicode, long a_glyfIndex) { - m_cmap.addMapping(a_unicode, a_glyfIndex); - } - - public long getCharacterMapping(long a_unicode) { - return m_cmap.getGlyfIndex(new Long(a_unicode)); - } - - /** - * writes table directory. - * @throws IOException - */ - private void writeTableDirectory() throws IOException { - int headerLength = m_tables.size() * 16 + 16; - int tableOffset = headerLength; - for (FontFormatWriter table: m_tables) { - table.setOffset(tableOffset); - tableOffset += table.size(); - } // for table - - @SuppressWarnings("unchecked") - ArrayList tables = (ArrayList) m_tables.clone(); - Collections.sort(tables, new Comparator() { - public int compare(FontFormatWriter a_lhs, FontFormatWriter a_rhs) { - return a_lhs.getTag().compareTo(a_rhs.getTag()); - } - - public boolean equals(Object a_value) { - return false; - } - }); - - writeFixed32(1.0); - - int numOfTables = tables.size(); - writeUInt16(numOfTables); - int searchRange = getSearchRange(numOfTables); - writeUInt16(searchRange); - int entrySelector = getEntrySelector(numOfTables); - writeUInt16(entrySelector); - writeUInt16(numOfTables * 16 - searchRange); - - for (FontFormatWriter table: tables) { - writeTag(table.getTag()); - writeUInt32(table.getCheckSum()); - writeUInt32(table.getOffset()); - writeUInt32(table.size()); - } // for - - // padding is always 4 zeros - for (int i = 0; i < 4; i++) { - writeUInt8(0); - } // for i - } - - private int getSearchRange(int a_value) { - int retval - = (int) (Math.pow(2, Math.floor(Math.log(a_value) / Math.log(2)))); - return 16 * retval; - } - - private int getEntrySelector(int a_value) { - int retval - = (int) Math.floor(Math.log(a_value) / Math.log(2)); - return retval; - } -} +/* + * $Id: FontFileWriter.java,v 1.15 2004/10/04 02:25:39 eed3si9n Exp $ + * + * $Copyright: copyright (c) 2003, e.e d3si9n $ + * $License: + * This source code is part of DoubleType. + * DoubleType is a graphical typeface designer. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This Program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * In addition, as a special exception, e.e d3si9n gives permission to + * link the code of this program with any Java Platform that is available + * to public with free of charge, including but not limited to + * Sun Microsystem's JAVA(TM) 2 RUNTIME ENVIRONMENT (J2RE), + * and distribute linked combinations including the two. + * You must obey the GNU General Public License in all respects for all + * of the code used other than Java Platform. If you modify this file, + * you may extend this exception to your version of the file, but you are not + * obligated to do so. If you do not wish to do so, delete this exception + * statement from your version. + * $ + */ + + +package org.doubletype.ossa.truetype; + +import java.io.*; +import java.util.*; + +/** + * @author e.e + */ +public class FontFileWriter extends FontFormatWriter { + private CmapWriter m_cmap; + private GlyfWriter m_glyf; + private LocaWriter m_loca; + private HeadWriter m_head; + private HdmxWriter m_hdmx; + private HheaWriter m_hhea; + private HmtxWriter m_hmtx; + private MaxpWriter m_maxp; + private NameWriter m_name; + private PostWriter m_post; + private OS2Writer m_os2; + + protected RandomAccessFile m_file; + private ArrayList m_tables = new ArrayList<>(); + + public FontFileWriter(RandomAccessFile a_file) { + super(); + + m_file = a_file; + + m_loca = new LocaWriter(); + m_maxp = new MaxpWriter(); + m_head = new HeadWriter(); + m_hdmx = new HdmxWriter(); + m_os2 = new OS2Writer(m_head); + m_cmap = new CmapWriter(m_os2); + + m_glyf = new GlyfWriter(m_loca, m_maxp, + m_head, m_hdmx); + + m_hhea = new HheaWriter(m_glyf, m_head); + m_hmtx = new HmtxWriter(m_glyf, m_hhea); + m_name = new NameWriter(); + m_post = new PostWriter(); + + // http://www.microsoft.com/typography/otspec/recom.htm + // head, hhea, maxp, OS/2, hmtx, LTSH, VDMX, hdmx, cmap, + // fpgm, prep, cvt, loca, glyf, kern, name, post, gasp, PCLT, DSIG + /* + m_tables.add(m_head); + m_tables.add(m_hhea); + m_tables.add(m_maxp); + m_tables.add(m_os2); + m_tables.add(m_hmtx); + m_tables.add(m_hdmx); + m_tables.add(m_cmap); + m_tables.add(m_loca); + m_tables.add(m_glyf); + m_tables.add(m_name); + m_tables.add(m_post); + */ + + // Verdana has head, hhea, maxp, OS/2, gasp, name, cmap, loca + // LTSH, VDMX, prep, fpgm, cvt, hmtx, hdmx, glyf, post, kern, edt0, DSIG + m_tables.add(m_head); + m_tables.add(m_hhea); + m_tables.add(m_maxp); + m_tables.add(m_os2); + m_tables.add(m_name); + m_tables.add(m_cmap); + m_tables.add(m_loca); + + m_tables.add(m_hmtx); + m_tables.add(m_hdmx); + m_tables.add(m_glyf); + m_tables.add(m_post); + } + + /** + * write TrueType file to the random access file + */ + public void write() throws IOException { + m_cmap.write(); + // hmtx must be written before hhea + m_hmtx.write(); + m_hhea.write(); + + m_glyf.write(); + m_loca.write(); + + m_head.setCheckSumAdjustment(0); + m_head.write(); + m_maxp.write(); // must be written after m_glyf + m_hdmx.write(); + m_name.write(); + m_post.write(); + m_os2.write(); + + writeTableDirectory(); + byte [] tableDir = toByteArray(); + for (FontFormatWriter table: m_tables) { + m_buffer.write(table.toByteArray()); + } // for table + + long checkSum = 0xb1b0afba - (0xffffffff & getCheckSum()); + m_head.setCheckSumAdjustment(checkSum); + m_head.reset(); + m_head.write(); + + reset(); + + m_buffer.write(tableDir); + for (FontFormatWriter table: m_tables) { + m_buffer.write(table.toByteArray()); + } // for table + + m_file.write(toByteArray()); + m_file.close(); + } + + public void setAscent(int a_value) { + m_os2.setTypoAscender(a_value); + m_os2.setCapHeight(a_value); + } + + public void setDescent(int a_value) { + m_os2.setTypoDescender(-a_value); + } + + public void setXHeight(int a_value) { + m_os2.setXHeight(a_value); + } + + public void setLineGap(int a_value) { + m_os2.setTypoLineGap(a_value); + m_hhea.setLineGap(a_value); + } + + public void setFontFamilyName(String a_name) { + m_name.m_familyName = a_name; + } + + public void setCopyrightYear(String a_year) { + m_name.m_year = a_year; + } + + public void setManufacturer(String a_manufacturer) { + m_name.m_manufacturer = a_manufacturer; + } + + public void setFontVersion(String a_version) { + m_name.m_version = a_version; + } + + public void addUnicodeRange(TTUnicodeRange a_range) { + m_cmap.addUnicodeRange(a_range); + } + + /** + * http://www.microsoft.com/typography/otspec/os2.htm + * @param a_codeRange position of the bit. For example, JIS will be 17. + */ + public void setCodeRangeFlag(int a_codeRange) { + m_os2.setCodePageRangeFlag(a_codeRange); + } + + /** + * adds glyph to the 'glyf' subtable. + * @param a_glyph the glyph to be added. + * @return 'glyf' index of the added glyph. + */ + public int addGlyph(TTGlyph a_glyph) { + return m_glyf.add(a_glyph); + } + + public TTGlyph getGlyph(int a_index) { + return m_glyf.getGlyph(a_index); + } + + /** + * adds character mapping to + * @param a_unicode unicode of the character + * @param a_glyfIndex 'glyf' index obtained from #addGlyph + */ + public void addCharacterMapping(long a_unicode, long a_glyfIndex) { + m_cmap.addMapping(a_unicode, a_glyfIndex); + } + + public long getCharacterMapping(long a_unicode) { + return m_cmap.getGlyfIndex(new Long(a_unicode)); + } + + /** + * writes table directory. + * @throws IOException + */ + private void writeTableDirectory() throws IOException { + int headerLength = m_tables.size() * 16 + 16; + int tableOffset = headerLength; + for (FontFormatWriter table: m_tables) { + table.setOffset(tableOffset); + tableOffset += table.size(); + } // for table + + @SuppressWarnings("unchecked") + ArrayList tables = (ArrayList) m_tables.clone(); + Collections.sort(tables, new Comparator() { + public int compare(FontFormatWriter a_lhs, FontFormatWriter a_rhs) { + return a_lhs.getTag().compareTo(a_rhs.getTag()); + } + + public boolean equals(Object a_value) { + return false; + } + }); + + writeFixed32(1.0); + + int numOfTables = tables.size(); + writeUInt16(numOfTables); + int searchRange = getSearchRange(numOfTables); + writeUInt16(searchRange); + int entrySelector = getEntrySelector(numOfTables); + writeUInt16(entrySelector); + writeUInt16(numOfTables * 16 - searchRange); + + for (FontFormatWriter table: tables) { + writeTag(table.getTag()); + writeUInt32(table.getCheckSum()); + writeUInt32(table.getOffset()); + writeUInt32(table.size()); + } // for + + // padding is always 4 zeros + for (int i = 0; i < 4; i++) { + writeUInt8(0); + } // for i + } + + private int getSearchRange(int a_value) { + int retval + = (int) (Math.pow(2, Math.floor(Math.log(a_value) / Math.log(2)))); + return 16 * retval; + } + + private int getEntrySelector(int a_value) { + int retval + = (int) Math.floor(Math.log(a_value) / Math.log(2)); + return retval; + } +} diff --git a/libsrc/ttf/src/org/doubletype/ossa/truetype/TTUnicodeRange.java b/libsrc/ttf/src/org/doubletype/ossa/truetype/TTUnicodeRange.java index c55084c16..0437f0f36 100644 --- a/libsrc/ttf/src/org/doubletype/ossa/truetype/TTUnicodeRange.java +++ b/libsrc/ttf/src/org/doubletype/ossa/truetype/TTUnicodeRange.java @@ -1,380 +1,380 @@ -/* - * $Id: TTUnicodeRange.java,v 1.1 2004/01/25 11:00:10 eed3si9n Exp $ - * - * $Copyright: copyright (c) 2003-2004, e.e d3si9n $ - * $License: - * This source code is part of DoubleType. - * DoubleType is a graphical typeface designer. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This Program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * In addition, as a special exception, e.e d3si9n gives permission to - * link the code of this program with any Java Platform that is available - * to public with free of charge, including but not limited to - * Sun Microsystem's JAVA(TM) 2 RUNTIME ENVIRONMENT (J2RE), - * and distribute linked combinations including the two. - * You must obey the GNU General Public License in all respects for all - * of the code used other than Java Platform. If you modify this file, - * you may extend this exception to your version of the file, but you are not - * obligated to do so. If you do not wish to do so, delete this exception - * statement from your version. - * $ - */ - -package org.doubletype.ossa.truetype; - -import java.util.*; - -import java.lang.Character.UnicodeBlock; - -/** - * @author e.e - */ -public class TTUnicodeRange implements Comparable { - public static final long k_notDef = 0x0001; - public static final long k_null = 0x0000; - public static final long k_cr = 0x000D; - public static final long k_space = 0x0020; - - static private boolean s_isInitialized = false; - static private ArrayList s_list = new ArrayList<>(); - static private TTUnicodeRange s_selected = null; - - static public TTUnicodeRange of(long a_unicode) { - initList(); - - TTUnicodeRange retval = null; - UnicodeBlock block = UnicodeBlock.of((int)a_unicode); - if (block == null) - return retval; - - int i; - for (i = 0; i < s_list.size(); i++) { - TTUnicodeRange range = s_list.get(i); - if (range.m_block.equals(block)) { - return range; - } // if - } // for i - - return retval; - } - - static public TTUnicodeRange getLastFound() { - return s_selected; - } - - static private void initList() { - if (s_isInitialized) - return; - - s_isInitialized = true; - - s_list.add(new TTUnicodeRange( - UnicodeBlock.BASIC_LATIN, 0x0020, 0x007F, 0, 63)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.LATIN_1_SUPPLEMENT, 0x0080, 0x00FF, 1, 0)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.LATIN_EXTENDED_A, 0x0100, 0x017f, 2)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.LATIN_EXTENDED_B, 0x0180, 0x024f, 3)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.IPA_EXTENSIONS, 0x0250, 0x02af, 4)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.SPACING_MODIFIER_LETTERS, 0x02B0, 0x02FF, 5)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.COMBINING_DIACRITICAL_MARKS, 0x0300, 0x036F, 6)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.GREEK, 0x0370, 0x03FF, 7, 3)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.CYRILLIC, 0x0400, 0x04FF, 9, 2)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.ARMENIAN, 0x0530, 0x058F, 10)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.HEBREW, 0x0590, 0x05FF, 11, 5)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.ARABIC, 0x0600, 0x06FF, 13, 6)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.SYRIAC, 0x0700, 0x074F, 71)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.THAANA, 0x0780, 0x07BF, 72)); - - s_list.add(new TTUnicodeRange( - UnicodeBlock.DEVANAGARI, 0x0900, 0x097F, 15)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.BENGALI, 0x0980, 0x09FF, 16)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.GURMUKHI, 0x0A00, 0x0A7F, 17)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.GUJARATI, 0x0A80, 0x0AFF, 18)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.ORIYA, 0x0B00, 0x0B7F, 19)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.TAMIL, 0x0B80, 0x0BFF, 20)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.TELUGU, 0x0C00, 0x0C7F, 21)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.KANNADA, 0x0C80, 0x0CFF, 22)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.MALAYALAM, 0x0D00, 0x0D7F, 23)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.SINHALA, 0x0D80, 0x0DFF, 73)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.THAI, 0x0E00, 0x0E7F, 24, 16)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.LAO, 0x0E80, 0x0EFF, 25)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.TIBETAN, 0x0F00, 0x0FFF, 70)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.MYANMAR, 0x1000, 0x109F, 74)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.GEORGIAN, 0x10A0, 0x10FF, 26)); - // TODO: wansung or johab? - s_list.add(new TTUnicodeRange( - UnicodeBlock.HANGUL_JAMO, 0x1100, 0x11FF, 28, 19)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.ETHIOPIC, 0x1200, 0x137F, 75)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.CHEROKEE, 0x13A0, 0x13FF, 76)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.UNIFIED_CANADIAN_ABORIGINAL_SYLLABICS, 0x1400, 0x167F, 77)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.OGHAM, 0x1680, 0x169F, 78)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.RUNIC, 0x16A0, 0x16FF, 79)); - - // TODO: tagalog, hanunoo, buhid, tagbanwa - - s_list.add(new TTUnicodeRange( - UnicodeBlock.KHMER, 0x1780, 0x17FF, 80)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.MONGOLIAN, 0x1800, 0x18AF, 81)); - - // linbu, tai le, khmer symbol, phonetic extensions, - - s_list.add(new TTUnicodeRange( - UnicodeBlock.LATIN_EXTENDED_ADDITIONAL, 0x1E00, 0x1EFF, 29)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.GREEK_EXTENDED, 0x1F00, 0x1FFF, 30)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.GENERAL_PUNCTUATION, 0x2000, 0x206F, 31)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.SUPERSCRIPTS_AND_SUBSCRIPTS, 0x2070, 0x209F, 32)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.CURRENCY_SYMBOLS, 0x20A0, 0x20CF, 33)); - - // combining diacritical marks - s_list.add(new TTUnicodeRange( - UnicodeBlock.COMBINING_MARKS_FOR_SYMBOLS, 0x20D0, 0x20FF, 34)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.LETTERLIKE_SYMBOLS, 0x2100, 0x214F, 35)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.NUMBER_FORMS, 0x2150, 0x218F, 36)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.ARROWS, 0x2190, 0x21FF, 37)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.MATHEMATICAL_OPERATORS, 0x2200, 0x22FF, 38)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.MISCELLANEOUS_TECHNICAL, 0x2300, 0x23FF, 39)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.CONTROL_PICTURES, 0x2400, 0x243F, 40)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.OPTICAL_CHARACTER_RECOGNITION, 0x2440, 0x245F, 41)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.ENCLOSED_ALPHANUMERICS, 0x2460, 0x24FF, 42)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.BOX_DRAWING, 0x2500, 0x257F, 43)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.BLOCK_ELEMENTS, 0x2580, 0x259F, 44)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.GEOMETRIC_SHAPES, 0x25A0, 0x25FF, 45)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.MISCELLANEOUS_SYMBOLS, 0x2600, 0x26FF, 46)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.DINGBATS, 0x2700, 0x27BF, 47)); - - // TODO: mics. math symbols A, supplemental arrows A - - s_list.add(new TTUnicodeRange( - UnicodeBlock.BRAILLE_PATTERNS, 0x2800, 0x28FF, 82)); - - // TODO: supplemental arrows B, mics. math symbols B, - // supplemental math op., mics. symbols and arrows - - -// CJKV supplements - s_list.add(new TTUnicodeRange( - UnicodeBlock.CJK_RADICALS_SUPPLEMENT, 0x2E80, 0x2EFF, 59)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.KANGXI_RADICALS, 0x2F00, 0x2FDF, 59)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.IDEOGRAPHIC_DESCRIPTION_CHARACTERS, 0x2FF0, 0x2FFF, 59)); - - - s_list.add(new TTUnicodeRange( - UnicodeBlock.CJK_SYMBOLS_AND_PUNCTUATION, 0x3000, 0x303f, 48)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.HIRAGANA, 0x3040, 0x309f, 49, 17)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.KATAKANA, 0x30a0, 0x30ff, 50, 17)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.BOPOMOFO, 0x3100, 0x312f, 51)); - // TODO: wansung or johab? - s_list.add(new TTUnicodeRange( - UnicodeBlock.HANGUL_COMPATIBILITY_JAMO, 0x3130, 0x0318F, 52, 19)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.KANBUN, 0x3190, 0x319F, 59)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.BOPOMOFO_EXTENDED, 0x31A0, 0x31BF, 51)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.KATAKANA_PHONETIC_EXTENSIONS, 0x31F0, 0x31FF, 50, 17)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.ENCLOSED_CJK_LETTERS_AND_MONTHS, 0x3200, 0x32FF, 54)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.CJK_COMPATIBILITY, 0x3300, 0x33ff, 55)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A, 0x03400, 0x4dbf, 59)); - // TODO: yijing hex symbols - - // the kanji characters - s_list.add(new TTUnicodeRange( - UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS, 0x4e00, 0x9fff, 59, 17)); - - s_list.add(new TTUnicodeRange( - UnicodeBlock.YI_SYLLABLES, 0xA000, 0xA48F, 83)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.YI_RADICALS, 0xA490, 0xA4CF, 83)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.HANGUL_SYLLABLES, 0xAC00, 0xD7AF, 56)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.HIGH_SURROGATES, 0xD800, 0xDB7F, 0)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.HIGH_PRIVATE_USE_SURROGATES, 0xDB80, 0xDBFF, 0)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.LOW_SURROGATES, 0xDC00, 0xDFFF, 0)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.PRIVATE_USE_AREA, 0xE000, 0xF8FF, 60)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.CJK_COMPATIBILITY_IDEOGRAPHS, 0xf900, 0xfaff, 61)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.ALPHABETIC_PRESENTATION_FORMS, 0xFB00, 0xFB4F, 62)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.ARABIC_PRESENTATION_FORMS_A, 0xFB50, 0xFDFF, 62)); - - // TODO: variation selectors - - s_list.add(new TTUnicodeRange( - UnicodeBlock.COMBINING_HALF_MARKS, 0xFE20, 0xFE2F, 64)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.CJK_COMPATIBILITY_FORMS, 0xFE30, 0xFE4F, 65)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.SMALL_FORM_VARIANTS, 0xFE50, 0xFE6F, 66)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.ARABIC_PRESENTATION_FORMS_B, 0xFE70, 0xFEFF, 67)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.HALFWIDTH_AND_FULLWIDTH_FORMS, 0xFF00, 0xFFEF, 68, 17)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.SPECIALS, 0xFFF0, 0xFFFF, 69)); - } - - static public boolean find(String a_unicodeRange) { - initList(); - - s_selected = null; - - int i; - for (i = 0; i < s_list.size(); i++) { - TTUnicodeRange range = (TTUnicodeRange) s_list.get(i); - if (range.m_block.toString().equals(a_unicodeRange)) { - s_selected = range; - - return true; - } // if - } // for i - - return false; - } - - - private UnicodeBlock m_block = null; - private long m_start = 0; - private long m_end = 0; - - /** http://www.microsoft.com/typography/otspec/os2.htm - */ - private int m_osTwoFlag = 0; - - /** http://www.microsoft.com/typography/otspec/os2.htm - */ - private int m_codePageFlag = 0; - - public TTUnicodeRange(UnicodeBlock a_block, - long a_start, - long a_end, - int a_osTwoFlag) - { - m_block = a_block; - m_start = a_start; - m_end = a_end; - m_osTwoFlag = a_osTwoFlag; - } - - public TTUnicodeRange(UnicodeBlock a_block, - long a_start, - long a_end, - int a_osTwoFlag, - int a_codePageFlag) - { - m_block = a_block; - m_start = a_start; - m_end = a_end; - m_osTwoFlag = a_osTwoFlag; - m_codePageFlag = a_codePageFlag; - } - - public boolean equals(Object a_object) { - TTUnicodeRange object = (TTUnicodeRange) a_object; - return (m_start == object.m_start); - } - - public int compareTo(Object a_object) { - TTUnicodeRange object = (TTUnicodeRange) a_object; - if (this.m_start < object.m_start) { - return -1; - } else if (this.m_start == object.m_start) { - return 0; - } else - return 1; - } - - public String toString() { - return m_block.toString(); - } - - public long getStartCode() { - return m_start; - } - - public long getEndCode() { - return m_end; - } - - public int getOsTwoFlag() { - return m_osTwoFlag; - } - - public int getCodeRangeFlag() { - return m_codePageFlag; - } -} +/* + * $Id: TTUnicodeRange.java,v 1.1 2004/01/25 11:00:10 eed3si9n Exp $ + * + * $Copyright: copyright (c) 2003-2004, e.e d3si9n $ + * $License: + * This source code is part of DoubleType. + * DoubleType is a graphical typeface designer. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This Program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * In addition, as a special exception, e.e d3si9n gives permission to + * link the code of this program with any Java Platform that is available + * to public with free of charge, including but not limited to + * Sun Microsystem's JAVA(TM) 2 RUNTIME ENVIRONMENT (J2RE), + * and distribute linked combinations including the two. + * You must obey the GNU General Public License in all respects for all + * of the code used other than Java Platform. If you modify this file, + * you may extend this exception to your version of the file, but you are not + * obligated to do so. If you do not wish to do so, delete this exception + * statement from your version. + * $ + */ + +package org.doubletype.ossa.truetype; + +import java.util.*; + +import java.lang.Character.UnicodeBlock; + +/** + * @author e.e + */ +public class TTUnicodeRange implements Comparable { + public static final long k_notDef = 0x0001; + public static final long k_null = 0x0000; + public static final long k_cr = 0x000D; + public static final long k_space = 0x0020; + + static private boolean s_isInitialized = false; + static private ArrayList s_list = new ArrayList<>(); + static private TTUnicodeRange s_selected = null; + + static public TTUnicodeRange of(long a_unicode) { + initList(); + + TTUnicodeRange retval = null; + UnicodeBlock block = UnicodeBlock.of((int)a_unicode); + if (block == null) + return retval; + + int i; + for (i = 0; i < s_list.size(); i++) { + TTUnicodeRange range = s_list.get(i); + if (range.m_block.equals(block)) { + return range; + } // if + } // for i + + return retval; + } + + static public TTUnicodeRange getLastFound() { + return s_selected; + } + + static private void initList() { + if (s_isInitialized) + return; + + s_isInitialized = true; + + s_list.add(new TTUnicodeRange( + UnicodeBlock.BASIC_LATIN, 0x0020, 0x007F, 0, 63)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.LATIN_1_SUPPLEMENT, 0x0080, 0x00FF, 1, 0)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.LATIN_EXTENDED_A, 0x0100, 0x017f, 2)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.LATIN_EXTENDED_B, 0x0180, 0x024f, 3)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.IPA_EXTENSIONS, 0x0250, 0x02af, 4)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.SPACING_MODIFIER_LETTERS, 0x02B0, 0x02FF, 5)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.COMBINING_DIACRITICAL_MARKS, 0x0300, 0x036F, 6)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.GREEK, 0x0370, 0x03FF, 7, 3)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.CYRILLIC, 0x0400, 0x04FF, 9, 2)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.ARMENIAN, 0x0530, 0x058F, 10)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.HEBREW, 0x0590, 0x05FF, 11, 5)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.ARABIC, 0x0600, 0x06FF, 13, 6)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.SYRIAC, 0x0700, 0x074F, 71)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.THAANA, 0x0780, 0x07BF, 72)); + + s_list.add(new TTUnicodeRange( + UnicodeBlock.DEVANAGARI, 0x0900, 0x097F, 15)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.BENGALI, 0x0980, 0x09FF, 16)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.GURMUKHI, 0x0A00, 0x0A7F, 17)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.GUJARATI, 0x0A80, 0x0AFF, 18)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.ORIYA, 0x0B00, 0x0B7F, 19)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.TAMIL, 0x0B80, 0x0BFF, 20)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.TELUGU, 0x0C00, 0x0C7F, 21)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.KANNADA, 0x0C80, 0x0CFF, 22)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.MALAYALAM, 0x0D00, 0x0D7F, 23)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.SINHALA, 0x0D80, 0x0DFF, 73)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.THAI, 0x0E00, 0x0E7F, 24, 16)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.LAO, 0x0E80, 0x0EFF, 25)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.TIBETAN, 0x0F00, 0x0FFF, 70)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.MYANMAR, 0x1000, 0x109F, 74)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.GEORGIAN, 0x10A0, 0x10FF, 26)); + // TODO: wansung or johab? + s_list.add(new TTUnicodeRange( + UnicodeBlock.HANGUL_JAMO, 0x1100, 0x11FF, 28, 19)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.ETHIOPIC, 0x1200, 0x137F, 75)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.CHEROKEE, 0x13A0, 0x13FF, 76)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.UNIFIED_CANADIAN_ABORIGINAL_SYLLABICS, 0x1400, 0x167F, 77)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.OGHAM, 0x1680, 0x169F, 78)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.RUNIC, 0x16A0, 0x16FF, 79)); + + // TODO: tagalog, hanunoo, buhid, tagbanwa + + s_list.add(new TTUnicodeRange( + UnicodeBlock.KHMER, 0x1780, 0x17FF, 80)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.MONGOLIAN, 0x1800, 0x18AF, 81)); + + // linbu, tai le, khmer symbol, phonetic extensions, + + s_list.add(new TTUnicodeRange( + UnicodeBlock.LATIN_EXTENDED_ADDITIONAL, 0x1E00, 0x1EFF, 29)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.GREEK_EXTENDED, 0x1F00, 0x1FFF, 30)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.GENERAL_PUNCTUATION, 0x2000, 0x206F, 31)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.SUPERSCRIPTS_AND_SUBSCRIPTS, 0x2070, 0x209F, 32)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.CURRENCY_SYMBOLS, 0x20A0, 0x20CF, 33)); + + // combining diacritical marks + s_list.add(new TTUnicodeRange( + UnicodeBlock.COMBINING_MARKS_FOR_SYMBOLS, 0x20D0, 0x20FF, 34)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.LETTERLIKE_SYMBOLS, 0x2100, 0x214F, 35)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.NUMBER_FORMS, 0x2150, 0x218F, 36)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.ARROWS, 0x2190, 0x21FF, 37)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.MATHEMATICAL_OPERATORS, 0x2200, 0x22FF, 38)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.MISCELLANEOUS_TECHNICAL, 0x2300, 0x23FF, 39)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.CONTROL_PICTURES, 0x2400, 0x243F, 40)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.OPTICAL_CHARACTER_RECOGNITION, 0x2440, 0x245F, 41)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.ENCLOSED_ALPHANUMERICS, 0x2460, 0x24FF, 42)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.BOX_DRAWING, 0x2500, 0x257F, 43)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.BLOCK_ELEMENTS, 0x2580, 0x259F, 44)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.GEOMETRIC_SHAPES, 0x25A0, 0x25FF, 45)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.MISCELLANEOUS_SYMBOLS, 0x2600, 0x26FF, 46)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.DINGBATS, 0x2700, 0x27BF, 47)); + + // TODO: mics. math symbols A, supplemental arrows A + + s_list.add(new TTUnicodeRange( + UnicodeBlock.BRAILLE_PATTERNS, 0x2800, 0x28FF, 82)); + + // TODO: supplemental arrows B, mics. math symbols B, + // supplemental math op., mics. symbols and arrows + + +// CJKV supplements + s_list.add(new TTUnicodeRange( + UnicodeBlock.CJK_RADICALS_SUPPLEMENT, 0x2E80, 0x2EFF, 59)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.KANGXI_RADICALS, 0x2F00, 0x2FDF, 59)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.IDEOGRAPHIC_DESCRIPTION_CHARACTERS, 0x2FF0, 0x2FFF, 59)); + + + s_list.add(new TTUnicodeRange( + UnicodeBlock.CJK_SYMBOLS_AND_PUNCTUATION, 0x3000, 0x303f, 48)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.HIRAGANA, 0x3040, 0x309f, 49, 17)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.KATAKANA, 0x30a0, 0x30ff, 50, 17)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.BOPOMOFO, 0x3100, 0x312f, 51)); + // TODO: wansung or johab? + s_list.add(new TTUnicodeRange( + UnicodeBlock.HANGUL_COMPATIBILITY_JAMO, 0x3130, 0x0318F, 52, 19)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.KANBUN, 0x3190, 0x319F, 59)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.BOPOMOFO_EXTENDED, 0x31A0, 0x31BF, 51)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.KATAKANA_PHONETIC_EXTENSIONS, 0x31F0, 0x31FF, 50, 17)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.ENCLOSED_CJK_LETTERS_AND_MONTHS, 0x3200, 0x32FF, 54)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.CJK_COMPATIBILITY, 0x3300, 0x33ff, 55)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A, 0x03400, 0x4dbf, 59)); + // TODO: yijing hex symbols + + // the kanji characters + s_list.add(new TTUnicodeRange( + UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS, 0x4e00, 0x9fff, 59, 17)); + + s_list.add(new TTUnicodeRange( + UnicodeBlock.YI_SYLLABLES, 0xA000, 0xA48F, 83)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.YI_RADICALS, 0xA490, 0xA4CF, 83)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.HANGUL_SYLLABLES, 0xAC00, 0xD7AF, 56)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.HIGH_SURROGATES, 0xD800, 0xDB7F, 0)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.HIGH_PRIVATE_USE_SURROGATES, 0xDB80, 0xDBFF, 0)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.LOW_SURROGATES, 0xDC00, 0xDFFF, 0)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.PRIVATE_USE_AREA, 0xE000, 0xF8FF, 60)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.CJK_COMPATIBILITY_IDEOGRAPHS, 0xf900, 0xfaff, 61)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.ALPHABETIC_PRESENTATION_FORMS, 0xFB00, 0xFB4F, 62)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.ARABIC_PRESENTATION_FORMS_A, 0xFB50, 0xFDFF, 62)); + + // TODO: variation selectors + + s_list.add(new TTUnicodeRange( + UnicodeBlock.COMBINING_HALF_MARKS, 0xFE20, 0xFE2F, 64)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.CJK_COMPATIBILITY_FORMS, 0xFE30, 0xFE4F, 65)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.SMALL_FORM_VARIANTS, 0xFE50, 0xFE6F, 66)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.ARABIC_PRESENTATION_FORMS_B, 0xFE70, 0xFEFF, 67)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.HALFWIDTH_AND_FULLWIDTH_FORMS, 0xFF00, 0xFFEF, 68, 17)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.SPECIALS, 0xFFF0, 0xFFFF, 69)); + } + + static public boolean find(String a_unicodeRange) { + initList(); + + s_selected = null; + + int i; + for (i = 0; i < s_list.size(); i++) { + TTUnicodeRange range = (TTUnicodeRange) s_list.get(i); + if (range.m_block.toString().equals(a_unicodeRange)) { + s_selected = range; + + return true; + } // if + } // for i + + return false; + } + + + private UnicodeBlock m_block = null; + private long m_start = 0; + private long m_end = 0; + + /** http://www.microsoft.com/typography/otspec/os2.htm + */ + private int m_osTwoFlag = 0; + + /** http://www.microsoft.com/typography/otspec/os2.htm + */ + private int m_codePageFlag = 0; + + public TTUnicodeRange(UnicodeBlock a_block, + long a_start, + long a_end, + int a_osTwoFlag) + { + m_block = a_block; + m_start = a_start; + m_end = a_end; + m_osTwoFlag = a_osTwoFlag; + } + + public TTUnicodeRange(UnicodeBlock a_block, + long a_start, + long a_end, + int a_osTwoFlag, + int a_codePageFlag) + { + m_block = a_block; + m_start = a_start; + m_end = a_end; + m_osTwoFlag = a_osTwoFlag; + m_codePageFlag = a_codePageFlag; + } + + public boolean equals(Object a_object) { + TTUnicodeRange object = (TTUnicodeRange) a_object; + return (m_start == object.m_start); + } + + public int compareTo(TTUnicodeRange a_object) { + TTUnicodeRange object = a_object; + if (this.m_start < object.m_start) { + return -1; + } else if (this.m_start == object.m_start) { + return 0; + } else + return 1; + } + + public String toString() { + return m_block.toString(); + } + + public long getStartCode() { + return m_start; + } + + public long getEndCode() { + return m_end; + } + + public int getOsTwoFlag() { + return m_osTwoFlag; + } + + public int getCodeRangeFlag() { + return m_codePageFlag; + } +} diff --git a/libsrc/ttf/src/org/doubletype/ossa/xml/RInterleave.java b/libsrc/ttf/src/org/doubletype/ossa/xml/RInterleave.java index 5abbc2c00..2c158592a 100644 --- a/libsrc/ttf/src/org/doubletype/ossa/xml/RInterleave.java +++ b/libsrc/ttf/src/org/doubletype/ossa/xml/RInterleave.java @@ -1,757 +1,753 @@ -/* - * The Relaxer artifact - * Copyright (c) 2000-2004, ASAMI Tomoharu, All rights reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * - Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package org.doubletype.ossa.xml; - -import java.util.*; -import java.net.URL; -import java.math.*; -import java.lang.reflect.*; -import java.sql.Time; -import java.sql.Timestamp; -import org.w3c.dom.*; - -/** - * RInterleave - * - * @since May. 13, 2002 - * @version Oct. 22, 2003 - * @author ASAMI, Tomoharu (asami@relaxer.org) - */ -@SuppressWarnings("all") -public final class RInterleave { - private RStack rstack_; - private List entries_ = new ArrayList<>(); - private Map entryByStateClass_ = new HashMap<>(); - private Map entryByElementName_ = new HashMap<>(); - private Boolean isMatch_ = null; - - public RInterleave(RStack rstack) { - rstack_ = rstack; - } - - public Object getProperty(Class stateClass) { - StateClassEntry entry = _getEntryByStateClass(stateClass); - return (entry.getObject()); - } - - public Object[] getPropertyList(Class stateClass) { - StateClassEntry entry = _getEntryByStateClass(stateClass); - return (entry.getObjects()); - } - - public String getElementPropertyAsString(String elementName) { - Element element = _getElementByElementName(elementName); - if (element == null) { - return (null); - } - return (URelaxer.getElementPropertyAsString(element)); - } - - public boolean getElementPropertyAsBoolean(String elementName) { - Element element = _getElementByElementName(elementName); - if (element == null) { - return (false); - } - return (URelaxer.getElementPropertyAsBoolean(element)); - } - - public Boolean getElementPropertyAsBooleanObject(String elementName) { - Element element = _getElementByElementName(elementName); - if (element == null) { - return (null); - } - return (URelaxer.getElementPropertyAsBooleanObject(element)); - } - - public byte getElementPropertyAsByte(String elementName) { - Element element = _getElementByElementName(elementName); - if (element == null) { - return (-1); - } - return (URelaxer.getElementPropertyAsByte(element)); - } - - public Byte getElementPropertyAsByteObject(String elementName) { - Element element = _getElementByElementName(elementName); - if (element == null) { - return (null); - } - return (URelaxer.getElementPropertyAsByteObject(element)); - } - - public short getElementPropertyAsShort(String elementName) { - Element element = _getElementByElementName(elementName); - if (element == null) { - return (-1); - } - return (URelaxer.getElementPropertyAsShort(element)); - } - - public Short getElementPropertyAsShortObject(String elementName) { - Element element = _getElementByElementName(elementName); - if (element == null) { - return (null); - } - return (URelaxer.getElementPropertyAsShortObject(element)); - } - - public int getElementPropertyAsInt(String elementName) { - Element element = _getElementByElementName(elementName); - if (element == null) { - return (-1); - } - return (URelaxer.getElementPropertyAsInt(element)); - } - - public Integer getElementPropertyAsIntObject(String elementName) { - Element element = _getElementByElementName(elementName); - if (element == null) { - return (null); - } - return (URelaxer.getElementPropertyAsIntObject(element)); - } - - public long getElementPropertyAsLong(String elementName) { - Element element = _getElementByElementName(elementName); - if (element == null) { - return (-1); - } - return (URelaxer.getElementPropertyAsLong(element)); - } - - public Long getElementPropertyAsLongObject(String elementName) { - Element element = _getElementByElementName(elementName); - if (element == null) { - return (null); - } - return (URelaxer.getElementPropertyAsLongObject(element)); - } - - public float getElementPropertyAsFloat(String elementName) { - Element element = _getElementByElementName(elementName); - if (element == null) { - return (Float.NaN); - } - return (URelaxer.getElementPropertyAsFloat(element)); - } - - public Float getElementPropertyAsFloatObject(String elementName) { - Element element = _getElementByElementName(elementName); - if (element == null) { - return (null); - } - return (URelaxer.getElementPropertyAsFloatObject(element)); - } - - public double getElementPropertyAsDouble(String elementName) { - Element element = _getElementByElementName(elementName); - if (element == null) { - return (Double.NaN); - } - return (URelaxer.getElementPropertyAsDouble(element)); - } - - public Double getElementPropertyAsDoubleObject(String elementName) { - Element element = _getElementByElementName(elementName); - if (element == null) { - return (null); - } - return (URelaxer.getElementPropertyAsDoubleObject(element)); - } - - public BigDecimal getElementPropertyAsBigDecimal(String elementName) { - Element element = _getElementByElementName(elementName); - if (element == null) { - return (null); - } - return (URelaxer.getElementPropertyAsBigDecimal(element)); - } - - public BigInteger getElementPropertyAsBigInteger(String elementName) { - Element element = _getElementByElementName(elementName); - if (element == null) { - return (null); - } - return (URelaxer.getElementPropertyAsBigInteger(element)); - } - - public Date getElementPropertyAsDate(String elementName) { - Element element = _getElementByElementName(elementName); - if (element == null) { - return (null); - } - return (URelaxer.getElementPropertyAsDate(element)); - } - - public Locale getElementPropertyAsLocale(String elementName) { - Element element = _getElementByElementName(elementName); - if (element == null) { - return (null); - } - return (URelaxer.getElementPropertyAsLocale(element)); - } - - public URL getElementPropertyAsURL(String elementName) { - Element element = _getElementByElementName(elementName); - if (element == null) { - return (null); - } - return (URelaxer.getElementPropertyAsURL(element)); - } - - public java.sql.Timestamp getElementPropertyAsSQLTimestamp( - String elementName - ) { - Element element = _getElementByElementName(elementName); - if (element == null) { - return (null); - } - return (URelaxer.getElementPropertyAsSQLTimestamp(element)); - } - - public java.sql.Time getElementPropertyAsSQLTime( - String elementName - ) { - Element element = _getElementByElementName(elementName); - if (element == null) { - return (null); - } - return (URelaxer.getElementPropertyAsSQLTime(element)); - } - - public java.sql.Date getElementPropertyAsSQLDate( - String elementName - ) { - Element element = _getElementByElementName(elementName); - if (element == null) { - return (null); - } - return (URelaxer.getElementPropertyAsSQLDate(element)); - } - - public byte[] getElementPropertyAsBinaryBASE64( - String elementName - ) { - Element element = _getElementByElementName(elementName); - if (element == null) { - return (null); - } - return (URelaxer.getElementPropertyAsBinaryBASE64(element)); - } - - public byte[] getElementPropertyAsBinaryHEX( - String elementName - ) { - Element element = _getElementByElementName(elementName); - if (element == null) { - return (null); - } - return (URelaxer.getElementPropertyAsBinaryHEX(element)); - } - - public List getElementPropertyAsStringList(String elementName) { - List list = _getElementListByElementName(elementName); - int size = list.size(); - List result = new ArrayList<>(); - for (int i = 0;i < size;i++) { - Element element = (Element)list.get(i); - result.add(URelaxer.getElementPropertyAsString(element)); - } - return (result); - } - - public List getElementPropertyAsBooleanList(String elementName) { - List list = _getElementListByElementName(elementName); - int size = list.size(); - List result = new ArrayList<>(); - for (int i = 0;i < size;i++) { - Element element = (Element)list.get(i); - result.add(URelaxer.getElementPropertyAsBooleanObject(element)); - } - return (result); - } - - public List getElementPropertyAsByteList(String elementName) { - List list = _getElementListByElementName(elementName); - int size = list.size(); - List result = new ArrayList<>(); - for (int i = 0;i < size;i++) { - Element element = (Element)list.get(i); - result.add(URelaxer.getElementPropertyAsByteObject(element)); - } - return (result); - } - - public List getElementPropertyAsShortList(String elementName) { - List list = _getElementListByElementName(elementName); - int size = list.size(); - List result = new ArrayList<>(); - for (int i = 0;i < size;i++) { - Element element = (Element)list.get(i); - result.add(URelaxer.getElementPropertyAsShortObject(element)); - } - return (result); - } - - public List getElementPropertyAsIntList(String elementName) { - List list = _getElementListByElementName(elementName); - int size = list.size(); - List result = new ArrayList<>(); - for (int i = 0;i < size;i++) { - Element element = (Element)list.get(i); - result.add(URelaxer.getElementPropertyAsIntObject(element)); - } - return (result); - } - - public List getElementPropertyAsLongList(String elementName) { - List list = _getElementListByElementName(elementName); - int size = list.size(); - List result = new ArrayList<>(); - for (int i = 0;i < size;i++) { - Element element = (Element)list.get(i); - result.add(URelaxer.getElementPropertyAsLongObject(element)); - } - return (result); - } - - public List getElementPropertyAsFloatList(String elementName) { - List list = _getElementListByElementName(elementName); - int size = list.size(); - List result = new ArrayList<>(); - for (int i = 0;i < size;i++) { - Element element = (Element)list.get(i); - result.add(URelaxer.getElementPropertyAsFloatObject(element)); - } - return (result); - } - - public List getElementPropertyAsDoubleList(String elementName) { - List list = _getElementListByElementName(elementName); - int size = list.size(); - List result = new ArrayList<>(); - for (int i = 0;i < size;i++) { - Element element = (Element)list.get(i); - result.add(URelaxer.getElementPropertyAsDoubleObject(element)); - } - return (result); - } - - public List getElementPropertyAsBigDecimalList(String elementName) { - List list = _getElementListByElementName(elementName); - int size = list.size(); - List result = new ArrayList<>(); - for (int i = 0;i < size;i++) { - Element element = (Element)list.get(i); - result.add(URelaxer.getElementPropertyAsBigDecimal(element)); - } - return (result); - } - - public List getElementPropertyAsBigIntegerList(String elementName) { - List list = _getElementListByElementName(elementName); - int size = list.size(); - List result = new ArrayList<>(); - for (int i = 0;i < size;i++) { - Element element = (Element)list.get(i); - result.add(URelaxer.getElementPropertyAsBigInteger(element)); - } - return (result); - } - - public List getElementPropertyAsDateList(String elementName) { - List list = _getElementListByElementName(elementName); - int size = list.size(); - List result = new ArrayList<>(); - for (int i = 0;i < size;i++) { - Element element = (Element)list.get(i); - result.add(URelaxer.getElementPropertyAsDate(element)); - } - return (result); - } - - public List getElementPropertyAsLocaleList(String elementName) { - List list = _getElementListByElementName(elementName); - int size = list.size(); - List result = new ArrayList<>(); - for (int i = 0;i < size;i++) { - Element element = (Element)list.get(i); - result.add(URelaxer.getElementPropertyAsLocale(element)); - } - return (result); - } - - public List getElementPropertyAsURLList(String elementName) { - List list = _getElementListByElementName(elementName); - int size = list.size(); - List result = new ArrayList<>(); - for (int i = 0;i < size;i++) { - Element element = (Element)list.get(i); - result.add(URelaxer.getElementPropertyAsURL(element)); - } - return (result); - } - - public List getElementPropertyAsSQLTimestampList( - String elementName - ) { - List list = _getElementListByElementName(elementName); - int size = list.size(); - List result = new ArrayList<>(); - for (int i = 0;i < size;i++) { - Element element = (Element)list.get(i); - result.add(URelaxer.getElementPropertyAsSQLTimestamp(element)); - } - return (result); - } - - public List