Skip to content

Commit

Permalink
added fonts prewarming for 100 times faster generation speed
Browse files Browse the repository at this point in the history
  • Loading branch information
softmarshmallow committed Dec 26, 2020
1 parent f588a38 commit da0add6
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion figma/src/reflect-render/buttons.render/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export async function drawButtons(seq: number, col: number = 50, row: number = 5
// focus to created page
figma.currentPage = newPageForRenderer

await prewarmFonts()
// horizontal margin between two generated buttons.
const marginBetweenGeneratedElements = 50
let xPos = 0
Expand All @@ -29,7 +30,7 @@ export async function drawButtons(seq: number, col: number = 50, row: number = 5
i++;

const fontName = generateRandomFont()
await figma.loadFontAsync(fontName)

const buttonFrame = figma.createFrame()

buttonFrame.name = `relfect-buttons/with-text-${i}`
Expand Down Expand Up @@ -124,6 +125,21 @@ export async function drawButtons(seq: number, col: number = 50, row: number = 5
}


async function prewarmFonts() {
await figma.loadFontAsync({
family: "Roboto",
style: "Bold"
})
await figma.loadFontAsync({
family: "Roboto",
style: "Medium"
})
await figma.loadFontAsync({
family: "Roboto",
style: "Regular"
})
}


function generateRandomIcon() {

Expand Down

0 comments on commit da0add6

Please sign in to comment.