mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-06-22 08:15:35 +00:00
#803 Align text (left, right, center) in Define*Text
This commit is contained in:
@@ -35,6 +35,7 @@ import com.jpexs.decompiler.flash.tags.dynamictext.SameStyleTextRecord;
|
||||
import com.jpexs.decompiler.flash.tags.dynamictext.TextStyle;
|
||||
import com.jpexs.decompiler.flash.tags.dynamictext.Word;
|
||||
import com.jpexs.decompiler.flash.tags.text.ParsedSymbol;
|
||||
import com.jpexs.decompiler.flash.tags.text.TextAlign;
|
||||
import com.jpexs.decompiler.flash.tags.text.TextLexer;
|
||||
import com.jpexs.decompiler.flash.tags.text.TextParseException;
|
||||
import com.jpexs.decompiler.flash.types.BasicType;
|
||||
@@ -663,6 +664,11 @@ public class DefineEditTextTag extends TextTag {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean alignText(TextAlign textAlign) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RECT getRect(Set<BoundedTag> added) {
|
||||
return bounds;
|
||||
|
||||
@@ -30,6 +30,7 @@ import com.jpexs.decompiler.flash.tags.base.MissingCharacterHandler;
|
||||
import com.jpexs.decompiler.flash.tags.base.RenderContext;
|
||||
import com.jpexs.decompiler.flash.tags.base.TextTag;
|
||||
import com.jpexs.decompiler.flash.tags.text.ParsedSymbol;
|
||||
import com.jpexs.decompiler.flash.tags.text.TextAlign;
|
||||
import com.jpexs.decompiler.flash.tags.text.TextLexer;
|
||||
import com.jpexs.decompiler.flash.tags.text.TextParseException;
|
||||
import com.jpexs.decompiler.flash.types.BasicType;
|
||||
@@ -444,6 +445,41 @@ public class DefineText2Tag extends TextTag {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean alignText(TextAlign textAlign) {
|
||||
int maxWidth = 0;
|
||||
for (TEXTRECORD tr : textRecords) {
|
||||
int width = tr.getTotalAdvance();
|
||||
|
||||
if (width > maxWidth) {
|
||||
maxWidth = width;
|
||||
}
|
||||
}
|
||||
|
||||
for (TEXTRECORD tr : textRecords) {
|
||||
int width = tr.getTotalAdvance();
|
||||
switch (textAlign) {
|
||||
case LEFT:
|
||||
tr.xOffset = 0;
|
||||
tr.styleFlagsHasXOffset = true;
|
||||
break;
|
||||
case CENTER:
|
||||
tr.xOffset = (maxWidth - width) / 2;
|
||||
tr.styleFlagsHasXOffset = true;
|
||||
break;
|
||||
case RIGHT:
|
||||
tr.xOffset = maxWidth - width;
|
||||
tr.styleFlagsHasXOffset = true;
|
||||
break;
|
||||
case JUSTIFY:
|
||||
tr.xOffset = 0;
|
||||
tr.styleFlagsHasXOffset = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RECT getRect(Set<BoundedTag> added) {
|
||||
return textBounds;
|
||||
|
||||
@@ -31,6 +31,7 @@ import com.jpexs.decompiler.flash.tags.base.MissingCharacterHandler;
|
||||
import com.jpexs.decompiler.flash.tags.base.RenderContext;
|
||||
import com.jpexs.decompiler.flash.tags.base.TextTag;
|
||||
import com.jpexs.decompiler.flash.tags.text.ParsedSymbol;
|
||||
import com.jpexs.decompiler.flash.tags.text.TextAlign;
|
||||
import com.jpexs.decompiler.flash.tags.text.TextLexer;
|
||||
import com.jpexs.decompiler.flash.tags.text.TextParseException;
|
||||
import com.jpexs.decompiler.flash.types.BasicType;
|
||||
@@ -425,7 +426,6 @@ public class DefineTextTag extends TextTag {
|
||||
tr.glyphEntries[i].glyphAdvance = advance;
|
||||
|
||||
currentX += advance;
|
||||
|
||||
}
|
||||
|
||||
if (currentX > maxX) {
|
||||
@@ -453,6 +453,41 @@ public class DefineTextTag extends TextTag {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean alignText(TextAlign textAlign) {
|
||||
int maxWidth = 0;
|
||||
for (TEXTRECORD tr : textRecords) {
|
||||
int width = tr.getTotalAdvance();
|
||||
|
||||
if (width > maxWidth) {
|
||||
maxWidth = width;
|
||||
}
|
||||
}
|
||||
|
||||
for (TEXTRECORD tr : textRecords) {
|
||||
int width = tr.getTotalAdvance();
|
||||
switch (textAlign) {
|
||||
case LEFT:
|
||||
tr.xOffset = 0;
|
||||
tr.styleFlagsHasXOffset = true;
|
||||
break;
|
||||
case CENTER:
|
||||
tr.xOffset = (maxWidth - width) / 2;
|
||||
tr.styleFlagsHasXOffset = true;
|
||||
break;
|
||||
case RIGHT:
|
||||
tr.xOffset = maxWidth - width;
|
||||
tr.styleFlagsHasXOffset = true;
|
||||
break;
|
||||
case JUSTIFY:
|
||||
tr.xOffset = 0;
|
||||
tr.styleFlagsHasXOffset = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCharacterId() {
|
||||
return characterID;
|
||||
|
||||
@@ -28,6 +28,7 @@ import com.jpexs.decompiler.flash.exporters.shape.CanvasShapeExporter;
|
||||
import com.jpexs.decompiler.flash.exporters.shape.SVGShapeExporter;
|
||||
import com.jpexs.decompiler.flash.importers.TextImportResizeTextBoundsMode;
|
||||
import com.jpexs.decompiler.flash.tags.Tag;
|
||||
import com.jpexs.decompiler.flash.tags.text.TextAlign;
|
||||
import com.jpexs.decompiler.flash.tags.text.TextParseException;
|
||||
import com.jpexs.decompiler.flash.types.ColorTransform;
|
||||
import com.jpexs.decompiler.flash.types.FILLSTYLE;
|
||||
@@ -85,6 +86,8 @@ public abstract class TextTag extends CharacterTag implements DrawableTag {
|
||||
// use the texts from the "texts" argument when it is not null
|
||||
public abstract boolean setFormattedText(MissingCharacterHandler missingCharHandler, String formattedText, String[] texts) throws TextParseException;
|
||||
|
||||
public abstract boolean alignText(TextAlign textAlign);
|
||||
|
||||
@Override
|
||||
public abstract int getCharacterId();
|
||||
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright (C) 2010-2015 JPEXS, All rights reserved.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3.0 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library.
|
||||
*/
|
||||
package com.jpexs.decompiler.flash.tags.text;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author JPEXS
|
||||
*/
|
||||
public enum TextAlign {
|
||||
|
||||
LEFT, RIGHT, CENTER, JUSTIFY
|
||||
}
|
||||
@@ -70,4 +70,12 @@ public class TEXTRECORD implements Serializable {
|
||||
}
|
||||
return ret.toString();
|
||||
}
|
||||
|
||||
public int getTotalAdvance() {
|
||||
int width = 0;
|
||||
for (GLYPHENTRY ge : glyphEntries) {
|
||||
width += ge.glyphAdvance;
|
||||
}
|
||||
return width;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user