use of net.heartsome.cat.common.innertag.InnerTagBean in project translationstudio8 by heartsome.
the class XGridCellRenderer method drawInnerTag.
protected void drawInnerTag(GC gc, TextLayout layout) {
String displayStr = layout.getText();
List<InnerTagBean> innerTagBeans = innerTagFactory.getInnerTagBeans();
Rectangle bounds = getBounds();
for (InnerTagBean innerTagBean : innerTagBeans) {
String placeHolder = placeHolderBuilder.getPlaceHolder(innerTagBeans, innerTagBeans.indexOf(innerTagBean));
int start = displayStr.indexOf(placeHolder);
if (start == -1) {
continue;
}
if (gc != null) {
Point p = layout.getLocation(start, false);
int x = bounds.x + p.x + leftMargin;
x += SEGMENT_LINE_SPACING;
Point tagSize = tagRender.calculateTagSize(innerTagBean);
int lineIdx = layout.getLineIndex(start);
Rectangle r = layout.getLineBounds(lineIdx);
int y = bounds.y + p.y + topMargin + r.height / 2 - tagSize.y / 2;
tagRender.draw(gc, innerTagBean, x, y - layout.getAscent());
}
}
}
use of net.heartsome.cat.common.innertag.InnerTagBean in project translationstudio8 by heartsome.
the class SegmentViewer method setText.
/**
* @see net.heartsome.cat.ts.ui.innertag.ISegmentViewer#setText(java.lang.String)
*/
public void setText(String text) {
// 重置缓存的标记。
reset();
if (isSource()) {
// 当前是源文本
IInnerTagFactory innerTagFactory = new XliffInnerTagFactory(text, placeHolderBuilder);
List<InnerTagBean> innerTagBeans = innerTagFactory.getInnerTagBeans();
for (InnerTagBean innerTagBean : innerTagBeans) {
InnerTag innerTag = InnerTagUtil.createInnerTagControl(getTextWidget(), innerTagBean, tagStyle);
innerTag.setVisible(false);
innerTagCacheList.add(innerTag);
sourceMaxTagIndex = Math.max(sourceMaxTagIndex, innerTagBean.getIndex());
}
// 记录错误标记的起始,source 中所有标记都不是错误标记。
errorTagStart = innerTagCacheList.size();
text = innerTagFactory.getText();
} else {
// 当前是目标文本
XliffInnerTagFactory innerTagFactory = new XliffInnerTagFactory(source, placeHolderBuilder);
// source 中包含的内部标记。
List<InnerTagBean> sourceInnerTagBeans = innerTagFactory.getInnerTagBeans();
// 记录错误标记的起始,source 中所有标记都不是错误标记。
errorTagStart = sourceInnerTagBeans.size();
// 如果当前是 Target,就先记录 Source 中的最大索引。
for (InnerTagBean innerTagBean : sourceInnerTagBeans) {
// 记录source中内部标记的最大标记索引。
sourceMaxTagIndex = Math.max(sourceMaxTagIndex, innerTagBean.getIndex());
}
text = innerTagFactory.parseInnerTag(text, true);
List<InnerTagBean> innerTagBeans = innerTagFactory.getInnerTagBeans();
for (InnerTagBean innerTagBean : innerTagBeans) {
InnerTag innerTag = InnerTagUtil.createInnerTagControl(getTextWidget(), innerTagBean, tagStyle);
innerTag.setVisible(false);
innerTagCacheList.add(innerTag);
}
}
getTextWidget().setText(resetRegularString(text));
}
use of net.heartsome.cat.common.innertag.InnerTagBean in project translationstudio8 by heartsome.
the class IntelligentTagPrcessor method processNextStandloneTag.
private static StringBuilder processNextStandloneTag(String srcFullText, List<InnerTagBean> srcTags, int startTagsOffset) {
StringBuilder sb = new StringBuilder();
if (startTagsOffset >= srcTags.size()) {
return sb;
}
String firstTagCnt = srcTags.get(startTagsOffset).getContent();
int i = startTagsOffset + 1;
int offset = srcFullText.indexOf(firstTagCnt) + firstTagCnt.length();
while (i < srcTags.size()) {
InnerTagBean nextTag = srcTags.get(i);
String nextTagCnt = nextTag.getContent();
if (nextTag.getType() == TagType.STANDALONE && srcFullText.indexOf(nextTagCnt) == offset) {
sb.append(nextTagCnt);
offset += nextTagCnt.length();
i++;
} else {
break;
}
}
return sb;
}
use of net.heartsome.cat.common.innertag.InnerTagBean in project translationstudio8 by heartsome.
the class IntelligentTagPrcessor method processPreStandloneTag.
private static StringBuilder processPreStandloneTag(String targetText, String srcFullText, List<InnerTagBean> srcTags, int startTagsOffset) {
StringBuilder sb = new StringBuilder();
if (startTagsOffset >= srcTags.size()) {
return sb;
}
String lastTagCnt = srcTags.get(startTagsOffset).getContent();
int i = startTagsOffset - 1;
int offset = srcFullText.lastIndexOf(lastTagCnt);
while (i >= 0) {
InnerTagBean preTag = srcTags.get(i);
String preTagCnt = preTag.getContent();
if (preTag.getType() == TagType.STANDALONE && targetText.indexOf(preTagCnt) == -1 && srcFullText.lastIndexOf(preTagCnt) + preTagCnt.length() == offset) {
sb.insert(0, preTagCnt);
offset = srcFullText.lastIndexOf(preTagCnt);
i--;
} else {
break;
}
}
return sb;
}
Aggregations