package {
import com.adobe.viewsource.ViewSource;
import flash.display.DisplayObject;
import flash.display.Graphics;
import flash.display.Sprite;
import flash.text.engine.FontPosture;
import flash.text.engine.JustificationStyle;
import flash.text.engine.Kerning;
import flashx.textLayout.container.ContainerController;
import flashx.textLayout.conversion.TextConverter;
import flashx.textLayout.edit.EditManager;
import flashx.textLayout.elements.Configuration;
import flashx.textLayout.elements.TextFlow;
import flashx.textLayout.formats.BlockProgression;
import flashx.textLayout.formats.Direction;
import flashx.textLayout.formats.JustificationRule;
import flashx.textLayout.formats.TextAlign;
import flashx.textLayout.formats.TextLayoutFormat;
import flashx.textLayout.formats.WhiteSpaceCollapse;
import flashx.undo.UndoManager;
[SWF (backgroundColor='#ffffff', width='800', height='600')]
public class TLFSample05 extends Sprite {
public function TLFSample05() {
super();
ViewSource.addMenuItem(this, "srcview/index.html");
const MARK_UP:String =
"<TextFlow xmlns='http://ns.adobe.com/textLayout/2008'>" +
"<div><p>こんにちは。</p></div>" +
"<p>私の名前は <span fontSize='25' color='#cc0000'>大雅</span> です。</p>" +
"<p>私は日本人です。</p>" +
"<p>お寿司が好きです。</p>" +
"<p>お酒はもっと好きです。<br /></p>" +
"<p><span fontSize='20' fontWeight='BOLD' color='#006600'>大事なことなのでもう一度言います。<br /></span></p>" +
"<p>私の名前は <span fontSize='25' color='#0000cc'>大雅</span> です。</p>" +
"<p>私は日本人です。</p>" +
"<p>お寿司が好きです。</p>" +
"<p>お酒はもっと好きです。</p>" +
"</TextFlow>";
var gap :int;
var controllerWidth_ :int;
var controllerHeight_ :int;
var width_ :int;
var height_ :int;
var target :MySprite;
var config :Configuration;
var g :Graphics;
var textFlow :TextFlow;
var textLayoutFormat :TextLayoutFormat;
gap = 10;
controllerWidth_ = 410;
controllerHeight_ = 200;
width_ = controllerWidth_ + gap + gap;
height_ = controllerHeight_ + gap + gap;
target = addChild( new MySprite() ) as MySprite;
textLayoutFormat = new TextLayoutFormat();
textLayoutFormat.color = 0x333333;
textLayoutFormat.fontSize = 18;
textLayoutFormat.kerning = Kerning.ON;
textLayoutFormat.fontStyle = FontPosture.NORMAL;
textLayoutFormat.textAlign = TextAlign.START;
textLayoutFormat.direction = Direction.LTR;
textLayoutFormat.blockProgression = BlockProgression.RL;
textLayoutFormat.locale = "ja";
textLayoutFormat.whiteSpaceCollapse = WhiteSpaceCollapse.PRESERVE;
textLayoutFormat.justificationRule = JustificationRule.EAST_ASIAN;
textLayoutFormat.justificationStyle = JustificationStyle.PUSH_IN_KINSOKU;
textLayoutFormat.columnCount = 2;
config = new Configuration();
config.textFlowInitialFormat = textLayoutFormat;
textFlow = TextConverter.importToFlow(MARK_UP, TextConverter.TEXT_LAYOUT_FORMAT, config);
textFlow.interactionManager = new EditManager( new UndoManager() );
textFlow.flowComposer.addController(
new ContainerController(target, controllerWidth_, controllerHeight_)
);
textFlow.flowComposer.updateAllControllers();
target.x = width_ + 10;
target.y = 20;
g = target.getGraphics();
g.beginFill(0xcccccc);
g.drawRect(gap, -gap, -width_, height_);
g.endFill();
}
}
}
import flash.display.Shape;
import flash.display.Sprite;
import flash.display.DisplayObject;
import flash.display.Graphics;
import flash.geom.Rectangle;
class MySprite extends Sprite {
protected var dummyShape:Shape;
public function MySprite() {
super();
dummyShape = new Shape();
}
public override function addChild(child:DisplayObject):DisplayObject {
trace("MySprite.addChild()");
return super.addChild(child);
}
public override function removeChild(child:DisplayObject):DisplayObject {
trace("MySprite.removeChild()");
return super.removeChild(child);
}
public override function get graphics():Graphics {
trace("MySprite.graphics");
return dummyShape.graphics;
}
public override function set scrollRect(value:Rectangle):void {
trace("scrollRect : ", value);
}
public function getGraphics():Graphics {
return super.graphics;
}
}