Skip to content

Commit f90a52e

Browse files
authored
Merge pull request #401 from cloudinary/feature/add-stroke-solid
Feature/add stroke solid
2 parents 134ec9d + 0a477d7 commit f90a52e

File tree

4 files changed

+43
-1
lines changed

4 files changed

+43
-1
lines changed

__TESTS__/unit/values/TextStyle/TextStyle.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import {FontWeight} from "../../../../src/qualifiers/fontWeight";
55
import {FontHinting} from "../../../../src/qualifiers/fontHinting";
66
import {TextDecoration} from "../../../../src/qualifiers/textDecoration";
77
import {TextAlignment} from "../../../../src/qualifiers/textAlignment";
8+
import {Stroke} from "../../../../src/qualifiers/textStroke";
9+
import {Color} from "../../../../src/qualifiers/color";
810

911
describe('Text Style tests', () => {
1012
it('Create a new instance', () => {
@@ -35,6 +37,14 @@ describe('Text Style tests', () => {
3537
expect(res).toBe('arial_50_bold_italic_strikethrough_justify_stroke_letter_spacing_10_line_spacing_20_antialias_good_hinting_full');
3638
});
3739

40+
it('Create a new instance with stroke solid', () => {
41+
const res = new TextStyle('arial', 50)
42+
.stroke(Stroke.solid(2, Color.WHITE))
43+
.toString();
44+
expect(res).toBe('arial_50_stroke_bo_2px_solid_white');
45+
});
46+
47+
3848
it('Ensure normal is not included in the URL(this is the default)', () => {
3949
const res = new TextStyle('arial', 50)
4050
.fontWeight(FontWeight.normal())

src/qualifiers.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,13 @@ import {StreamingProfile} from "./qualifiers/streamingProfile";
3131
import {TextAlignment} from "./qualifiers/textAlignment";
3232
import {TextDecoration} from "./qualifiers/textDecoration";
3333
import {GradientFade} from "./qualifiers/GradientFade";
34+
import {Stroke} from "./qualifiers/textStroke";
3435

3536

3637
const Qualifiers = {
3738
TextDecoration,
3839
TextAlignment,
40+
Stroke,
3941
StreamingProfile,
4042
SimulateColorBlind,
4143
RotationMode,

src/qualifiers/textStroke.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import {SystemColors} from "./color";
2+
import {ExpressionQualifier} from "./expression/ExpressionQualifier";
3+
/**
4+
* @description Contains function to set the outline stroke.
5+
* <b>Learn more</b>: {@link https://cloudinary.com/documentation/image_transformations#adding_text_overlays | Adding text overlays to images}
6+
* <b>Learn more</b>: {@link https://cloudinary.com/documentation/video_manipulation_and_delivery#adding_text_captions | Adding text overlays to videos}
7+
* @memberOf Qualifiers
8+
* @namespace TextAlignment
9+
* @see To be used with {@link Qualifiers.TextStyle|Text Style}
10+
*/
11+
12+
13+
/**
14+
* @summary qualifier Adding a Border-like qualifier to the same action.
15+
* @memberOf Qualifiers.Stroke
16+
* @param {number|string|ExpressionQualifier} width The width in pixels.
17+
* @param {number|string|SystemColors} color The color of the border.
18+
*/
19+
function solid(width: number | string | ExpressionQualifier, color: number | string | SystemColors): string{
20+
return `bo_${width}px_solid_${color}`;
21+
}
22+
23+
const Stroke = {solid};
24+
25+
export {Stroke, solid};

src/qualifiers/textStyle.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class TextStyle {
2323
private _textDecoration: string;
2424
private _textAlignment: string;
2525
private _stroke: boolean;
26+
private _strokeStyle: string;
2627
private _fontHinting: string;
2728

2829
/**
@@ -127,7 +128,10 @@ class TextStyle {
127128
/**
128129
* @description Whether to include an outline stroke. Set the color and weight of the stroke
129130
*/
130-
stroke(): this {
131+
stroke(textStroke?: string): this {
132+
if(textStroke) {
133+
this._strokeStyle = textStroke;
134+
}
131135
this._stroke = true;
132136
return this;
133137
}
@@ -140,6 +144,7 @@ class TextStyle {
140144
this._textDecoration !== normalTextDecoration() && this._textDecoration,
141145
this._textAlignment,
142146
this._stroke && 'stroke',
147+
this._strokeStyle,
143148
this._letterSpacing && `letter_spacing_${this._letterSpacing}`,
144149
this._lineSpacing && `line_spacing_${this._lineSpacing}`,
145150
this._fontAntialias && `antialias_${this._fontAntialias}`,

0 commit comments

Comments
 (0)