From 4202e73a69274a94a4a9b1195ef5f1ded872fab9 Mon Sep 17 00:00:00 2001 From: Yarosalv Maslov <148754748+Yar04ek@users.noreply.github.com> Date: Tue, 12 Dec 2023 12:14:20 +0100 Subject: [PATCH] [7.6.0][CDE] ApiUniColor.ToJSON check (#1015) * feature: ApiUniColor.ToJSON * ref: ApiUniColor.ToJSON * ref: ApiUniColor.ToJSON * ref: ApiUniColor.ToJSON * ref: ApiUniColor.ToJSON --- js/docx/smoke/api_uni_color/to_json.js | 25 +++++++++++++++++++++++++ spec/docx/smoke/api_uni_color_spec.rb | 10 ++++++++++ 2 files changed, 35 insertions(+) create mode 100644 js/docx/smoke/api_uni_color/to_json.js diff --git a/js/docx/smoke/api_uni_color/to_json.js b/js/docx/smoke/api_uni_color/to_json.js new file mode 100644 index 00000000..2e63279c --- /dev/null +++ b/js/docx/smoke/api_uni_color/to_json.js @@ -0,0 +1,25 @@ +builder.CreateFile("docx"); + let oDocument = Api.GetDocument(); + let oParagraph = oDocument.GetElement(0); + // RGBColor is an inheritor of UniColor class. + // It is impossible to use an instance of UniColor class directly + let oRGBColor = Api.CreateRGBColor(255, 111, 61); + let oFill = Api.CreateSolidFill(oRGBColor); + oParagraph.AddText(oFill.ToJSON()); + GlobalVariable["JSON_UniColor"] = oFill.ToJSON(); +builder.CloseFile(); + +///////////////////// + +builder.CreateFile("docx"); + let oDocument = Api.GetDocument(); + let oParagraph = oDocument.GetElement(0); + let jsonSolidFill = GlobalVariable["JSON_UniColor"]; + let oFillRestored = Api.FromJSON(jsonSolidFill); + let oStroke = Api.CreateStroke(0, Api.CreateNoFill()); + let oDrawing = Api.CreateShape("rect", 5930900, 395605, oFillRestored, oStroke); + let jsonDrawing = oDrawing.ToJSON(false, true); + oParagraph.AddText(jsonDrawing); + oDocument.Push(oParagraph); +builder.SaveFile("docx", "UnicolorToJson.docx"); +builder.CloseFile(); diff --git a/spec/docx/smoke/api_uni_color_spec.rb b/spec/docx/smoke/api_uni_color_spec.rb index f5e47f06..fff70fdd 100644 --- a/spec/docx/smoke/api_uni_color_spec.rb +++ b/spec/docx/smoke/api_uni_color_spec.rb @@ -6,4 +6,14 @@ docx = builder.build_and_parse('js/docx/smoke/api_uni_color/get_class_type.js') expect(docx.elements[1].nonempty_runs.first.text).to eq('Class Type = presetColor') end + + it 'ApiUniColor | ToJSON method' do + docx = builder.build_and_parse('js/docx/smoke/api_uni_color/to_json.js') + json = JSON.parse(docx.elements[0].nonempty_runs.first.text) + color = json['graphic']['spPr']['fill']['fill']['color'] + expect(color['type']).to eq('uniColor') + expect(color['color']['rgba']['red']).to eq(255) + expect(color['color']['rgba']['green']).to eq(111) + expect(color['color']['rgba']['blue']).to eq(61) + end end