diff --git a/js/docx/smoke/api_stroke/to_json.js b/js/docx/smoke/api_stroke/to_json.js new file mode 100644 index 000000000..fd3fd7788 --- /dev/null +++ b/js/docx/smoke/api_stroke/to_json.js @@ -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(); diff --git a/spec/docx/smoke/api_stroke_spec.rb b/spec/docx/smoke/api_stroke_spec.rb index a594cd3d8..425d7e709 100644 --- a/spec/docx/smoke/api_stroke_spec.rb +++ b/spec/docx/smoke/api_stroke_spec.rb @@ -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 'ApiRGBColor | 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