【问题标题】:Autodesk Forge Viewer Markup Large Text Gets Cut OffAutodesk Forge 查看器标记大文本被截断
【发布时间】: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


    【解决方案1】:

    尝试增加文本框的大小 - 您可以订阅 MARKUPCORE.EVENT_HISTORY_CHANGED 事件来捕获更改后的文本框并设置其大小:

    编辑:为什么不把所有的转换都移到事件回调中,这样我们就不需要捎带这个看起来有点老套的插件了

    markupExt.addEventListener( Autodesk.Extensions.Markup.Core.EVENT_HISTORY_CHANGED, e=>{
    
       const textMarkup = markupExt.getMarkup(e.data.targetId);
       //check 'textMarkup.type' and 'label' is for textbox
       const currentStyles = textMarkup.getStyle();
    
       // be sure to wrap this in a control flow to check and only set size right after the textbox is first created to prevent interference with changes made by user
    
       textMarkup.setSize(textMarkup.position, textMarkup.size.x*3, textMarkup.size.y*3) 
    
       currentStyles['stroke-width'] *= 3, currentStyles['font-size'] *= 3;
       textMarkup.setStyle(currentStyles);
    });
    
    

    【讨论】:

    • 我假设 markupExt 是 MarkupsCore 扩展 Autodesk.Viewing.MarkupsCore,但我得到一个异常说它没有 get 方法。知道我错过了什么吗?
    • 谢谢! - 不幸的是它没有解决问题。也许我实施错了? (请在问题中查看我的更新 1)
    • 为什么不把所有的转换都移到事件回调中,这样我们就不需要捎带这个看起来有点老套的插件——见编辑
    • 你可以尝试在你的例子中写一些带有后代的文本,看看它是否会切断后代部分? “233”对我来说也很好用,因为这里的所有文字都是“在线上”可以这么说的。我也尝试更改以在历史更改事件中设置字体大小,但不幸的是,这并没有改变任何东西:(
    • 好的,这很有趣。我想那时我将不得不进行更多实验,以弄清楚为什么它对我不起作用。我认为缩放级别也会以某种方式干扰这一点
    猜你喜欢
    • 2018-03-16
    • 2021-11-12
    • 1970-01-01
    • 2021-05-30
    • 2020-03-08
    • 2021-09-19
    • 2020-10-23
    • 2017-01-07
    • 2018-06-11
    相关资源
    最近更新 更多