001: /*
002: * $Id: TextStyleChangeRecord.java,v 1.3 2002/07/15 22:39:32 skavish Exp $
003: *
004: * ==========================================================================
005: *
006: * The JGenerator Software License, Version 1.0
007: *
008: * Copyright (c) 2000 Dmitry Skavish (skavish@usa.net). All rights reserved.
009: *
010: * Redistribution and use in source and binary forms, with or without
011: * modification, are permitted provided that the following conditions are met:
012: *
013: * 1. Redistributions of source code must retain the above copyright
014: * notice, this list of conditions and the following disclaimer.
015: *
016: * 2. Redistributions in binary form must reproduce the above copyright
017: * notice, this list of conditions and the following disclaimer in
018: * the documentation and/or other materials provided with the
019: * distribution.
020: *
021: * 3. The end-user documentation included with the redistribution, if
022: * any, must include the following acknowlegement:
023: * "This product includes software developed by Dmitry Skavish
024: * (skavish@usa.net, http://www.flashgap.com/)."
025: * Alternately, this acknowlegement may appear in the software itself,
026: * if and wherever such third-party acknowlegements normally appear.
027: *
028: * 4. The name "The JGenerator" must not be used to endorse or promote
029: * products derived from this software without prior written permission.
030: * For written permission, please contact skavish@usa.net.
031: *
032: * 5. Products derived from this software may not be called "The JGenerator"
033: * nor may "The JGenerator" appear in their names without prior written
034: * permission of Dmitry Skavish.
035: *
036: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
037: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
038: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
039: * DISCLAIMED. IN NO EVENT SHALL DMITRY SKAVISH OR THE OTHER
040: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
041: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
042: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
043: * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
044: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
045: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
046: * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
047: * SUCH DAMAGE.
048: *
049: */
050:
051: package org.openlaszlo.iv.flash.api.text;
052:
053: import org.openlaszlo.iv.flash.parser.*;
054: import org.openlaszlo.iv.flash.util.*;
055: import org.openlaszlo.iv.flash.api.*;
056: import java.io.*;
057: import java.util.*;
058:
059: /**
060: * TextStyleChangeRecord.
061: * <p>
062: * Changes the text style or/and position of the following text (TextRecord)
063: *
064: * @author Dmitry Skavish
065: * @see TextRecord
066: */
067: public final class TextStyleChangeRecord extends FlashItem {
068:
069: private Font font = null; // font of the following text
070: private Color color = null; // color of the following text
071: private int xOffset = Integer.MAX_VALUE; // x of the following text
072: private int yOffset = Integer.MAX_VALUE; // y of the following text
073: private int height; // font height
074:
075: /**
076: * Creates empty change record
077: */
078: public TextStyleChangeRecord() {
079: }
080:
081: /**
082: * Creates change record of font and color
083: *
084: * @param font new font
085: * @param height height of the new font
086: * @param color new color
087: */
088: public TextStyleChangeRecord(Font font, int height, Color color) {
089: this .font = font;
090: this .height = height;
091: this .color = color;
092: }
093:
094: /**
095: * Creates change record of X and Y
096: *
097: * @param x new X (in twixels)
098: * @param y new Y (in twixels)
099: */
100: public TextStyleChangeRecord(int x, int y) {
101: this .xOffset = x;
102: this .yOffset = y;
103: }
104:
105: public void setFont(Font font) {
106: this .font = font;
107: }
108:
109: public void setColor(Color color) {
110: this .color = color;
111: }
112:
113: public void setX(int x) {
114: this .xOffset = x;
115: }
116:
117: public void setY(int y) {
118: this .yOffset = y;
119: }
120:
121: public void setHeight(int h) {
122: this .height = h;
123: }
124:
125: public Font getFont() {
126: return font;
127: }
128:
129: public Color getColor() {
130: return color;
131: }
132:
133: public int getX() {
134: return xOffset;
135: }
136:
137: public int getY() {
138: return yOffset;
139: }
140:
141: public int getHeight() {
142: return height;
143: }
144:
145: /**
146: * Merges this record into specified one
147: * <P>
148: * Attributes of the specified one have bigger priority
149: *
150: * @param ts specified record
151: */
152: public void mergeTo(TextStyleChangeRecord ts) {
153: if (ts.getFont() == null) {
154: ts.setFont(font);
155: ts.setHeight(height);
156: }
157: if (ts.getColor() == null)
158: ts.setColor(color);
159: if (ts.getX() == Integer.MAX_VALUE)
160: ts.setX(xOffset);
161: if (ts.getY() == Integer.MAX_VALUE)
162: ts.setY(yOffset);
163: }
164:
165: public void write(FlashOutput fob) {
166: // write control record
167: fob.initBits();
168: fob.writeBits(0x08, 4);
169: fob.writeBool(font != null);
170: fob.writeBool(color != null);
171: fob.writeBool(yOffset != Integer.MAX_VALUE);
172: fob.writeBool(xOffset != Integer.MAX_VALUE);
173: fob.flushBits();
174: if (font != null)
175: fob.writeFontID(font);
176: if (color != null)
177: color.write(fob);
178: if (xOffset != Integer.MAX_VALUE)
179: fob.writeWord(xOffset);
180: if (yOffset != Integer.MAX_VALUE)
181: fob.writeWord(yOffset);
182: if (font != null)
183: fob.writeWord(height);
184: }
185:
186: public boolean isX() {
187: return xOffset != Integer.MAX_VALUE;
188: }
189:
190: public boolean isY() {
191: return yOffset != Integer.MAX_VALUE;
192: }
193:
194: public void printContent(PrintStream out, String indent) {
195: out.println(indent + "TextStyleChangeRecord: ");
196: if (font != null)
197: out.println(indent + " font=" + font.getFontName()
198: + ", height=" + height);
199: if (color != null)
200: color.printContent(out, indent + " ");
201: if (xOffset != Integer.MAX_VALUE)
202: out.println(indent + " xOffset=" + xOffset);
203: if (yOffset != Integer.MAX_VALUE)
204: out.println(indent + " yOffset=" + yOffset);
205: }
206:
207: protected FlashItem copyInto(FlashItem item, ScriptCopier copier) {
208: ((TextStyleChangeRecord) item).font = font;
209: ((TextStyleChangeRecord) item).color = color == null ? null
210: : (Color) color.getCopy(copier);
211: ((TextStyleChangeRecord) item).xOffset = xOffset;
212: ((TextStyleChangeRecord) item).yOffset = yOffset;
213: ((TextStyleChangeRecord) item).height = height;
214: return item;
215: }
216:
217: public FlashItem getCopy(ScriptCopier copier) {
218: return copyInto(new TextStyleChangeRecord(), copier);
219: }
220: }
|