簡體   English   中英

導入自定義fonts轉JSF

[英]Import custom fonts to JSF

我無法將自定義 fonts 導入我的 JSF 頁面。 項目結構如下所示:項目結構截圖

我試圖在我的 styles.css 中寫下以下內容:

@font-face {
    font-family: "Gotham Pro Bold";
    src: url('#{resource["fonts/GothaProBol.otf"]}');
}

但它不起作用。 它被編譯為/javax.faces.resource/fonts/GothaProBol.otf.xhtml ,但字體不在javax.faces.resource中,我不知道為什么它附加.xhtml

下列:

src: url("#{facesContext.externalContext.requestContextPath}/resources/fonts/GothaProBol.otf");

被編譯成

src: url("/resources/fonts/GothaProBol.otf");

但它也不起作用。

如何正確導入 fonts?

提前致謝。

這樣做是使用OmniFaces進行的

  1. 添加了依賴項pom.xml ):

    <dependency> <groupId>org.omnifaces</groupId> <artifactId>omnifaces</artifactId> <version>1.8.1</version> </dependency>

  2. faces-config.xml添加了OmniFaces的資源處理程序:

    <application> <resource-handler> org.omnifaces.resourcehandler.UnmappedResourceHandler </resource-handler> </application>

  3. /javax.faces.resource/*映射到FacesServlet如下( web.xml ):

    <servlet> <servlet-name>Faces Servlet</servlet-name> <servlet-class>javax.faces.webapp.FacesServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>Faces Servlet</servlet-name> <url-pattern>/javax.faces.resource/*</url-pattern> <url-pattern>*.xhtml</url-pattern> </servlet-mapping>

  4. 在CSS中使用#{resource["<path>"]} ,如下所示:

    @font-face { font-family: "Gotham Pro Bold"; src: url('#{resource["fonts/GothaProBol.otf"]}'); }

我有同樣的問題。 這個 URL 有效

    @font-face {
    font-family: "MyFont";
    src:
    url("mfont/mfont.ttf.xhtml?ln=fonts")
    format("truetype")
    }

該文件位於“/resources/fonts/mfont/mfont.ttf”

另請注意,css 文件本身包含在使用 h:outputStylesheet 中(因為字體 url 需要相對於 css)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM