Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

WeChat small program API font


May 19, 2021 WeChat Mini Program Development Document


Table of contents


wx.loadFontFace(Object object)

Base library 2.1.0 starts to support, and low versions need to be compatible.

The network font is loaded dynamically, and the file address needs to be the download type. '2.10.0' supports global effective and needs to be called .js app.

Attention:

  1. The font file returns a contet-type reference font that fails to resolve if it is not formatted correctly.
  2. Font links must be https (ios does not support http)
  3. Font links must be from the same source, or cors support is turned on, and the domain name of the servicewechat.com
  4. Native components such as canvas do not support fonts added using interfaces
  5. The tool suggests that faild to load font can be ignored
  6. '2.10.0' previously only worked on the calling page.

Parameters

Object object

Property Type The default Required Description The lowest version
global boolean false Whether Whether to take effect globally 2.10.0
family string Is The defined font name
source string Is The address of the font resource. The recommended formats are TTF and WOFF2, which are incompatible on lower versions of iOS.
desc Object Whether Optional font descriptor
success function Whether The interface calls a successful callback function
fail function Whether The interface calls the failed callback function
complete function Whether Callback function at end of interface call (call succeeds, fails are executed)

The structure of object.desc

Property Type The default Required Description
style string 'normal' no Font style, optional value is normal / italic / oblique
weight string 'normal' no Font thick, optional value is normal / bold / 100/200 ../ 900
variant string 'normal' no Set the font display of small uppercase letters, optional value is normal / small-caps / inherit

Object.success callback function

parameter
Object res
Attributes type illustrate
status string Load font results

Object.FAIL callback function

parameter
Object res
Property Type Description
status string Load the font results

object.complete callback function

Parameters
Object res
Property Type Description
status string Load the font results

The sample code

Preview the effect in the developer tool

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