首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在sap ui5富文本编辑器中设置默认字体系列和字体大小

在sap ui5富文本编辑器中设置默认字体系列和字体大小
EN

Stack Overflow用户
提问于 2020-04-28 18:52:34
回答 1查看 565关注 0票数 1

通过以下代码,我能够在sap ui5中使用富文本编辑器。

代码语言:javascript
复制
    sap.ui.require(["sap/ui/richtexteditor/RichTextEditor", "sap/ui/richtexteditor/EditorType"],
                    function (RTE, EditorType) {
                var oRichTextEditor = new RTE("myRTE", {
                    editorType: EditorType.TinyMCE4,
                    width: "100%",
                    height: "200px",
                    customToolbar: true,
                    showGroupFont: true,
                    showGroupLink: true,
                    showGroupInsert: true,
                    value: sHtmlValue,
                    ready: function () {
                        this.addButtonGroup("styleselect").addButtonGroup("table");
                    }
                });

                that.getView().byId("textarea").addContent(oRichTextEditor);
            });

现在客户端希望将默认字体系列和字体大小设置为Arial,并将大小设置为11

您能告诉我如何设置这些默认值吗?

EN

回答 1

Stack Overflow用户

发布于 2020-04-28 20:42:31

开箱即用的RTE不支持11点。您必须增强有效字体大小的可用列表。

然后,在beforeEditorInit事件中,可以应用您的设置

代码语言:javascript
复制
sap.ui.require([
    "sap/ui/richtexteditor/RichTextEditor",
    "sap/ui/richtexteditor/EditorType",
    "sap/ui/richtexteditor/library"
], (RTE, EditorType, RTELibrary) => {
    // RTE only supports a few FontSizes out of the box. Add your additional FontSize here
    const aFontSizes = RTELibrary.EditorCommands.FontSize;
    aFontSizes.push(11);
    aFontSizes.sort((a, b) => a - b);

    const oRichTextEditor = new RTE("myRTE", {
        editorType: EditorType.TinyMCE4,
        customToolbar: true,
        showGroupFont: true,
        beforeEditorInit: function (oEvent) {
            const oConfig = oEvent.getParameter("configuration");
            const fnSuperSetup = oConfig.setup;
            oConfig.setup = (oEditor) => {
                // if you want you can call the original setup method here
                fnSuperSetup(oEditor);
                oEditor.on("init", function () {
                    oEditor.execCommand("FontName", false, "arial, helvetica, sans-serif");
                    oEditor.execCommand("FontSize", false, "11pt");
                });
            };
        }
    });

    this.getView().byId("mainPage").addContent(oRichTextEditor);
});

一个小缺点:下拉菜单没有选择正确的值(11磅)。但您可以在源代码中看到它实际上是11pt:

也许其他人知道为什么调用execCommand时dropdown不能正确更新(它只适用于比插入的元素小的元素)。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61478462

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档