feathersui / feathersui-starling

User interface components for Starling Framework and Adobe AIR
https://feathersui.com/learn/as3-starling/
Other
914 stars 386 forks source link

how to creat Vertica TextBlockTextRenderer? #1796

Closed feipinxiang closed 4 years ago

feipinxiang commented 4 years ago

I want to achieve the effect of Classical Chinese. I used TextBlockTextRenderer.lineRotation = TextRotation.ROTATE_90 to get the result is wrong. This text is read from top to bottom, right to left, one Chinese character by one Chinese character. chinese The text reading order in the picture is 關關雎鳩,在河之洲。窈窕淑女,君子好逑。參差荇菜,左右流之。窈窕淑女,寤寐求之。求之不得,寤寐思服。悠哉悠哉,輾轉反側。參差荇菜,左右采之。窈窕淑女,琴瑟友之。參差荇菜,左右芼之。窈窕淑女,鐘鼓樂之。……

joshtynjala commented 4 years ago

Perhaps you can set lineRotation on the TextBlockTextRenderer, and also set textRotation on the ElementFormat.

feipinxiang commented 4 years ago

Perhaps you can set lineRotation on the TextBlockTextRenderer, and also set textRotation on the ElementFormat.

Yes, I already tried it. If I used tf_block.lineRotation = TextRotation.ROTATE_90, get result like this.All character lined up and overlapped. 2019-12-19_121138.jpg

If use tf_block.lineRotation = TextRotation.ROTATE_90 and _format.textRotation = TextRotation.ROTATE_90, the TextBlockTextRenderer is invisible. I don't see any code about vertical alignment in TextBlockTextRenderer source code.

var _fontColor:uint = 0x0;
var _fontSize:uint = 30;
var _fontFamily:String = "微软雅黑,Arial,_sans";

var _font:FontDescription = new FontDescription();
_font.fontLookup = FontLookup.DEVICE;
_font.fontName = _fontFamily;
//_font.cffHinting = CFFHinting.HORIZONTAL_STEM;
//_font.renderingMode = RenderingMode.CFF;
//_font.fontWeight = _fontWeight;
//_font.fontPosture = _fontPosture;

var _format:ElementFormat = new ElementFormat();
_format.color = _fontColor;
_format.fontSize = _fontSize;
//_format.fontDescription = _font;
_format.textRotation = TextRotation.AUTO;
//_format.textRotation = TextRotation.ROTATE_90;
_format.breakOpportunity = BreakOpportunity.ANY;
_format.locale = "zh";

var tf_block:TextBlockTextRenderer = new TextBlockTextRenderer();
tf_block.elementFormat = _format;
tf_block.textAlign = HorizontalAlign.LEFT;
tf_block.wordWrap = true;
tf_block.lineRotation = TextRotation.ROTATE_90;
tf_block.textJustifier = new EastAsianJustifier("ja", LineJustification.ALL_BUT_MANDATORY_BREAK, JustificationStyle.PUSH_IN_KINSOKU);

addChild(tf_block);

tf_block.width = 100;
tf_block.text = " 關關雎鳩,在河之洲。窈窕淑女,君子好逑。參差荇菜,左右流之。窈窕淑女,寤寐求之。求之不得,寤寐思服。悠哉悠哉,輾轉反側。參差荇菜,左右采之。窈窕淑女,琴瑟友之。參差荇菜,左右芼之。窈窕淑女,鐘鼓樂之。";
joshtynjala commented 4 years ago

I'm afraid that I don't have any more suggestions. TextBlockTextRenderer is basically just a wrapper around Flash Text Engine, so you should look at Adobe's documentation for FTE for help.

You are also welcome to start a forum thread to potentially get help from the community.

jamikado commented 4 years ago

One suggestion would be to take a look at the sample code in my old extension that also wrapped FTE. https://wiki.starling-framework.org/extensions/tlfsprite

https://gist.github.com/jamikado/3167820#file_tlf_sprite_snippets.as You don't need to switch to TLFSprite but just try and set the same FTE settings on the text formatter when using TextBlockTextRenderer to use east asian justifucation styles.... here is a snippet that did the vertical layout sample:

EDIT: On second thought this might be using TLF APIs so you might be better off switching to use TLFTextRenderer instead https://forum.starling-framework.org/d/7825-feathers-tlf-text-renderer

// Define east asian ideographic layout and formatting
// along with enforced composition height limit
textLayoutFormat = new TextLayoutFormat();
// define Japanese text in a string of Unicode characters
var jaText:String = String.fromCharCode(
    0x30AF, 0x30ED, 0x30B9, 0x30D7, 0x30E9, 0x30C3, 0x30C8, 0x30D5, 
    0x30A9, 0x30FC, 0x30E0, 0x4E0A, 0x3067, 0x518D, 0x751F, 0x53EF, 
    0x80FD, 0x306A) + 
    "Flash Video" +
    String.fromCharCode(
        0x3092, 0x914D, 0x4FE1, 0x3001, 0x653F, 0x5E9C, 0x6700, 0x65B0, 
        0x60C5, 0x5831, 0x3092, 0x3088, 0x308A, 0x591A, 0x304F, 0x306E, 
        0x56FD, 0x6C11, 0x306B, 0x9AD8, 0x54C1, 0x8CEA, 0x306A, 0x753B, 
        0x50CF, 0x3067, 0x7C21, 0x5358, 0x304B, 0x3064, 0x30EA, 0x30A2, 
        0x30EB, 0x30BF, 0x30A4, 0x30E0, 0x306B, 0x63D0, 0x4F9B, 0x3059, 
        0x308B, 0x3053, 0x3068, 0x304C, 0x53EF, 0x80FD, 0x306B, 0x306A, 
        0x308A, 0x307e, 0x3057, 0x305F, 0x3002);
textLayoutFormat.locale = "ja";
if (Capabilities.os.search("Mac OS") > -1) 
    textLayoutFormat.fontFamily = String.fromCharCode(0x5C0F, 0x585A, 0x660E, 0x671D) + " Pro R"; // "Kozuka Mincho Pro R"
else 
    textLayoutFormat.fontFamily = "Kozuka Mincho Pro R";
// specify right-to-left block progression, east Asian justification, and top vertical alignment
textLayoutFormat.blockProgression = BlockProgression.RL;
textLayoutFormat.justificationRule = JustificationRule.EAST_ASIAN;
textLayoutFormat.verticalAlign = VerticalAlign.TOP;
textLayoutFormat.fontSize = 18;