1 50 51 package org.openlaszlo.iv.flash.api.text; 52 53 import org.openlaszlo.iv.flash.parser.*; 54 import org.openlaszlo.iv.flash.util.*; 55 import org.openlaszlo.iv.flash.api.*; 56 import java.io.*; 57 import java.util.*; 58 59 67 public final class TextStyleChangeRecord extends FlashItem { 68 69 private Font font = null; private Color color = null; private int xOffset = Integer.MAX_VALUE; private int yOffset = Integer.MAX_VALUE; private int height; 75 78 public TextStyleChangeRecord() {} 79 80 87 public TextStyleChangeRecord( Font font, int height, Color color ) { 88 this.font = font; 89 this.height = height; 90 this.color = color; 91 } 92 93 99 public TextStyleChangeRecord( int x, int y ) { 100 this.xOffset = x; 101 this.yOffset = y; 102 } 103 104 public void setFont( Font font ) { this.font = font; } 105 public void setColor( Color color ) { this.color = color; } 106 public void setX( int x ) { this.xOffset = x; } 107 public void setY( int y ) { this.yOffset = y; } 108 public void setHeight( int h ) { this.height = h; } 109 110 public Font getFont() { return font; } 111 public Color getColor() { return color; } 112 public int getX() { return xOffset; } 113 public int getY() { return yOffset; } 114 public int getHeight() { return height; } 115 116 123 public void mergeTo( TextStyleChangeRecord ts ) { 124 if( ts.getFont() == null ) { 125 ts.setFont( font ); 126 ts.setHeight( height ); 127 } 128 if( ts.getColor() == null ) ts.setColor( color ); 129 if( ts.getX() == Integer.MAX_VALUE ) ts.setX( xOffset ); 130 if( ts.getY() == Integer.MAX_VALUE ) ts.setY( yOffset ); 131 } 132 133 public void write( FlashOutput fob ) { 134 fob.initBits(); 136 fob.writeBits( 0x08, 4 ); 137 fob.writeBool( font != null ); 138 fob.writeBool( color != null ); 139 fob.writeBool( yOffset != Integer.MAX_VALUE ); 140 fob.writeBool( xOffset != Integer.MAX_VALUE ); 141 fob.flushBits(); 142 if( font != null ) fob.writeFontID( font ); 143 if( color != null ) color.write(fob); 144 if( xOffset != Integer.MAX_VALUE ) fob.writeWord(xOffset); 145 if( yOffset != Integer.MAX_VALUE ) fob.writeWord(yOffset); 146 if( font != null ) fob.writeWord(height); 147 } 148 149 public boolean isX() { 150 return xOffset != Integer.MAX_VALUE; 151 } 152 153 public boolean isY() { 154 return yOffset != Integer.MAX_VALUE; 155 } 156 157 public void printContent( PrintStream out, String indent ) { 158 out.println( indent+"TextStyleChangeRecord: " ); 159 if( font != null ) out.println( indent+" font="+font.getFontName()+", height="+height ); 160 if( color != null ) color.printContent(out, indent+" "); 161 if( xOffset != Integer.MAX_VALUE ) out.println( indent+" xOffset="+xOffset ); 162 if( yOffset != Integer.MAX_VALUE ) out.println( indent+" yOffset="+yOffset ); 163 } 164 165 protected FlashItem copyInto( FlashItem item, ScriptCopier copier ) { 166 ((TextStyleChangeRecord)item).font = font; 167 ((TextStyleChangeRecord)item).color = color == null? null: (Color) color.getCopy(copier); 168 ((TextStyleChangeRecord)item).xOffset = xOffset; 169 ((TextStyleChangeRecord)item).yOffset = yOffset; 170 ((TextStyleChangeRecord)item).height = height; 171 return item; 172 } 173 174 public FlashItem getCopy( ScriptCopier copier ) { 175 return copyInto( new TextStyleChangeRecord(), copier ); 176 } 177 } 178 179 | Popular Tags |