tencent cloud

All product documents
Tencent Cloud Super App as a Service
Last updated: 2025-01-23 17:55:46
Font
Last updated: 2025-01-23 17:55:46

loadFontFace

This API is used via wx.loadFontFace(Object object).
Feature Description: Dynamically loads web fonts. The file address must be of download type, and it needs to be invoked within js.
Note:
The contet-type returned by the font file refers to the font, and will fail to parse if it is not in the correct format;
For true machine compatibility, the font link must be https;
The link to the font must be under the same source, or enable cors support, the domain name of the mini program is servicewechat.com(If the client has a custom domain name, please adjust it here according to the custom configuration).;
The tooltip Faild to load font can be ignored.
Parameter and Description: Object
Attribute
Type
Default value
Required
Description
family
string
-
Yes
Defined font name
source
string
-
Yes
The address of the font resource. The recommended formats are TTF and WOFF, as WOFF2 may not be compatible with older versions of iOS.
desc
object
-
No
Optional font descriptors
success
function
-
No
Callback Function of Successful Interface Call
fail
function
-
No
Callback Function of Successful Interface Call
complete
function
-
No
Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations)
Structural value of 'desc'
Structure attributes
Type
Default value
Required
Description
style
string
normal
No
Font style, with optional values being 'normal', 'italic', or 'oblique'.
weight
string
normal
No
Font weight, with optional values being 'normal', 'bold', '100', '200', or '900'.
variant
string
normal
No
Sets the display text for small capital letters, with optional values being 'normal', 'small-caps', or 'inherit'.
Parameters for object.success callback function: Object res.
Attribute
Type
Description
status
string
Font Loading Results
Parameters for object.fail callback function: Object res
Attribute
Type
Description
status
string
Font Loading Results
object.complete Callback Function Parameters: Object res
Attribute
Type
Description
status
string
Font Loading Results
Sample Code
// https://sungd.github.io/Pacifico.ttf Font links need to have https enabled and cross-domain settings turned on
wx.loadFontFace({
family:Bitstream Vera Serif Bold,
family:MyFont.
source:url(’https://sungd.github.io/Pacifico.ttf‘),
Success: console.log
})
page {
font-family: 'MyFont';
}

Was this page helpful?
You can also Contact Sales or Submit a Ticket for help.
Yes
No

Feedback

Contact Us

Contact our sales team or business advisors to help your business.

Technical Support

Open a ticket if you're looking for further assistance. Our Ticket is 7x24 available.

7x24 Phone Support
Hong Kong, China
+852 800 906 020 (Toll Free)
United States
+1 844 606 0804 (Toll Free)
United Kingdom
+44 808 196 4551 (Toll Free)
Canada
+1 888 605 7930 (Toll Free)
Australia
+61 1300 986 386 (Toll Free)
EdgeOne hotline
+852 300 80699
More local hotlines coming soon