Skip to content

Commit

Permalink
feature: ApiTableRowPr.ToJSON
Browse files Browse the repository at this point in the history
  • Loading branch information
Yar04ek committed Nov 29, 2023
1 parent 7ff8f13 commit cbaf606
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 18 deletions.
29 changes: 16 additions & 13 deletions js/docx/smoke/api_rgb_color/to_json.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();

10 changes: 5 additions & 5 deletions spec/docx/smoke/api_rgb_color_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit cbaf606

Please sign in to comment.