text align fixed with external viewer

This commit is contained in:
2015-02-18 21:12:12 +01:00
parent 2aba948769
commit f7541748ac
3 changed files with 37 additions and 60 deletions
@@ -447,36 +447,8 @@ public class DefineText2Tag extends TextTag {
@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;
}
}
alignText(textRecords, textAlign);
setModified(true);
return true;
}
@@ -455,36 +455,8 @@ public class DefineTextTag extends TextTag {
@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;
}
}
alignText(textRecords, textAlign);
setModified(true);
return true;
}
@@ -117,6 +117,39 @@ public abstract class TextTag extends CharacterTag implements DrawableTag {
}
}
public static void alignText(List<TEXTRECORD> textRecords, 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;
}
}
}
public static Map<String, Object> getTextRecordsAttributes(List<TEXTRECORD> list, List<Tag> tags) {
Map<String, Object> att = new HashMap<>();
RECT textBounds = new RECT(Integer.MAX_VALUE, Integer.MIN_VALUE, Integer.MAX_VALUE, Integer.MIN_VALUE);