📄 fstextconstructortest.java
字号:
*/
public Object[][] strings()
{
Object[][] parameters = new Object[][] {
new Object[] { "The quick brown, fox jumped over the lazy dog.", "atoz" },
new Object[] { "This line contains the same no. of characters.", "fixed" },
new Object[] { "Lorem ipsum dolor sit amet, consectetuer elit.", "latin" },
new Object[] { "Rato roeu a rolha da garrafa do rei da Russia.", "rhyme" },
};
return parameters;
}
private void encodeFontToFile(FSTextConstructor textGenerator, File file) throws Exception
{
int fontSize = 280;
int lineSpacing = fontSize;
int margin = fontSize;
FSMovie movie = new FSMovie();
ArrayList lines = new ArrayList();
char c = 0;
for (int i=0; i<32; i++)
{
StringBuffer line = new StringBuffer();
for (int j=0; j<64; j++, c++)
line.append((char)c);
lines.add(line.toString());
}
int fontId = movie.newIdentifier();
FSDefineText2 text = textGenerator.defineTextBlock(movie.newIdentifier(), lines, fontSize, FSColorTable.black(), lineSpacing);
FSDefineFont2 font = textGenerator.defineFont();
font.setIdentifier(fontId);
int screenWidth = text.getBounds().getWidth() + margin + margin;
int screenHeight = text.getBounds().getHeight() + margin + margin;
movie.setFrameSize(new FSBounds(0, 0, screenWidth, screenHeight));
movie.setFrameRate(1.0f);
movie.add(new FSSetBackgroundColor(FSColorTable.lightblue()));
movie.add(font);
movie.add(text);
movie.add(new FSPlaceObject2(text.getIdentifier(), 1, margin , margin));
movie.add(new FSShowFrame());
movie.encodeToFile(file.getPath());
}
private void encodeCharacterSet(FSTextConstructor textGenerator, char[] chars, File file) throws Exception
{
int fontSize = 280;
int lineSpacing = fontSize;
int margin = fontSize;
int charsPerline = 32;
FSMovie movie = new FSMovie();
ArrayList lines = new ArrayList();
char c = 0;
StringBuffer line = new StringBuffer();
for (int i=0; i<chars.length; i++)
{
line.append(chars[i]);
if (i % charsPerline == charsPerline-1)
{
lines.add(line.toString());
line = new StringBuffer();
}
}
if (line.length() > 0)
lines.add(line.toString());
int fontId = movie.newIdentifier();
textGenerator.willDisplay(chars);
FSDefineFont2 font = textGenerator.defineFont();
FSDefineText2 text = textGenerator.defineTextBlock(movie.newIdentifier(), lines, fontSize, FSColorTable.black(), lineSpacing);
font.setIdentifier(fontId);
int screenWidth = text.getBounds().getWidth() + margin + margin;
int screenHeight = text.getBounds().getHeight() + margin + margin;
movie.setFrameSize(new FSBounds(0, 0, screenWidth, screenHeight));
movie.setFrameRate(1.0f);
movie.add(new FSSetBackgroundColor(FSColorTable.lightblue()));
movie.add(font);
movie.add(text);
movie.add(new FSPlaceObject2(text.getIdentifier(), 1, margin , margin));
FSShapeConstructor path = new FSShapeConstructor();
int textWidth = text.getBounds().getWidth();
int textHeight = text.getBounds().getHeight();
int shapeId = movie.newIdentifier();
path.add(new FSSolidLine(1, FSColorTable.darkblue()));
path.rect(text.getBounds().getMinX(), text.getBounds().getMinY(),
textWidth, textHeight);
movie.add(path.defineShape(shapeId));
movie.add(new FSPlaceObject2(shapeId, 2, margin+textWidth/2, margin+textHeight/2));
movie.add(new FSShowFrame());
movie.encodeToFile(file.getPath());
}
private void encodeBoundedCharacterSet(FSTextConstructor textGenerator, char[] chars, File file) throws Exception
{
int fontSize = 280;
int lineSpacing = fontSize;
int margin = fontSize;
int charsPerLine = 32;
int layer = 1;
FSMovie movie = new FSMovie();
FSShapeConstructor path = new FSShapeConstructor();
textGenerator.willDisplay(chars);
int maxWidth = 0;
int x = margin;
int y = margin;
int fontId = movie.newIdentifier();
FSDefineFont2 font = textGenerator.defineFont();
font.setIdentifier(fontId);
movie.setFrameSize(new FSBounds(0, 0, 0, 0));
movie.setFrameRate(1.0f);
movie.add(new FSSetBackgroundColor(FSColorTable.lightblue()));
movie.add(font);
for (int i=0; i<chars.length; i++)
{
FSDefineText2 text = textGenerator.defineText(movie.newIdentifier(), String.valueOf(chars[i]), fontSize, FSColorTable.black());
int textWidth = text.getBounds().getWidth();
int textHeight = text.getBounds().getHeight();
int advance = textGenerator.advanceForChar(chars[i], fontSize) + 40;
int shapeId = movie.newIdentifier();
path.newPath();
path.add(new FSSolidLine(1, FSColorTable.darkblue()));
path.rect(text.getBounds().getMinX(), text.getBounds().getMinY(),
textWidth, textHeight);
movie.add(path.defineShape(shapeId));
movie.add(new FSPlaceObject2(shapeId, layer++, x+textWidth/2, y+textHeight/2));
movie.add(text);
movie.add(new FSPlaceObject2(text.getIdentifier(), layer++, x, y));
if (i % charsPerLine == charsPerLine-1)
{
maxWidth = x+advance+margin > maxWidth ? x+advance+margin : maxWidth;
x = margin;
y += lineSpacing;
}
else
{
x += advance;
}
}
movie.setFrameSize(new FSBounds(0, 0, maxWidth, y+margin));
movie.add(new FSShowFrame());
movie.encodeToFile(file.getPath());
}
private void encodeString(FSTextConstructor textGenerator, String str, File file) throws Exception
{
int fontSize = 280;
int margin = fontSize;
int layer = 1;
int x = margin;
int y = margin;
FSMovie movie = new FSMovie();
FSShapeConstructor path = new FSShapeConstructor();
textGenerator.willDisplay(str.toCharArray());
int fontId = movie.newIdentifier();
FSDefineFont2 font = textGenerator.defineFont();
font.setIdentifier(fontId);
movie.setFrameRate(1.0f);
movie.add(new FSSetBackgroundColor(FSColorTable.lightblue()));
movie.add(font);
FSDefineText2 text = textGenerator.defineText(movie.newIdentifier(), str, fontSize, FSColorTable.black());
int textWidth = text.getBounds().getWidth();
int textHeight = text.getBounds().getHeight();
int shapeId = movie.newIdentifier();
path.newPath();
path.add(new FSSolidLine(1, FSColorTable.darkblue()));
path.rect(text.getBounds().getMinX(), text.getBounds().getMinY(),
textWidth, textHeight);
movie.add(path.defineShape(shapeId));
movie.add(new FSPlaceObject2(shapeId, layer++, x+textWidth/2, y+textHeight/2));
movie.add(text);
movie.add(new FSPlaceObject2(text.getIdentifier(), layer++, x, y));
movie.add(new FSShowFrame());
movie.setFrameSize(new FSBounds(0, 0, textWidth+2*margin, textHeight+2*margin));
movie.encodeToFile(file.getPath());
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -