2017-06-19 88 views
0

我下載了名爲「Clunk」的TTF字體,我試圖將它應用於某些文本。爲什麼TTF字體不能在我的瀏覽器中工作?

下面是我使用的代碼:

<html> 
<head> 
<style> 
@font-face { 
    font-family: clunk; 
    src: url('clunk.ttf'); 
} 

h1 { 
    font-family: clunk; 
} 
</style> 
</head> 
<body> 
<h1 id="logo">Test</h1> 
</body> 
</html> 

這似乎並不工作和Chrome是給我兩個錯誤:

Failed to decode downloaded font: (path to the file) 
OTS parsing error: incorrect entrySelector for table directory 

在Firefox中,這是出現錯誤:

downloadable font: bad search range (font-family: "clunk" style:normal weight:normal stretch:normal src index:0) source: (path to the file) test.html:4:12 

downloadable font: incorrect entrySelector for table directory (font-family: "clunk" style:normal weight:normal stretch:normal src index:0) source: (path to the file) test.html:4:12 

downloadable font: rejected by sanitizer (font-family: "clunk" style:normal weight:normal stretch:normal src index:0) source: (path to the file) 

我搜索了這些錯誤,但這個問題似乎很廣泛,很難找到迷你惡意的例子。在這種簡單的情況下會造成什麼錯誤?

+0

你使用的是git嗎? –

回答

0

我發現this answer從2009年開始建議用FontForge重建字體。我試過了,它解決了這個問題,所以它似乎是字體本身而不是代碼的問題。

在這種特殊情況下,字體中的字母是「缺少極值點」,FontForge只需單擊即可解決。

1

試試這個

src: url('/clunk.ttf'); 
+0

如果你的路徑似乎是/font/clunk.ttf,你的src應該是這樣的src:'url('/ font/clunk。ttf');' – clarkoy

0

轉到:

http://yourwebsite/clunk.ttf

如果不能下載(作爲第一個錯誤狀態),那麼你的文件位置是不正確的。您可能需要設置像一個絕對路徑:

http://yourwebsite/somesubpath/clunk.ttf

或者

/somesubpath/clunk.ttf

0

檢查你的路徑,最佳做法是始終使用相對路徑(例:)

src: url('fonts/clunk.ttf') format('truetype'); 

檢查標題:Access-Control-Allow-Origin

enter image description here

+0

將src更改爲您發佈的內容並沒有改變任何內容。它發現文件很好,但它似乎不喜歡格式或其他東西,即使應該支持TTF。 – Pikamander2

+0

你提供了正確的標題? – Hash

1

這可能對你有幫助。

https://everythingfonts.com/ttf-to-woff

基本上你需要做的是:

- 轉換的.TTF到.woff

我不知道爲什麼將它的工作原理。但它總是對我有用。 另外...刪除您的緩存或更改文件的名稱。

我希望這有助於

+0

FontForge完全解決了我的問題,但是出於好奇,我嘗試了你的網站。它修復了控制檯錯誤,並使字體顯示出來,但是卻搞砸了字體中的一個字母。這是一個很好的備份選項,但FontForge更好地完成了這項工作,並且我能夠保留TTF文件類型。 – Pikamander2

+0

如果我發給你的轉換器沒有完美轉換,只需查看其他字體轉換器即可。有些比其他人好。瀏覽器,代碼或思維沒有任何問題。有時你的字體不適合瀏覽器。但是,一旦你轉換它,BAM ...它的工作。 –

相關問題