Text Engine 縦書きサンプル forked from: Text Engine 縦書きサンプル
- // forked from mtok's Text Engine 縦書きサンプル
- package
- {
- [SWF(width="465", height="465", backgroundColor="0xffffff", frameRate="0")]
- import flash.display.Shape;
- import flash.display.Sprite;
- import flash.geom.Rectangle;
- import flash.text.engine.EastAsianJustifier;
- import flash.text.engine.ElementFormat;
- import flash.text.engine.FontDescription;
- import flash.text.engine.TextBlock;
- import flash.text.engine.TextBaseline;
- import flash.text.engine.LineJustification;
- import flash.text.engine.TextElement;
- import flash.text.engine.TextLine;
- import flash.text.engine.TextRotation;
- import flash.system.Capabilities;
- /**
- * ...
- * @author ...
- */
- public class Tategaki extends Sprite
- {
- private var grid:Shape;
- private var screen:Sprite;
- public function Tategaki()
- {
- grid = new Shape();
- grid.graphics.lineStyle(1, 0xA0EBF3);
- GraphicsUtils.drawGrid(grid.graphics, new Rectangle(0, 0, 451, 451), 50);
- GraphicsUtils.drawGrid(grid.graphics, new Rectangle(0, 0, 451, 451), 25, Vector.<Number>([2.5,2.5]));
- addChild(grid);
- addChild(screen = new Sprite());
- grid.x = screen.x = 5;
- grid.y = screen.y = 5;
- var japanese:String = "そこから出発して三日のあいだ東の方へ進んでゆくと、ディオミーラにまいります。\n都市には七十の銀の丸屋根、あらゆる神々の銅像、錫を敷きつめた道、玻璃づくりの劇場、朝ごとに塔の上より刻を告げる金の鶏がございます。すべてこのようなめでたさは、旅人ならば他国でも目にしてとっくに知っておるものばかりでございます。";
- var textBlock:TextBlock = new TextBlock();
- var font:FontDescription = new FontDescription();
- if (Capabilities.os.search("Mac OS") > -1) {
- font.fontName = "MS 明朝";
- } else {
- font.fontName = "MS 明朝";
- }
- var format:ElementFormat = new ElementFormat(font);
- format.fontSize = 28;
- format.locale = "ja";
- format.color = 0x222222;
- textBlock.baselineZero = TextBaseline.IDEOGRAPHIC_CENTER;
- textBlock.textJustifier = new EastAsianJustifier("ja", LineJustification.ALL_INCLUDING_LAST);
- textBlock.lineRotation = TextRotation.ROTATE_90;
- var linePosition:Number = this.stage.stageWidth - 40;
- textBlock.content = new TextElement(japanese, format);
- var previousLine:TextLine = null;
- var textLine:TextLine;
- screen.graphics.lineStyle(1, 0xff0000);
- while (true) {
- textLine = textBlock.createTextLine(previousLine, 450);
- if (textLine == null)
- break;
- textLine.y = 0;
- textLine.x = linePosition;
- screen.graphics.moveTo(textLine.x, textLine.y);
- screen.graphics.lineTo(textLine.x, textLine.height);
- linePosition -= 50;
- screen.addChild(textLine);
- previousLine = textLine;
- }
- }
- }
- }
- import flash.display.Graphics;
- import flash.geom.Point;
- import flash.geom.Rectangle;
- class GraphicsUtils {
- public function GraphicsUtils() {
- ;
- }
- public static function drawGrid(g:Graphics, rect:Rectangle, size:Number, pattern:Vector.<Number> = null):void {
- var i:Number;
- var limitW:Number;
- var limitH:Number;
- limitW = rect.x + rect.width;
- limitH = rect.y + rect.height;
- if (pattern == null) {
- i = rect.y;
- while (i < limitH) {
- g.moveTo(rect.x, i);
- g.lineTo(limitW, i);
- i += size;
- }
- i = rect.x;
- while ( i < limitW) {
- g.moveTo(i, rect.y);
- g.lineTo(i, limitH);
- i += size;
- }
- }else {
- i = rect.y;
- while (i < limitH) {
- drawDotLine(g, rect.x, i, limitW, i, pattern);
- i += size;
- }
- i = rect.x;
- while (i < limitW) {
- drawDotLine(g, i, rect.y, i, limitH, pattern);
- i += size;
- }
- }
- }
- public static function drawDotLine(g:Graphics, fromX:Number, fromY:Number, toX:Number, toY:Number, pattern:Vector.<Number>):void {
- var i:int;
- var n:Number;
- var v:Point = new Point(toX - fromX, toY - fromY);
- var tmp:Point;
- var l:Number = v.length;
- var sl:SimpleList = new SimpleList();
- var s:Boolean = true;
- v.normalize(1);
- for (i = 0; i < pattern.length; i++) {
- n = pattern[i];
- tmp = v.clone();
- tmp.normalize(n);
- sl.append({v:tmp, length:n});
- }
- var pos:Point = new Point(fromX, fromY);
- var obj:Object;
- n = 0;
- g.moveTo(pos.x, pos.y);
- while (true) {
- obj = sl.next();
- n += obj.length;
- if (n > l) {
- pos.x = toX;
- pos.y = toY;
- s = step(g, pos, s);
- break;
- }else {
- pos.offset(obj.v.x, obj.v.y);
- s = step(g, pos, s);
- }
- }
- }
- private static function step(g:Graphics, p:Point, s:Boolean):Boolean {
- if (s) {
- g.lineTo(p.x, p.y);
- }else {
- g.moveTo(p.x, p.y);
- }
- return !s;
- }
- }
- class SimpleList {
- private var currentElement:ListElement;
- private var appendFunc:Function;
- public function SimpleList(data:* = null) {
- if (data != null) {
- _initialize(data);
- }else{
- appendFunc = _initialize;
- }
- }
- public function append(data:*):void {
- appendFunc.call(null, data);
- }
- public function _initialize(data:*):void {
- currentElement = new ListElement(data);
- currentElement.next = currentElement;
- currentElement.prev = currentElement;
- appendFunc = _append;
- }
- public function _append(data:*):void {
- var elem:ListElement = new ListElement(data);
- var tmp:ListElement;
- tmp = currentElement.next;
- currentElement.next = elem;
- elem.prev = currentElement;
- elem.next = tmp;
- tmp.prev = elem;
- currentElement = elem;
- }
- public function current():*{
- return currentElement.data;
- }
- public function next():* {
- currentElement = currentElement.next;
- return currentElement.data;
- }
- public function prev():*{
- currentElement = currentElement.prev;
- return currentElement.data;
- }
- }
- class ListElement {
- public var next:ListElement;
- public var prev:ListElement;
- public var data:*;
- public function ListElement(data:*) {
- this.data = data;
- }
- }
Text Engine 縦書きサンプル forked from: Text Engine 縦書きサンプル
- // forked from mtok's Text Engine 縦書きサンプル
- package
- {
- [SWF(width="465", height="465", backgroundColor="0xffffff", frameRate="0")]
- import flash.display.Shape;
- import flash.display.Sprite;
- import flash.geom.Rectangle;
- import flash.text.engine.EastAsianJustifier;
- import flash.text.engine.ElementFormat;
- import flash.text.engine.FontDescription;
- import flash.text.engine.TextBlock;
- import flash.text.engine.TextBaseline;
- import flash.text.engine.LineJustification;
- import flash.text.engine.TextElement;
- import flash.text.engine.TextLine;
- import flash.text.engine.TextRotation;
- import flash.system.Capabilities;
- /**
- * ...
- * @author ...
- */
- public class Tategaki extends Sprite
- {
- private var grid:Shape;
- private var screen:Sprite;
- public function Tategaki()
- {
- grid = new Shape();
- grid.graphics.lineStyle(1, 0xA0EBF3);
- GraphicsUtils.drawGrid(grid.graphics, new Rectangle(0, 0, 451, 451), 50);
- GraphicsUtils.drawGrid(grid.graphics, new Rectangle(0, 0, 451, 451), 25, Vector.<Number>([2.5,2.5]));
- addChild(grid);
- addChild(screen = new Sprite());
- grid.x = screen.x = 5;
- grid.y = screen.y = 5;
- var japanese:String = "夕暮れてすとは\n\n\tおやまぁ雲のはたてに物ぞ思ふ\nあまつそらなる\n人を恋ふとて";
- var textBlock:TextBlock = new TextBlock();
- var font:FontDescription = new FontDescription();
- if (Capabilities.os.search("Mac OS") > -1) {
- font.fontName = "小塚明朝";
- } else {
- font.fontName = "HGP行書体";
- }
- var format:ElementFormat = new ElementFormat(font);
- format.fontSize = 50;
- format.locale = "ja";
- format.color = 0x222222;
- textBlock.baselineZero = TextBaseline.IDEOGRAPHIC_CENTER;
- textBlock.textJustifier = new EastAsianJustifier("ja", LineJustification.ALL_INCLUDING_LAST);
- textBlock.lineRotation = TextRotation.ROTATE_90;
- var linePosition:Number = this.stage.stageWidth - 40;
- textBlock.content = new TextElement(japanese, format);
- var previousLine:TextLine = null;
- var textLine:TextLine;
- screen.graphics.lineStyle(1, 0xff0000);
- while (true) {
- textLine = textBlock.createTextLine(previousLine, 450);
- if (textLine == null)
- break;
- textLine.y = 0;
- textLine.x = linePosition;
- screen.graphics.moveTo(textLine.x, textLine.y);
- screen.graphics.lineTo(textLine.x, textLine.height);
- linePosition -= 50;
- screen.addChild(textLine);
- previousLine = textLine;
- }
- }
- }
- }
- import flash.display.Graphics;
- import flash.geom.Point;
- import flash.geom.Rectangle;
- class GraphicsUtils {
- public function GraphicsUtils() {
- ;
- }
- public static function drawGrid(g:Graphics, rect:Rectangle, size:Number, pattern:Vector.<Number> = null):void {
- var i:Number;
- var limitW:Number;
- var limitH:Number;
- limitW = rect.x + rect.width;
- limitH = rect.y + rect.height;
- if (pattern == null) {
- i = rect.y;
- while (i < limitH) {
- g.moveTo(rect.x, i);
- g.lineTo(limitW, i);
- i += size;
- }
- i = rect.x;
- while ( i < limitW) {
- g.moveTo(i, rect.y);
- g.lineTo(i, limitH);
- i += size;
- }
- }else {
- i = rect.y;
- while (i < limitH) {
- drawDotLine(g, rect.x, i, limitW, i, pattern);
- i += size;
- }
- i = rect.x;
- while (i < limitW) {
- drawDotLine(g, i, rect.y, i, limitH, pattern);
- i += size;
- }
- }
- }
- public static function drawDotLine(g:Graphics, fromX:Number, fromY:Number, toX:Number, toY:Number, pattern:Vector.<Number>):void {
- var i:int;
- var n:Number;
- var v:Point = new Point(toX - fromX, toY - fromY);
- var tmp:Point;
- var l:Number = v.length;
- var sl:SimpleList = new SimpleList();
- var s:Boolean = true;
- v.normalize(1);
- for (i = 0; i < pattern.length; i++) {
- n = pattern[i];
- tmp = v.clone();
- tmp.normalize(n);
- sl.append({v:tmp, length:n});
- }
- var pos:Point = new Point(fromX, fromY);
- var obj:Object;
- n = 0;
- g.moveTo(pos.x, pos.y);
- while (true) {
- obj = sl.next();
- n += obj.length;
- if (n > l) {
- pos.x = toX;
- pos.y = toY;
- s = step(g, pos, s);
- break;
- }else {
- pos.offset(obj.v.x, obj.v.y);
- s = step(g, pos, s);
- }
- }
- }
- private static function step(g:Graphics, p:Point, s:Boolean):Boolean {
- if (s) {
- g.lineTo(p.x, p.y);
- }else {
- g.moveTo(p.x, p.y);
- }
- return !s;
- }
- }
- class SimpleList {
- private var currentElement:ListElement;
- private var appendFunc:Function;
- public function SimpleList(data:* = null) {
- if (data != null) {
- _initialize(data);
- }else{
- appendFunc = _initialize;
- }
- }
- public function append(data:*):void {
- appendFunc.call(null, data);
- }
- public function _initialize(data:*):void {
- currentElement = new ListElement(data);
- currentElement.next = currentElement;
- currentElement.prev = currentElement;
- appendFunc = _append;
- }
- public function _append(data:*):void {
- var elem:ListElement = new ListElement(data);
- var tmp:ListElement;
- tmp = currentElement.next;
- currentElement.next = elem;
- elem.prev = currentElement;
- elem.next = tmp;
- tmp.prev = elem;
- currentElement = elem;
- }
- public function current():*{
- return currentElement.data;
- }
- public function next():* {
- currentElement = currentElement.next;
- return currentElement.data;
- }
- public function prev():*{
- currentElement = currentElement.prev;
- return currentElement.data;
- }
- }
- class ListElement {
- public var next:ListElement;
- public var prev:ListElement;
- public var data:*;
- public function ListElement(data:*) {
- this.data = data;
- }
- }
Text Engine 縦書きサンプル forked from: Text Engine 縦書きサンプル
- // forked from mtok's Text Engine 縦書きサンプル
- package
- {
- [SWF(width="465", height="465", backgroundColor="0xffffff", frameRate="0")]
- import flash.display.Shape;
- import flash.display.Sprite;
- import flash.geom.Rectangle;
- import flash.text.engine.EastAsianJustifier;
- import flash.text.engine.ElementFormat;
- import flash.text.engine.FontDescription;
- import flash.text.engine.TextBlock;
- import flash.text.engine.TextBaseline;
- import flash.text.engine.LineJustification;
- import flash.text.engine.TextElement;
- import flash.text.engine.TextLine;
- import flash.text.engine.TextRotation;
- import flash.system.Capabilities;
- /**
- * ...
- * @author ...
- */
- public class Tategaki extends Sprite
- {
- private var grid:Shape;
- private var screen:Sprite;
- public function Tategaki()
- {
- grid = new Shape();
- grid.graphics.lineStyle(1, 0xA0EBF3);
- GraphicsUtils.drawGrid(grid.graphics, new Rectangle(0, 0, 451, 451), 50);
- GraphicsUtils.drawGrid(grid.graphics, new Rectangle(0, 0, 451, 451), 25, Vector.<Number>([2.5,2.5]));
- addChild(grid);
- addChild(screen = new Sprite());
- grid.x = screen.x = 5;
- grid.y = screen.y = 5;
- var japanese:String = "夕暮れは\n雲のはたてに物ぞ思ふ\nあまつそらなる\n人を恋ふとて";
- var textBlock:TextBlock = new TextBlock();
- var font:FontDescription = new FontDescription();
- if (Capabilities.os.search("Mac OS") > -1) {
- font.fontName = "小塚明朝";
- } else {
- font.fontName = "HGP行書体";
- }
- var format:ElementFormat = new ElementFormat(font);
- format.fontSize = 50;
- format.locale = "ja";
- format.color = 0x222222;
- textBlock.baselineZero = TextBaseline.IDEOGRAPHIC_CENTER;
- textBlock.textJustifier = new EastAsianJustifier("ja", LineJustification.ALL_INCLUDING_LAST);
- textBlock.lineRotation = TextRotation.ROTATE_90;
- var linePosition:Number = this.stage.stageWidth - 40;
- textBlock.content = new TextElement(japanese, format);
- var previousLine:TextLine = null;
- var textLine:TextLine;
- screen.graphics.lineStyle(1, 0xff0000);
- while (true) {
- textLine = textBlock.createTextLine(previousLine, 450);
- if (textLine == null)
- break;
- textLine.y = 0;
- textLine.x = linePosition;
- screen.graphics.moveTo(textLine.x, textLine.y);
- screen.graphics.lineTo(textLine.x, textLine.height);
- linePosition -= 50;
- screen.addChild(textLine);
- previousLine = textLine;
- }
- }
- }
- }
- import flash.display.Graphics;
- import flash.geom.Point;
- import flash.geom.Rectangle;
- class GraphicsUtils {
- public function GraphicsUtils() {
- ;
- }
- public static function drawGrid(g:Graphics, rect:Rectangle, size:Number, pattern:Vector.<Number> = null):void {
- var i:Number;
- var limitW:Number;
- var limitH:Number;
- limitW = rect.x + rect.width;
- limitH = rect.y + rect.height;
- if (pattern == null) {
- i = rect.y;
- while (i < limitH) {
- g.moveTo(rect.x, i);
- g.lineTo(limitW, i);
- i += size;
- }
- i = rect.x;
- while ( i < limitW) {
- g.moveTo(i, rect.y);
- g.lineTo(i, limitH);
- i += size;
- }
- }else {
- i = rect.y;
- while (i < limitH) {
- drawDotLine(g, rect.x, i, limitW, i, pattern);
- i += size;
- }
- i = rect.x;
- while (i < limitW) {
- drawDotLine(g, i, rect.y, i, limitH, pattern);
- i += size;
- }
- }
- }
- public static function drawDotLine(g:Graphics, fromX:Number, fromY:Number, toX:Number, toY:Number, pattern:Vector.<Number>):void {
- var i:int;
- var n:Number;
- var v:Point = new Point(toX - fromX, toY - fromY);
- var tmp:Point;
- var l:Number = v.length;
- var sl:SimpleList = new SimpleList();
- var s:Boolean = true;
- v.normalize(1);
- for (i = 0; i < pattern.length; i++) {
- n = pattern[i];
- tmp = v.clone();
- tmp.normalize(n);
- sl.append({v:tmp, length:n});
- }
- var pos:Point = new Point(fromX, fromY);
- var obj:Object;
- n = 0;
- g.moveTo(pos.x, pos.y);
- while (true) {
- obj = sl.next();
- n += obj.length;
- if (n > l) {
- pos.x = toX;
- pos.y = toY;
- s = step(g, pos, s);
- break;
- }else {
- pos.offset(obj.v.x, obj.v.y);
- s = step(g, pos, s);
- }
- }
- }
- private static function step(g:Graphics, p:Point, s:Boolean):Boolean {
- if (s) {
- g.lineTo(p.x, p.y);
- }else {
- g.moveTo(p.x, p.y);
- }
- return !s;
- }
- }
- class SimpleList {
- private var currentElement:ListElement;
- private var appendFunc:Function;
- public function SimpleList(data:* = null) {
- if (data != null) {
- _initialize(data);
- }else{
- appendFunc = _initialize;
- }
- }
- public function append(data:*):void {
- appendFunc.call(null, data);
- }
- public function _initialize(data:*):void {
- currentElement = new ListElement(data);
- currentElement.next = currentElement;
- currentElement.prev = currentElement;
- appendFunc = _append;
- }
- public function _append(data:*):void {
- var elem:ListElement = new ListElement(data);
- var tmp:ListElement;
- tmp = currentElement.next;
- currentElement.next = elem;
- elem.prev = currentElement;
- elem.next = tmp;
- tmp.prev = elem;
- currentElement = elem;
- }
- public function current():*{
- return currentElement.data;
- }
- public function next():* {
- currentElement = currentElement.next;
- return currentElement.data;
- }
- public function prev():*{
- currentElement = currentElement.prev;
- return currentElement.data;
- }
- }
- class ListElement {
- public var next:ListElement;
- public var prev:ListElement;
- public var data:*;
- public function ListElement(data:*) {
- this.data = data;
- }
- }
Text Engine 縦書きサンプル forked from: Text Engine 縦書きサンプル
- package{
- import flash.display.Sprite;
- import flash.display.StageAlign;
- import flash.display.StageScaleMode;
- import flash.net.URLLoader;
- import flash.net.URLRequest;
- import flashx.textLayout.compose.StandardFlowComposer;
- import flashx.textLayout.container.DisplayObjectContainerController;
- import flashx.textLayout.container.IContainerController;
- import flashx.textLayout.elements.TextFlow;
- import flashx.textLayout.conversion.TextFilter;
- import flash.events.Event;
- import flash.events.IOErrorEvent;
- [SWF(width = "460", height = "300", backgroundColor = "0xFFFFFF")]
- public class Index2 extends Sprite
- {
- private static const MARKUP:String = "test.xml";
- private var _textFlow:TextFlow;
- public function Index2()
- {
- // ステージ設定
- stage.scaleMode = StageScaleMode.NO_SCALE;
- stage.align = StageAlign.TOP_LEFT;
- // テキストレイアウト読み込み
- var loader:URLLoader = new URLLoader();
- loader.load(new URLRequest(MARKUP));
- loader.addEventListener(Event.COMPLETE,completeHandler);
- loader.addEventListener(IOErrorEvent.IO_ERROR,ioErrorHandler);
- }
- // 読み込み完了
- private function completeHandler(e:Event):void
- {
- _textFlow = TextFilter.importToFlow(e.target.data, TextFilter.TEXT_LAYOUT_FORMAT);
- _textFlow.flowComposer.addController(new DisplayObjectContainerController(this,stage.stageWidth, stage.stageHeight));
- _textFlow.flowComposer.updateAllContainers();
- }
- // 読み込みエラー
- private function ioErrorHandler(e:IOErrorEvent):void
- {
- var markup:String = "<?xml version='1.0' encoding='utf-8'?><flow:TextFlow paddingRight='20' paddingTop='20' paddingLeft='0' blockProgression='rl' whiteSpaceCollapse='preserve' xmlns:flow='http://ns.adobe.com/textLayout/2008'><flow:p><flow:span renderingMode='normal' locale='ja' color='0xff0000' trackingRight='0' fontSize='20' fontFamily='_ゴシック'>読み込み失敗</flow:span></flow:p></flow:TextFlow>";
- _textFlow = TextFilter.importToFlow(markup, TextFilter.TEXT_LAYOUT_FORMAT);
- _textFlow.flowComposer.addController(new DisplayObjectContainerController(this,stage.stageWidth, stage.stageHeight));
- _textFlow.flowComposer.updateAllContainers();
- }
- }
- }
notice: 


