Skip to content

Commit 50dddd0

Browse files
authored
Add antialiasing and hinting
1 parent b938041 commit 50dddd0

File tree

5 files changed

+64
-38
lines changed

5 files changed

+64
-38
lines changed

lib-es5/uploader.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ exports.rename = function rename(from_public_id, to_public_id, callback) {
241241
});
242242
};
243243

244-
var TEXT_PARAMS = ["public_id", "font_family", "font_size", "font_color", "text_align", "font_weight", "font_style", "background", "opacity", "text_decoration"];
244+
var TEXT_PARAMS = ["public_id", "font_family", "font_size", "font_color", "text_align", "font_weight", "font_style", "background", "opacity", "text_decoration", "font_hinting", "font_antialiasing"];
245245

246246
exports.text = function text(content, callback) {
247247
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};

lib-es5/utils/index.js

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,6 @@ var LAYER_KEYWORD_PARAMS = {
159159
};
160160

161161
function textStyle(layer) {
162-
var font_family = layer.font_family;
163-
var font_size = layer.font_size;
164162
var keywords = [];
165163
var style = "";
166164
Object.keys(LAYER_KEYWORD_PARAMS).forEach(function (attr) {
@@ -170,23 +168,24 @@ function textStyle(layer) {
170168
keywords.push(attr_value);
171169
}
172170
});
173-
var letter_spacing = layer.letter_spacing;
174-
if (letter_spacing) {
175-
keywords.push(`letter_spacing_${letter_spacing}`);
176-
}
177-
var line_spacing = layer.line_spacing;
178-
if (line_spacing) {
179-
keywords.push(`line_spacing_${line_spacing}`);
180-
}
181-
if (font_size || font_family || !isEmpty(keywords)) {
182-
if (!font_family) {
183-
throw "Must supply font_family for text in overlay/underlay";
171+
172+
Object.keys(layer).forEach(function (attr) {
173+
if (attr === "letter_spacing" || attr === "line_spacing") {
174+
keywords.push(`${attr}_${layer[attr]}`);
184175
}
185-
if (!font_size) {
186-
throw "Must supply font_size for text in overlay/underlay";
176+
if (attr === "font_hinting") {
177+
keywords.push(`${attr.split("_").pop()}_${layer[attr]}`);
187178
}
188-
keywords.unshift(font_size);
189-
keywords.unshift(font_family);
179+
if (attr === "font_antialiasing") {
180+
keywords.push(`antialias_${layer[attr]}`);
181+
}
182+
});
183+
184+
if (layer.hasOwnProperty("font_size" || "font_family") || !isEmpty(keywords)) {
185+
if (!layer.font_size) throw `Must supply font_size for text in overlay/underlay`;
186+
if (!layer.font_family) throw `Must supply font_family for text in overlay/underlay`;
187+
keywords.unshift(layer.font_size);
188+
keywords.unshift(layer.font_family);
190189
style = compact(keywords).join("_");
191190
}
192191
return style;
@@ -1502,4 +1501,4 @@ exports.build_streaming_profiles_param = build_streaming_profiles_param;
15021501
exports.hashToParameters = hashToParameters;
15031502
exports.present = present;
15041503
exports.only = only;
1505-
exports.jsonArrayParam = jsonArrayParam;
1504+
exports.jsonArrayParam = jsonArrayParam;

lib/uploader.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ exports.rename = function rename(from_public_id, to_public_id, callback, options
189189
});
190190
};
191191

192-
const TEXT_PARAMS = ["public_id", "font_family", "font_size", "font_color", "text_align", "font_weight", "font_style", "background", "opacity", "text_decoration"];
192+
const TEXT_PARAMS = ["public_id", "font_family", "font_size", "font_color", "text_align", "font_weight", "font_style", "background", "opacity", "text_decoration", "font_hinting", "font_antialiasing"];
193193

194194
exports.text = function text(content, callback, options = {}) {
195195
return call_api("text", callback, options, function () {

lib/utils/index.js

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,6 @@ const LAYER_KEYWORD_PARAMS = {
151151
};
152152

153153
function textStyle(layer) {
154-
let font_family = layer.font_family;
155-
let font_size = layer.font_size;
156154
let keywords = [];
157155
let style = "";
158156
Object.keys(LAYER_KEYWORD_PARAMS).forEach((attr) => {
@@ -162,23 +160,24 @@ function textStyle(layer) {
162160
keywords.push(attr_value);
163161
}
164162
});
165-
let letter_spacing = layer.letter_spacing;
166-
if (letter_spacing) {
167-
keywords.push(`letter_spacing_${letter_spacing}`);
168-
}
169-
let line_spacing = layer.line_spacing;
170-
if (line_spacing) {
171-
keywords.push(`line_spacing_${line_spacing}`);
172-
}
173-
if (font_size || font_family || !isEmpty(keywords)) {
174-
if (!font_family) {
175-
throw "Must supply font_family for text in overlay/underlay";
163+
164+
Object.keys(layer).forEach((attr) => {
165+
if (attr === "letter_spacing" || attr === "line_spacing") {
166+
keywords.push(`${attr}_${layer[attr]}`);
176167
}
177-
if (!font_size) {
178-
throw "Must supply font_size for text in overlay/underlay";
168+
if (attr === "font_hinting") {
169+
keywords.push(`${attr.split("_").pop()}_${layer[attr]}`);
179170
}
180-
keywords.unshift(font_size);
181-
keywords.unshift(font_family);
171+
if (attr === "font_antialiasing") {
172+
keywords.push(`antialias_${layer[attr]}`);
173+
}
174+
});
175+
176+
if (layer.hasOwnProperty("font_size" || "font_family") || !isEmpty(keywords)) {
177+
if (!layer.font_size) throw `Must supply font_size for text in overlay/underlay`;
178+
if (!layer.font_family) throw `Must supply font_family for text in overlay/underlay`;
179+
keywords.unshift(layer.font_size);
180+
keywords.unshift(layer.font_family);
182181
style = compact(keywords).join("_");
183182
}
184183
return style;

test/utils_spec.js

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,7 @@ describe("utils", function () {
692692
"string",
693693
{
694694
"font_family": "arial",
695-
"font_size": 30,
695+
"font_size": "30",
696696
"text": "abc,αβγ/אבג",
697697
},
698698
"text:arial_30:abc%252C%CE%B1%CE%B2%CE%B3%252F%D7%90%D7%91%D7%92",
@@ -1129,6 +1129,34 @@ describe("utils", function () {
11291129
},
11301130
`text:Arial_18_bold_italic_letter_spacing_4_line_spacing_2:${text_encoded}`,
11311131
],
1132+
[
1133+
"text with text font_antialiasing",
1134+
{
1135+
text: text_layer,
1136+
font_family: "Arial",
1137+
font_size: "18",
1138+
font_weight: "bold",
1139+
font_style: "italic",
1140+
letter_spacing: 4,
1141+
line_spacing: 2,
1142+
font_antialiasing: "best",
1143+
},
1144+
`text:Arial_18_bold_italic_letter_spacing_4_line_spacing_2_antialias_best:${text_encoded}`,
1145+
],
1146+
[
1147+
"text with text font_hinting",
1148+
{
1149+
text: text_layer,
1150+
font_family: "Arial",
1151+
font_size: "18",
1152+
font_weight: "bold",
1153+
font_style: "italic",
1154+
letter_spacing: 4,
1155+
line_spacing: 2,
1156+
font_hinting: "medium",
1157+
},
1158+
`text:Arial_18_bold_italic_letter_spacing_4_line_spacing_2_hinting_medium:${text_encoded}`,
1159+
],
11321160
[
11331161
"subtitles",
11341162
{

0 commit comments

Comments
 (0)