Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[7.6.0][CDE] ApiStroke.ToJSON check #1010

Merged
merged 11 commits into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions js/docx/smoke/api_stroke/to_json.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
builder.CreateFile("docx");
var oGs1 = Api.CreateGradientStop(Api.CreateRGBColor(255, 213, 191), 0);
var oGs2 = Api.CreateGradientStop(Api.CreateRGBColor(255, 111, 61), 100000);
var arr = []
arr.push(Api.CreateBlipFill("https://api.onlyoffice.com/content/img/docbuilder/examples/icon_DocumentEditors.png", "tile"));
arr.push(Api.CreateSolidFill(Api.CreateRGBColor(102, 0, 204)))
arr.push(Api.CreateLinearGradientFill([oGs1, oGs2], 5400000))
arr.push(Api.CreateNoFill())
arr.push(Api.CreatePatternFill("cross", Api.CreateRGBColor(255, 111, 61), Api.CreateRGBColor(51, 51, 51)))
arr.push(Api.CreateRadialGradientFill([oGs1, oGs2]))
arr = arr.map((fill) => {
var oStroke = Api.CreateStroke(10 * 36000, fill);
return oStroke.ToJSON()
})
GlobalVariable["arrStroke"] = arr;
builder.CloseFile();

//////////////////////

builder.CreateFile("docx");
var arrStroke = GlobalVariable["arrStroke"];
arrStroke.forEach((stroke) => {
var odoc = Api.GetDocument();
var opar = Api.CreateParagraph();
opar.AddText(stroke)
odoc.Push(opar)
})
arrStroke.forEach((stroke) => {
var oStroke = Api.FromJSON(stroke);
var odoc = Api.GetDocument();
var opar = Api.CreateParagraph();
var oGs1 = Api.CreateGradientStop(Api.CreateRGBColor(255, 213, 191), 0);
var oGs2 = Api.CreateGradientStop(Api.CreateRGBColor(255, 111, 61), 100000);
var oFill = Api.CreateRadialGradientFill([oGs1, oGs2]);
var oDrawing = Api.CreateShape("star10", 10000 * 593, 10000 * 590, oFill, oStroke);
opar.AddDrawing(oDrawing);
odoc.Push(opar);
});
builder.SaveFile("docx", "StrokeToJson.docx");
builder.CloseFile();
9 changes: 9 additions & 0 deletions spec/docx/smoke/api_stroke_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 'ApiStroke | ToJSON method' do
docx = builder.build_and_parse('js/docx/smoke/api_stroke/to_json.js')
type = TestData.fill_types
docx.elements[1..6].each_with_index do |el, i|
json = JSON.parse(el.nonempty_runs.first.text)
expect(type[i]).to eq(json['fill']['fill']['type'])
end
end
end
6 changes: 6 additions & 0 deletions spec/test_data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ def self.number_formats
'0.00E+00'].freeze
end

# CDE fill types
# @return [Array<String (frozen)>]
def self.fill_types
%w[blipFill solid gradFill noFill pattFill gradFill]
end

# @return [Array<String (frozen)>]
def self.libs
%w[DjVuFile.dll
Expand Down
Loading