Codename One – 在TextField中使用来自外部ttf文件的Material Design Icons字体

huangapple 未分类评论48阅读模式
英文:

Codename One - Using Material Design Icons font in TextField from external ttf file

问题

I am using Codename One for a project of mine.

我正在使用Codename One进行我的一个项目。

I have to load the material design icons font.

我需要加载Material Design图标字体。

I know it is included in Codename One fonts but I need to populate the text field writing the original names, like on the web.

我知道它包含在Codename One字体中,但我需要填充文本字段,以原始名称编写,就像在网页上一样。

I have to write, for example, "3d_rotation", instead of a unicode sequence.

我必须编写,例如,“3d_rotation”,而不是Unicode序列。

//font file is in the src folder, it is recognized because a name different from "Material Icons" gives a sort of warning.
//字体文件位于src文件夹中,它被识别出来,因为与“Material Icons”不同的名称会产生一种警告。

Font materialFont = Font.createTrueTypeFont("Material Icons", "materialiconsregular.ttf").
derive(40, Font.STYLE_PLAIN);

textField.getUnselectedStyle().setFont(materialFont);
textField.getSelectedStyle().setFont(materialFont);

String string = "3d_rotation";

textField.setText(string);
System.out.println(string); //OK it's "3d_rotation"
mainLayout.add(textField);
//results in a blank textField with hidden chars like a "3d_rotation" long string.
//导致一个空的文本字段,其中包含像"3d_rotation"一样的隐藏字符。

At runtime I see that the text field is populated with the string and not the glyph, and the string is blank, like white characters, I just can move through them with the cursor.

在运行时,我看到文本字段中填充了字符串而不是字形,并且该字符串是空白的,就像白色字符一样,我只能用光标在其中移动。

What's wrong?
发生了什么问题?

英文:

I am using Codename One for a project of mine.

I have to load the material design icons font.

I know it is included in Codename One fonts but I need to populate the text field writing the original names, like on the web.

I have to write, for example, "3d_rotation", instead of a unicode sequence.

//font file is in the src folder, it is recognized because a name different from "Material Icons" gives a sort of warning.

 Font materialFont =Font.createTrueTypeFont("Material Icons", "materialiconsregular.ttf").
        derive(40, Font.STYLE_PLAIN);

    textField.getUnselectedStyle().setFont(materialFont);
    textField.getSelectedStyle().setFont(materialFont);
    
String string="3d_rotation";

    textField.setText(string);
System.out.println(string); //OK it's "3d_rotation"
mainLayout.add(textField);
//results in a blank textField with hidden chars like a "3d_rotation" long string.

At runtime I see that the text field is populated with the string and not the glyph, and the string is blank, like white characters, I just can move through them with the cursor.

What's wrong?

huangapple
  • 本文由 发表于 2020年6月29日 14:59:38
  • 转载请务必保留本文链接:https://java.coder-hub.com/62632793.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定