MCPcopy Create free account
hub / github.com/cloudinary/cloudinary_npm / textStyle

Function textStyle

lib/utils/index.js:97–132  ·  view source on GitHub ↗
(layer)

Source from the content-addressed store, hash-verified

95const applyQCompat = require("./qPolyfill");
96
97function textStyle(layer) {
98 let keywords = [];
99 let style = "";
100
101 if (!isEmpty(layer.text_style)) {
102 return layer.text_style;
103 }
104 Object.keys(LAYER_KEYWORD_PARAMS).forEach((attr) => {
105 let default_value = LAYER_KEYWORD_PARAMS[attr];
106 let attr_value = layer[attr] || default_value;
107 if (attr_value !== default_value) {
108 keywords.push(attr_value);
109 }
110 });
111
112 Object.keys(layer).forEach((attr) => {
113 if (attr === "letter_spacing" || attr === "line_spacing") {
114 keywords.push(`${attr}_${layer[attr]}`);
115 }
116 if (attr === "font_hinting") {
117 keywords.push(`${attr.split("_").pop()}_${layer[attr]}`);
118 }
119 if (attr === "font_antialiasing") {
120 keywords.push(`antialias_${layer[attr]}`);
121 }
122 });
123
124 if (layer.hasOwnProperty("font_size" || "font_family") || !isEmpty(keywords)) {
125 if (!layer.font_size) throw new Error('Must supply font_size for text in overlay/underlay');
126 if (!layer.font_family) throw new Error('Must supply font_family for text in overlay/underlay');
127 keywords.unshift(layer.font_size);
128 keywords.unshift(layer.font_family);
129 style = compact(keywords).join("_");
130 }
131 return style;
132}
133
134/**
135 * Normalize an expression string, replace "nice names" with their coded values and spaces with "_"

Callers 1

process_layerFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected