From cbaf60693c0ed5c02fd712ff4123917bcb2d0a2b Mon Sep 17 00:00:00 2001 From: Yar04ek Date: Wed, 29 Nov 2023 16:14:25 +0100 Subject: [PATCH] feature: ApiTableRowPr.ToJSON --- js/docx/smoke/api_rgb_color/to_json.js | 29 ++++++++++++++------------ spec/docx/smoke/api_rgb_color_spec.rb | 10 ++++----- 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/js/docx/smoke/api_rgb_color/to_json.js b/js/docx/smoke/api_rgb_color/to_json.js index 754e0ddef..afa0fd405 100644 --- a/js/docx/smoke/api_rgb_color/to_json.js +++ b/js/docx/smoke/api_rgb_color/to_json.js @@ -10,18 +10,21 @@ builder.CloseFile(); ///////////////////// builder.CreateFile("docx"); - let oNewDocument = Api.GetDocument(); + let oDocument = Api.GetDocument(); + let oParagraph1 = oDocument.GetElement(0); let jsonRGBColor = GlobalVariable["JSON_RGBColor"]; - let oParagraphRGBColor = oNewDocument.GetElement(0); - oParagraphRGBColor.AddText(jsonRGBColor); - let oRGBColorFromJSON = Api.FromJSON(jsonRGBColor); - let oParagraphRGBColorObject = Api.CreateParagraph(); - oNewDocument.Push(oParagraphRGBColorObject); - let bWriteNumberings = false; - let bWriteStyles = true; - let jsonDrawingFromJSON = oRGBColorFromJSON.ToJSON(bWriteNumberings, bWriteStyles); - let oParagraphDrawing = Api.CreateParagraph(); - oParagraphDrawing.AddText(jsonDrawingFromJSON); - oNewDocument.Push(oParagraphDrawing); -builder.SaveFile("docx", "RGBColorToJSON.docx"); + let oRGBColor = Api.FromJSON(jsonRGBColor); + oParagraph1.AddText(jsonRGBColor); + oDocument.Push(oParagraph1); + let oParagraph2 = Api.CreateParagraph(); + let oGs1 = Api.CreateGradientStop(oRGBColor, 0); + let oGs2 = Api.CreateGradientStop(oRGBColor, 10); + let oFill = Api.CreateLinearGradientFill([oGs1, oGs2], 5400000); + let oStroke = Api.CreateStroke(0, Api.CreateNoFill()); + let oDrawing = Api.CreateShape("rect", 5930900, 395605, oFill, oStroke); + let jsonDrawing = oDrawing.ToJSON(false, true); + oParagraph2.AddText(jsonDrawing); + oDocument.Push(oParagraph2); +builder.SaveFile("docx", "DrawingFromJSON.docx"); builder.CloseFile(); + diff --git a/spec/docx/smoke/api_rgb_color_spec.rb b/spec/docx/smoke/api_rgb_color_spec.rb index b6bdae500..60ad8c9c6 100644 --- a/spec/docx/smoke/api_rgb_color_spec.rb +++ b/spec/docx/smoke/api_rgb_color_spec.rb @@ -9,10 +9,10 @@ it 'ApiRGBColor | ToJSON method' do docx = builder.build_and_parse('js/docx/smoke/api_rgb_color/to_json.js') - expected_text = '{"rgba":{"red":0,"green":0,"blue":0,"alpha":255},"color":{"rgba":{"red":255,"green":111,"blue":61,"alpha":255},"type":"srgb"},"type":"uniColor"}' - expected_json = JSON.parse(expected_text) - third_paragraph_text = docx.elements[2].nonempty_runs.first.text - third_paragraph_json = JSON.parse(third_paragraph_text) - expect(third_paragraph_json).to include(expected_json) + first_paragraph_text = docx.elements[0].nonempty_runs.first.text + second_paragraph_text = docx.elements[1].nonempty_runs.first.text + first_paragraph_json = JSON.parse(first_paragraph_text) + second_paragraph_json = JSON.parse(second_paragraph_text) + expect(second_paragraph_json.to_s).to include(first_paragraph_json.to_s) end end