小编ADP*_*123的帖子

在 Google Web Toolkit 中使用自定义字体

我想在 Google Web Toolkit Web 应用程序中使用自定义字体。我已尝试遵循https://code.google.com/p/gwt-webfonts/ 上提供的文档/代码,但我仍然遇到问题。我不完全明白我需要做什么。

我有:

  1. 在我的项目中包含 gwt-webfonts-0.1.jar 文件依赖项
  2. 向我的 gwt.xml 文件添加了一个包含依赖项:
  3. 创建了 ClientBundle 的扩展:

    import com.google.gwt.dev.javac.testing.impl.MockResource;
    import com.google.gwt.dev.resource.impl.FileResource;
    import com.google.gwt.resources.client.ClientBundle;
    import com.google.gwt.resources.client.ClientBundle.Source;
    import com.google.gwt.resources.client.CssResource;
    import com.google.gwt.core.client.GWT;
    
    public interface MainClientBundle extends ClientBundle
    {
       @Source("LesJoursHeureux.otf")
       public FontResource myFont();
    
    };
    
    Run Code Online (Sandbox Code Playgroud)
  4. 在我的 ui.xml 文件中,我包含了对字体资源的引用:

    <ui:style type='com.example.TopMenuView.TopMenuViewStyle'>
        .maintitle {
            font-family: value('myFont.getFontName');
        }
    </ui:style>
    
    Run Code Online (Sandbox Code Playgroud)
  5. 这是我不知道该怎么做的地方。在我的 TopMenuView.java 类中,我包含了这个片段:

    private static MainClientBundle MY_RESOURCES = GWT.create(MainClientBundle.class);
    {
        MY_RESOURCES.myFont().ensureInjected();
    }
    
    Run Code Online (Sandbox Code Playgroud)
  6. 当我尝试构建项目时,我收到此错误:

    Creating assignment for style()
         [java]  Performing substitution in node font-family : .....
         [java]  [ERROR] …
    Run Code Online (Sandbox Code Playgroud)

java gwt

5
推荐指数
1
解决办法
2602
查看次数

标签 统计

gwt ×1

java ×1