Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class TextLayer extends AbstractLayer<TextLayer> {
protected String letterSpacing = null;
protected Integer lineSpacing = null;
protected String text = null;
protected Object textStyle = null;

@Override
TextLayer getThis() {
Expand Down Expand Up @@ -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) {
Expand All @@ -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<String> components = new ArrayList<String>();

if (StringUtils.isNotBlank(this.fontWeight) && !this.fontWeight.equals("normal"))
Expand Down Expand Up @@ -181,6 +209,5 @@ protected String textStyleIdentifier() {
components.add(0, this.fontFamily);

return StringUtils.join(components, "_");

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down