简体   繁体   English

在 Forge Viewer 的标记中为文本设置“字体大小”不起作用,但使用 CSS 设置样式可以

[英]Setting 'font-size' for text in Markup of Forge Viewer does not work, but styling with CSS does

I'm trying to display text using the Markup tool of Autodesk Forge Viewer 7.84, but the font-size style is being ignored.我正在尝试使用 Autodesk Forge Viewer 7.84 的标记工具显示文本,但忽略了字体大小样式。 It works when I add a css style for font-size to the <text> element, but the font-size attribute of the <text> does not work.当我将字体大小的 css 样式添加到 <text> 元素时它起作用,但是 <text> 的 font-size 属性不起作用。

This is the code to activate the tool:这是激活该工具的代码:

var toolInstance = new Autodesk.Viewing.Extensions.Markups.Core.EditModeText(this.core);
this.core.changeEditMode(toolInstance);
var markup = this.core.getSelection();
var style = markup ? markup.getStyle() : this.core.getStyle();
style['font-size'] = styleValue;
this.core.setStyle(style);

Also tried this other code from another question:还尝试了另一个问题中的其他代码:

markupExt.enterEditMode();
 var text1= new Autodesk.Viewing.Extensions.Markups.Core.CreateText(markupExt,2333, 
 {x:10,y:10}, {x:100,y:100},'My Test String Small', {"font-size":5})
  text1.execute();

Both options generate the correct element with the 'font-size' attribute set to the correct value, but the size of the text markup is not applied.这两个选项都会生成正确的元素,并将“字体大小”属性设置为正确的值,但不会应用文本标记的大小。

字体大小作为属性

But if I edit the <text> and add a style rule to the element, it works:但是,如果我编辑 <text> 并向元素添加样式规则,它会起作用:

字体大小作为样式规则

I don't want to create an extension or an override to the Markup scripts just to correct the text, by adding the style rule to every <text> element, as I think there is something wrong with either the Markup code, or somewhere on the Viewer/page setup (although the SVG specifications for <text> state that font-size should work).我不想通过将样式规则添加到每个 <text> 元素来创建标记脚本的扩展或覆盖来更正文本,因为我认为标记代码或某处有问题查看器/页面设置(尽管 SVG 规范 <text> state 字体大小应该有效)。

So the question is: how can I set the font-size of the text in Markup from code, preferably without overriding Viewer scripts?所以问题是:如何从代码中设置标记中文本的字体大小,最好不要覆盖查看器脚本?

The issue was a conflict with an old version of the NV.D3 library (to create charts and graphs).问题是与旧版本的 NV.D3 库(用于创建图表和图形)发生冲突。 The CSS file nv.d3.css had a style rule for all svg text, which ended up overwriting the svg text from the viewer. CSS 文件 nv.d3.css 对所有 svg 文本都有一个样式规则,最终会覆盖查看器中的 svg 文本。 Updating the NVD3 library solved the issue.更新 NVD3 库解决了这个问题。

The old one had this, which applied to all svgs on the document:旧的有这个,它适用于文档中的所有 svgs: 旧的 nv.d3.css

The updated one encapsulated it in its own namespace:更新后的将其封装在自己的命名空间中: 更新了 nv.d3.css

Make sure no other CSS has global rules to SVG, since it can conflict with the Markup tools of the Viewer.确保没有其他 CSS 具有针对 SVG 的全局规则,因为它可能与查看器的标记工具冲突。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM