Skip to content

Commit

Permalink
feature: ApiStroke.ToJSON
Browse files Browse the repository at this point in the history
  • Loading branch information
Yar04ek committed Dec 4, 2023
1 parent ad2eab5 commit 2e3b428
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
29 changes: 29 additions & 0 deletions js/docx/smoke/api_stroke/to_json.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
builder.CreateFile("docx");
let oDocument = Api.GetDocument();
let oParagraph = oDocument.GetElement(0);
let oRGBColor = Api.CreateRGBColor(255, 111, 61);
let oFill = Api.CreateSolidFill(oRGBColor);
let oStroke = Api.CreateStroke(5 * 36000, Api.CreateSolidFill(Api.CreateRGBColor(51, 51, 51)));
let jsonStroke = oStroke.ToJSON();
oParagraph.AddText(jsonStroke);
GlobalVariable["JSON_Stroke"] = jsonStroke;
builder.CloseFile();

//////////////////////

builder.CreateFile("docx");
let oDocument = Api.GetDocument();
let oParagraph1 = oDocument.GetElement(0);
let jsonStroke = GlobalVariable["JSON_Stroke"];
let oStrokeFromJSON = Api.FromJSON(jsonStroke);
oParagraph1.AddText(jsonStroke);
oDocument.Push(oParagraph1);
let oParagraph2 = Api.CreateParagraph();
let oRGBColor2 = Api.CreateRGBColor(255, 213, 191);
let oFill2 = Api.CreateSolidFill(oRGBColor2);
let oDrawing = Api.CreateShape("roundRect", 5930900, 395605, oFill2, oStrokeFromJSON);
let jsonDrawing = oDrawing.ToJSON(false, true);
oParagraph2.AddText(jsonDrawing);
oDocument.Push(oParagraph2);
builder.SaveFile("docx", "StrokeToJson.docx");
builder.CloseFile();
9 changes: 9 additions & 0 deletions spec/docx/smoke/api_stroke_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,13 @@
docx = builder.build_and_parse('js/docx/smoke/api_stroke/get_class_type.js')
expect(docx.elements[1].nonempty_runs.first.text).to eq('Class Type = stroke')
end

it 'ApiStroke | ToJSON method' do
docx = builder.build_and_parse('js/docx/smoke/api_stroke/to_json.js')
json = JSON.parse(docx.elements[1].nonempty_runs.first.text)
stroke = json['graphic']['spPr']['ln']['fill']['fill']['color']['color']['rgba']
expect(stroke['red']).to eq(51)
expect(stroke['green']).to eq(51)
expect(stroke['blue']).to eq(51)
end
end

0 comments on commit 2e3b428

Please sign in to comment.