View Javadoc

1   // Copyright 2001, FreeHEP.
2   package org.freehep.graphicsio.swf;
3   
4   import java.io.IOException;
5   
6   /**
7    * DefineFontInfo2 TAG.
8    * 
9    * @author Mark Donszelmann
10   * @author Charles Loomis
11   * @version $Id: DefineFontInfo2.java 8584 2006-08-10 23:06:37Z duns $
12   */
13  public class DefineFontInfo2 extends DefineFontInfo {
14  
15      int languageCode;
16  
17      public DefineFontInfo2(int fontID, String name, boolean italic,
18              boolean bold, int languageCode, int[] codes) {
19          super(fontID, name, false, false, italic, bold, true, codes);
20          this.languageCode = languageCode;
21      }
22  
23      public DefineFontInfo2() {
24          super(62, 6);
25      }
26  
27      public SWFTag read(int tagID, SWFInputStream swf, int len)
28              throws IOException {
29  
30          DefineFontInfo2 tag = new DefineFontInfo2();
31          tag.fontID = swf.readUnsignedShort();
32  
33          // associate this fontinfo with font
34          DefineFont font = (DefineFont) swf.getDictionary().get(tag.fontID);
35          int numGlyphs = font.getGlyphCount();
36          font.setFontInfo(tag);
37  
38          /* int nameLength = */ swf.readUnsignedByte();
39          tag.name = swf.readUTF();
40          /* int reserved = (int) */ swf.readUBits(3);
41          tag.shiftJIS = swf.readBitFlag();
42          tag.ansi = swf.readBitFlag();
43          tag.italic = swf.readBitFlag();
44          tag.bold = swf.readBitFlag();
45          tag.wideCodes = swf.readBitFlag();
46          tag.languageCode = swf.readLanguageCode();
47  
48          tag.codes = swf.readUnsignedShort(numGlyphs);
49          return tag;
50      }
51  
52      public void write(int tagID, SWFOutputStream swf) throws IOException {
53          swf.writeUnsignedShort(fontID);
54          swf.writeUnsignedByte(name.length());
55          swf.writeUTF(name);
56          swf.writeUBits(0, 3);
57          swf.writeBitFlag(false);
58          swf.writeBitFlag(false);
59          swf.writeBitFlag(italic);
60          swf.writeBitFlag(bold);
61          swf.writeBitFlag(true);
62          swf.writeLanguageCode(languageCode);
63          swf.writeUnsignedShort(codes);
64      }
65  
66      public String toString() {
67          StringBuffer s = new StringBuffer();
68          s.append(super.toString() + "\n");
69          s.append("  name:      " + name + "\n");
70          s.append("  numGlyphs: " + codes.length + "\n");
71          s.append("    ");
72          for (int i = 0; i < codes.length; i++) {
73              s.append("[" + codes[i] + ",'" + ((char) codes[i]) + "'] ");
74          }
75          s.append("\n");
76          return s.toString();
77      }
78  }