Skip to content

Commit

Permalink
[7.6.0][CDE] ApiUniColor.ToJSON check (#1015)
Browse files Browse the repository at this point in the history
* feature: ApiUniColor.ToJSON

* ref: ApiUniColor.ToJSON

* ref: ApiUniColor.ToJSON

* ref: ApiUniColor.ToJSON

* ref: ApiUniColor.ToJSON
  • Loading branch information
Yar04ek authored and askonev committed Jan 17, 2024
1 parent 60049b9 commit 4202e73
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
25 changes: 25 additions & 0 deletions js/docx/smoke/api_uni_color/to_json.js
Original file line number Diff line number Diff line change
@@ -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();
10 changes: 10 additions & 0 deletions spec/docx/smoke/api_uni_color_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 4202e73

Please sign in to comment.