📄 fsdefinefont2.java
字号:
/*
* FSDefineFont2.java
* Transform
*
* Copyright (c) 2001-2006 Flagstone Software Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* * Neither the name of Flagstone Software Ltd. nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.flagstone.transform;
import java.util.*;
/**
FSDefineFont2 defines the shapes and layout of the glyphs used in a font.
<p>It extends the functionality provided by the FSDefineFont class by:</p>
<ul>
<li>allowing more than 65535 glyphs in a particular font.</li>
<li>including the functionality provided by the FontInfo class.</li>
<li>specifying ascent, descent and leading layout information for the font.</li>
<li>specifying advances for each glyph.</li>
<li>specifying bounding rectangles for each glyph.</li>
<li>specifying kerning pairs defining the distance between pairs of glyphs.</li>
</ul>
<p>The FSDefineFont2 class combines the attributes of the FSFontInfo and FSDefineFont classes:</p>
<table class="datasheet">
<tr><th align="left" colspan="2">Attributes</th></tr>
<tr>
<td><a name="FSDefineFont2_0">type</a></td>
<td>Identifies the data structure when it is encoded. The type attribute is read-only and may be used when iterating through the objects in an FSMovie object to identify the object class without using run-time type checking.</td>
</tr>
<tr>
<td><a name="FSDefineFont2_1">identifier</a></td>
<td>The unique identifier for this object.</td>
</tr>
<tr>
<td><a name="FSDefineFont2_2">encoding</a></td>
<td>Specifies whether the font codes are ANSI, SJIS or Unicode.</td>
</tr>
<tr>
<td><a name="FSDefineFont2_3">language</a></td>
<td>Identifies the spoken language for the font, either FSText.Japanese, FSText.Korean,
FSText.Latin, FSText.SimplifiedChinese, FSText.TraditionalChinese. This attribute
is used when displaying text fields and assists in determining language-appropriate
line breaks.</td>
</tr>
<tr>
<td><a name="FSDefineFont2_4">italic</a></td>
<td>Whether the font is italicised.</td>
</tr>
<tr>
<td><a name="FSDefineFont2_5">bold</a></td>
<td>Whether the font is bold.</td>
</tr>
<tr>
<td><a name="FSDefineFont2_6">small</a></td>
<td>Small point size fonts will be drawn aligned to pixel boundaries to improve rendering.</td>
</tr>
<tr>
<td><a name="FSDefineFont2_7">name</a></td>
<td>The name of the font.</td>
</tr>
<tr>
<td><a name="FSDefineFont2_8">shapes</a></td>
<td>An array of FSShape objects that define the outline for each glyph.</td>
</tr>
<tr>
<td><a name="FSDefineFont2_9">codes</a></td>
<td>An array mapping a glyph index to a particular character code in the font.</td>
</tr>
</table>
<p>Additional layout information for the glyphs in the font can also be specified through the following set of attributes:</p>
<table class="datasheet">
<tr>
<td><a name="FSDefineFont2_10">ascent</a></td>
<td>The maximum ascent for the font in twips.</td>
</tr>
<tr>
<td><a name="FSDefineFont2_11">descent</a></td>
<td>The maximum descent for the font in twips.</td>
</tr>
<tr>
<td><a name="FSDefineFont2_12">leading</a></td>
<td>The leading for the font.</td>
</tr>
<tr>
<td><a name="FSDefineFont2_13">advances</a></td>
<td>An array of integers that define the advance for each glyph in the font.</td>
</tr>
<tr>
<td><a name="FSDefineFont2_14">bounds</a></td>
<td>An array of FSBounds object that define the bounding rectangle for each glyph in the font.</td>
</tr>
<tr>
<td><a name="FSDefineFont2_15">kernings</a></td>
<td>An array of FSKerning objects that define adjustment to the advance for particular pairs of glyphs in the font.</td>
</tr>
</table>
<p>The default values for the ascent, descent and leading attributes is zero and the arrays containing the advances, bounds and kernings are empty. If the attributes all set to their default values then the layout information will not be encoded. All the values must be set and the arrays must contain the same number of entries as there are glyphs before the layout information will be encoded.</p>
<h1 class="datasheet">History</h1>
<p>The FSDefineFont2 class represents the DefineFont2 structure from the Macromedia
Flash (SWF) File Format Specification. It was introduced in Flash 2. Support for
spoken languages was added in Flash 6. Support for small point size fonts was
added in Flash 7.</p>
*/
public class FSDefineFont2 extends FSDefineObject
{
private int encoding = FSText.Unicode;
private boolean small = false;
private boolean italic = false;
private boolean bold = false;
private int language = 0;
private String name = "";
private ArrayList shapes = new ArrayList();
private ArrayList codes = new ArrayList();
private int ascent = 0;
private int descent = 0;
private int leading = 0;
private ArrayList advances = null;
private ArrayList bounds = null;
private ArrayList kernings = null;
/**
* Construct an FSDefineFont2 object, initalizing it with values decoded
* from an encoded object.
*
* @param coder an FSCoder containing the binary data.
*/
public FSDefineFont2(FSCoder coder)
{
super(DefineFont2, 0);
decode(coder);
}
/**
* Constructs an FSDefineFont2 object specifying only the name of the font.
*
* If none of the remaining attributes are set the Flash Player will load the font from the system
* on which it is running or substitute a suitable font if the specified font cannot be found. This
* is particularly useful when defining fonts that will be used to display text in FSDefineTextField
* objects.
*
* The font will be defined to use Unicode encoding. The flags which define the font's face will be
* set to false. The arrays of glyphs which define the shapes and the code which map the character
* codes to a particular glyph will remain empty since the font is loaded from the system on which
* it is displayed.
*
* @param anIdentifier the unique identifier for this object.
* @param name the name of the font.
*/
public FSDefineFont2(int anIdentifier, String name)
{
super(DefineFont2, anIdentifier);
setName(name);
}
/**
* Constructs an FSDefineFont2 object by copying values from an existing
* object.
*
* @param obj an FSDefineFont2 object.
*/
public FSDefineFont2(FSDefineFont2 obj)
{
super(obj);
encoding = obj.encoding;
small = obj.small;
italic = obj.italic;
bold = obj.bold;
language = obj.language;
name = new String(obj.name);
shapes = new ArrayList();
for (Iterator i = obj.shapes.iterator(); i.hasNext();)
shapes.add(((FSShape)i.next()).clone());
codes = new ArrayList();
for (Iterator i = obj.codes.iterator(); i.hasNext();)
codes.add(new Integer(((Integer)i.next()).intValue()));
ascent = obj.ascent;
descent = obj.descent;
leading = obj.leading;
if (advances != null)
{
advances = new ArrayList();
for (Iterator i = obj.advances.iterator(); i.hasNext();)
advances.add(new Integer(((Integer)i.next()).intValue()));
}
if (bounds != null)
{
bounds = new ArrayList();
for (Iterator i = obj.bounds.iterator(); i.hasNext();)
bounds.add(((FSBounds)i.next()).clone());
}
if (kernings != null)
{
kernings = new ArrayList();
for (Iterator i = obj.kernings.iterator(); i.hasNext();)
kernings.add(((FSKerning)i.next()).clone());
}
}
/** Add a shape to the array of shapes.
@param anObject a shape.
*/
public void add(FSShape anObject) { shapes.add(anObject); }
/** Add a code to the array of codes.
@param aCode a code for a glyph.
*/
public void addCode(int aCode) { codes.add(new Integer(aCode)); }
/** Add an advance to the array of advances.
@param anAdvance an advance for a glyph.
*/
public void addAdvance(int anAdvance) { advances.add(new Integer(anAdvance)); }
/** Add a bounds object to the array of bounds for each glyph.
@param anObject an FSBounds.
*/
public void add(FSBounds anObject) { bounds.add(anObject); }
/** Add a kerning object to the array of kernings for pairs of glyphs.
@param anObject an FSKerning.
*/
public void add(FSKerning anObject) { kernings.add(anObject); }
/** Gets the encoding used for the font codes, either FSText.ASCII, FSText.SJIS or FSText.Unicode.
@return the encoding used to represent characters rendered in the font.
*/
public int getEncoding()
{
return encoding;
}
// Flash 7
/** Does the font have a small point size. This is used only with a Unicode font encoding.
*
* @return a boolean indicating whether the font will be aligned on pixel boundaries.
*/
public boolean isSmall()
{
return small;
}
/** Sets the font is small. Used only with Unicode fonts.
*
* @param aBool a boolean flag indicating the font will be aligned on pixel boundaries.
*/
public void setSmall(boolean aBool)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -