diff --git a/cloudinary-core/src/main/java/com/cloudinary/transformation/TextLayer.java b/cloudinary-core/src/main/java/com/cloudinary/transformation/TextLayer.java index df2986c4..55380df3 100644 --- a/cloudinary-core/src/main/java/com/cloudinary/transformation/TextLayer.java +++ b/cloudinary-core/src/main/java/com/cloudinary/transformation/TextLayer.java @@ -21,6 +21,7 @@ public class TextLayer extends AbstractLayer { protected String letterSpacing = null; protected Integer lineSpacing = null; protected String text = null; + protected Object textStyle = null; @Override TextLayer getThis() { @@ -118,6 +119,28 @@ public TextLayer text(String text) { return getThis(); } + /** + * Sets a text style identifier, + * Note: If this is used, all other style attributes are ignored in favor of this identifier + * @param textStyleIdentifier A variable string or an explicit style (e.g. "Arial_17_bold_antialias_best") + * @return Itself for chaining + */ + public TextLayer textStyle(String textStyleIdentifier) { + this.textStyle = textStyleIdentifier; + return getThis(); + } + + /** + * Sets a text style identifier using an expression. + * Note: If this is used, all other style attributes are ignored in favor of this identifier + * @param textStyleIdentifier An expression instance referencing the style. + * @return Itself for chaining + */ + public TextLayer textStyle(Expression textStyleIdentifier) { + this.textStyle = textStyleIdentifier; + return getThis(); + } + @Override public String toString() { if (this.publicId == null && this.text == null) { @@ -144,6 +167,11 @@ public String toString() { } protected String textStyleIdentifier() { + // Note: if a text-style argument is provided as a whole, it overrides everything else, no mix and match. + if (StringUtils.isNotBlank(this.textStyle)) { + return textStyle.toString(); + } + ArrayList components = new ArrayList(); if (StringUtils.isNotBlank(this.fontWeight) && !this.fontWeight.equals("normal")) @@ -181,6 +209,5 @@ protected String textStyleIdentifier() { components.add(0, this.fontFamily); return StringUtils.join(components, "_"); - } } diff --git a/cloudinary-core/src/test/java/com/cloudinary/test/CloudinaryTest.java b/cloudinary-core/src/test/java/com/cloudinary/test/CloudinaryTest.java index 7202e993..e0875980 100644 --- a/cloudinary-core/src/test/java/com/cloudinary/test/CloudinaryTest.java +++ b/cloudinary-core/src/test/java/com/cloudinary/test/CloudinaryTest.java @@ -101,6 +101,30 @@ public void testSecureDistribution() { assertEquals("https://res.cloudinary.com/test123/image/upload/test", result); } + @Test + public void testTextLayerStyleIdentifierVariables() { + String url = cloudinary.url().transformation( + new Transformation() + .variable("$style", "!Arial_12!") + .chain() + .overlay( + new TextLayer().text("hello-world").textStyle("$style") + )).generate("sample"); + + assertEquals("http://res.cloudinary.com/test123/image/upload/$style_!Arial_12!/l_text:$style:hello-world/sample", url); + + url = cloudinary.url().transformation( + new Transformation() + .variable("$style", "!Arial_12!") + .chain() + .overlay( + new TextLayer().text("hello-world").textStyle(new Expression("$style")) + )).generate("sample"); + + assertEquals("http://res.cloudinary.com/test123/image/upload/$style_!Arial_12!/l_text:$style:hello-world/sample", url); + } + + @Test public void testSecureDistributionOverwrite() { // should allow overwriting secure distribution if secure=TRUE