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 12, 2023
1 parent 12fcfcf commit 5f9900f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
12 changes: 6 additions & 6 deletions js/docx/smoke/api_stroke/to_json.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ 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);
Expand All @@ -15,15 +16,14 @@ builder.CreateFile("docx");
let oParagraph1 = oDocument.GetElement(0);
let jsonStroke = GlobalVariable["JSON_Stroke"];
let oStrokeFromJSON = Api.FromJSON(jsonStroke);
let oRGBColor2 = Api.CreateRGBColor(255, 213, 191);
let oFill = Api.CreateSolidFill(oRGBColor2);
let oDrawing = Api.CreateShape("roundRect", 5930900, 395605, oFill, oStrokeFromJSON);
let jsonDrawing = oDrawing.ToJSON(false, true);
oParagraph1.AddDrawing(oDrawing);
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();

6 changes: 1 addition & 5 deletions spec/docx/smoke/api_stroke_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,8 @@
expect(docx.elements[1].nonempty_runs.first.text).to eq('Class Type = stroke')
end

it 'ApiStroke | ToJSON method' do
it 'ApiRGBColor | ToJSON method' do
docx = builder.build_and_parse('js/docx/smoke/api_stroke/to_json.js')
expect(docx.elements.first.nonempty_runs.first.alternate_content.office2010_content.graphic.data.text_body.elements.first.character_style_array.size).to eq(2)
expect(docx.elements.first.nonempty_runs.first
.alternate_content.office2010_content.graphic.type).to eq(:shape)
expect(docx.elements[1].nonempty_runs.first.text).to include('"type":"stroke"')
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)
Expand Down

0 comments on commit 5f9900f

Please sign in to comment.