FontData: fullName property

Khả dụng hạn chế

This feature is not Baseline because it does not work in some of the most widely-used browsers.

Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

Thuộc tính chỉ đọc fullName của giao diện FontData trả về tên đầy đủ của mặt phông chữ. Đây thường là tên có thể đọc được bởi con người để xác định phông chữ, ví dụ: "Optima Bold".

Ví dụ bao gồm:

  • Apple SD Gothic Neo UltraLight
  • Arial Black
  • Avenir Next Heavy
  • Katari Medium Italic
  • YuMincho +36p Kana Extrabold

Giá trị

Một chuỗi.

Ví dụ

Đoạn code sau sẽ truy vấn tất cả các phông chữ có sẵn và ghi siêu dữ liệu. Điều này có thể được sử dụng, ví dụ, để điền vào điều khiển chọn phông chữ.

js
async function logFontData() {
  try {
    const availableFonts = await window.queryLocalFonts();
    for (const fontData of availableFonts) {
      console.log(fontData.postscriptName);
      console.log(fontData.fullName);
      console.log(fontData.family);
      console.log(fontData.style);
    }
  } catch (err) {
    console.error(err.name, err.message);
  }
}

Thông số kỹ thuật

Thông số kỹ thuật
Local Font Access API
# ref-for-dom-fontdata-fullname

Tương thích trình duyệt

Xem thêm