-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode.ts
More file actions
74 lines (66 loc) · 2.28 KB
/
code.ts
File metadata and controls
74 lines (66 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
const fontStyles : string[] =[
"Thin",
"ExtraLight",
"Light",
"Regular",
"Medium",
"SemiBold",
"Bold",
"ExtraBold",
"Black",
"Thin Italic",
"ExtraLight Italic",
"Light Italic",
"Regular Italic",
"Medium Italic",
"SemiBold Italic",
"Bold Italic",
"ExtraBold Italic",
"Black Italic",
]
const loadFonts = async (_figmaElement) => {
await figma.loadFontAsync({family: "Manrope", style: "Bold Italic"})
// await figma.loadFontAsync({family: figmaElement.fontName["family"], style: "Bold"})
console.log("finished")
// hay que hacer un loadFontAsync para cada estilo posible, pero si el estilo no existe, el programa no deja de correr
// hay que hacer un timeout y cuando se cumpla se siga al siguiente estilo.
// se tienen que cargar todos los estilos y luego generar el texto para todos los estilos encontrados
// me parece que la funcion loadFontsAsync es una funcion que funciona con Promises (?) asiq quizas valga la pena revisar
// el error handling para las funciones que retornan (o son) Promises.
}
function createFontDisplay(figmaElement) {
let text = figma.createText()
text.x = figmaElement.x
text.y = figmaElement.y + figmaElement.height*3/2
console.log(figmaElement.fontSize)
text.fontName = {family: figmaElement.fontName["family"], style: "Bold Italic"}
console.log(figmaElement.fontName)
text.characters = "Almost before we knew it, we had left the ground."
text.fontSize = figmaElement.fontSize
}
if (figma.editorType === 'figma') {
if (figma.currentPage.selection[0].type === "TEXT") {
let fonts = figma.currentPage.selection;
// console.log(fonts[0].fontName);
for (let i = 0; i < fonts.length; i++) {
const element = fonts[i];
console.log(element.fontName)
loadFonts(element).then(() => {
createFontDisplay(element)
const nodes: SceneNode[] = [];
nodes.push();
figma.currentPage.selection = nodes;
figma.viewport.scrollAndZoomIntoView(nodes);
figma.closePlugin();
})
// await figma.loadFontAsync(element.fontName)
// display.fontName["style"] = "Bold"
// for (let i = 0; i < display.FontName.length; i++) {
// const element = display.FontName[i];
// console.log(i)
// }
}
}
// If the plugins isn't run in Figma, run this code
} else {
};