【发布时间】:2020-01-26 16:23:54
【问题描述】:
在 Forge 查看器中加载 3D 模型时,我们会增加默认标记笔画和文本大小,如下所示:
proto.onEditModeChange = function() {
if (this.is2d) {
this.setStyles(0.0040, 0.02);
} else {
var currentStyles = this.core.getStyle();
this.setStyles(currentStyles['stroke-width'] * 3, currentStyles['font-size'] * 3);
}
};
proto.setStyles = function (strokeWidth, fontSize) {
var styleObject = this.core.getStyle();
styleObject['stroke-width'] = strokeWidth;
styleObject['font-size'] = fontSize;
this.core.setStyle(styleObject);
};
所以我们得到了笔画宽度和字体大小的默认样式,并将大小乘以 3,因为我们认为这是一个更好的默认大小。对于 2D 文件,我们硬编码了适合我们的大小。
我们现在在使用 3D 文件时遇到的问题是,当添加包含 descender 的标记文本时,下降部分会被切断。这是我写“pgqjy”的例子:
较小的字体不会出现此问题。如何防止文字被截断?
我们使用 Forge Viewer 6.*
更新 1
感谢 Bryan 建议我在创建标记后编辑它的大小。不幸的是,它并没有解决问题 - 文本仍然被截断。似乎增加文本框的高度只是在文本上方增加了更多的空白。这就是我增加高度的方法:
proto.onHistoryChanged = function(e) {
if (e.data.action === "execute" && e.data.targetId > 0) {
var markup = this.core.getMarkup(e.data.targetId);
if (markup && markup.type === "label" && markup.currentTextLines && markup.currentTextLines.length > 0) {
markup.setSize(markup.position, markup.size.x, markup.currentTextLines.length * markup.lineHeight);
}
}
};
【问题讨论】:
标签: autodesk-forge