简体   繁体   中英

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. 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.

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:

字体大小作为样式规则

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).

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). The CSS file nv.d3.css had a style rule for all svg text, which ended up overwriting the svg text from the viewer. Updating the NVD3 library solved the issue.

The old one had this, which applied to all svgs on the document: 旧的 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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