# wx.loadFontFace(Object object)

Start from base library version 2.1.0. Please remaining backward compatible.

with Promise style call: Supported

Mini Program plugin: Support, need to Mini Program base library version no less than 2.15.0

Dynamic load network font, file address should be download type. {%version(&#392.10.0&#39)Global validation is supported from%} app.js Called in.

Note:

  1. Font file returns contet-type Reference fontParsing fails when the format is incorrect.
  2. Font link must be https ios does not support http)
  3. Font links must be under the same source, or enabled cors support, Mini Program domain name isservicewechat.com
  4. Tooltip Faild to load Font can be ignored
  5. &#392.10.0&#39 Previously it only took effect on the call page.

# parameter

# Object object

attribute type Default values Required Introductions Minimum version
global boolean false no Global Effect 2.10.0
family string yes Defined font name
source string yes The address of the font resource. The suggested format is TTF and Woff, WOFF2 It won't be compatible on lower versions of iOS.
desc Object no Optional font descriptor
scopes Array no Font scope, optional value is webview / Native, default Webview, setup native Available at Canvas 2D Use under
success function no Interface calls the successful callback function
fail function no Interface calls failed callback functions
complete function no Callback function at the end of an interface call (both successful and unsuccessful calls are executed)

object.desc Structure

attribute type Default values Required Introductions
style string 'normal' no Font style, optional value is normal / italic / oblique
weight string 'normal' no Font size, optional value is normal / bold / 100 / 200../ 900
variant string 'normal' no Sets font display text for small uppercase letters, optional normal / small-caps / inherit

# object.success callback

# parameter
# Object res
attribute type Introductions
status string Load font results

# object.fail callback

# parameter
# Object res
attribute type Introductions
status string Load font results

# object.complete callback

# parameter
# Object res
attribute type Introductions
status string Load font results

# sample code

Preview with Developer Tool

wx.loadFontFace({
  family: 'Bitstream Wedding band Serif Bold',
  source: 'url("https://sungd.github.io/Pacific.ttf")',
  success: console.log
})