Skip to content
Permalink
Browse files

Implement set image width and size in file question for https://surve…

  • Loading branch information
gologames committed Mar 20, 2020
1 parent 5b6701f commit fca47be6fc0158bcb673141e5c3d9b7bf6dd891d
Showing with 55 additions and 12 deletions.
  1. +8 −0 src/flat_layout/flat_file.ts
  2. +47 −12 tests/flat_file.test.ts
@@ -25,6 +25,14 @@ export class FlatFile extends FlatQuestion {
point, this.question, this.controller, item.name, item.content));
if (this.question.canPreviewImage(item)) {
let imageSize: ISize = await SurveyHelper.getImageSize(item.content);
if (this.question.imageWidth) {
imageSize.width = SurveyHelper.parseWidth(this.question.imageWidth,
SurveyHelper.getPageAvailableWidth(this.controller));
}
if (this.question.imageHeight) {
imageSize.height = SurveyHelper.parseWidth(this.question.imageHeight,
SurveyHelper.getPageAvailableWidth(this.controller));
}
let imagePoint: IPoint = SurveyHelper.createPoint(compositeFlat);
imagePoint.yTop += this.controller.unitHeight *
FlatFile.IMAGE_GAP_SCALE;
@@ -38,7 +38,7 @@ test('Check one text file', async () => {
elements: [
{
type: 'file',
name: 'faque',
name: 'faqueonetxt',
titleLocation: 'hidden',
defaultValue: [
{
@@ -66,7 +66,7 @@ test('Check two text files', async () => {
elements: [
{
type: 'file',
name: 'faque',
name: 'faquetwotxt',
titleLocation: 'hidden',
allowMultiple: true,
defaultValue: [
@@ -107,14 +107,13 @@ test('Check two text files', async () => {
TestHelper.equalRect(expect, flats[0][0], assumeFile);
});
test('Check one image 16x16px file', async () => {
let oldFunction = SurveyHelper.getImageSize;
let imageSize: ISize = { width: 170, height: 50 };
SurveyHelper.getImageSize = async (url: string) => { return imageSize };
let json = {
let json: any = {
elements: [
{
type: 'file',
name: 'faque',
name: 'faqueoneimg',
titleLocation: 'hidden',
allowImagesPreview: true,
defaultValue: [
@@ -130,7 +129,6 @@ test('Check one image 16x16px file', async () => {
let survey: SurveyPDF = new SurveyPDF(json, TestHelper.defaultOptions);
let controller: DocController = new DocController(TestHelper.defaultOptions);
let flats: IPdfBrick[][] = await FlatSurvey.generateFlats(survey, controller);
SurveyHelper.getImageSize = oldFunction;
expect(flats.length).toBe(1);
expect(flats[0].length).toBe(1);
controller.margins.left += controller.unitWidth;
@@ -143,16 +141,14 @@ test('Check one image 16x16px file', async () => {
};
TestHelper.equalRect(expect, flats[0][0], assumeFile);
});

test('Check one image 16x16px file', async () => {
let oldFunction = SurveyHelper.getImageSize;
test('Check one image 16x16px file shorter than text', async () => {
let imageSize: ISize = { width: 50, height: 50 };
SurveyHelper.getImageSize = async (url: string) => { return imageSize };
let json = {
let json: any = {
elements: [
{
type: 'file',
name: 'faque',
name: 'faqueoneimgshrt',
titleLocation: 'hidden',
allowImagesPreview: true,
defaultValue: [
@@ -168,7 +164,6 @@ test('Check one image 16x16px file', async () => {
let survey: SurveyPDF = new SurveyPDF(json, TestHelper.defaultOptions);
let controller: DocController = new DocController(TestHelper.defaultOptions);
let flats: IPdfBrick[][] = await FlatSurvey.generateFlats(survey, controller);
SurveyHelper.getImageSize = oldFunction;
expect(flats.length).toBe(1);
expect(flats[0].length).toBe(1);
controller.margins.left += controller.unitWidth;
@@ -180,4 +175,44 @@ test('Check one image 16x16px file', async () => {
controller.unitHeight * (1.0 + FlatFile.IMAGE_GAP_SCALE)
};
TestHelper.equalRect(expect, flats[0][0], assumeFile);
});
test('Check one image 16x16px with set size', async () => {
let imageSize: ISize = { width: 50, height: 50 };
SurveyHelper.getImageSize = async (url: string) => { return imageSize };
let json: any = {
elements: [
{
type: 'file',
name: 'faqueoneimgwithsz',
titleLocation: 'hidden',
allowImagesPreview: true,
defaultValue: [
{
name: 'cat.png',
type: 'image/png',
content: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAAA3NCSVQICAjb4U/gAAAAt1BMVEVHcExTXGROYmJIT1ZPXmVJV11ES1JYZ24+SE5JU1s+R0xVYmtYZW1ETlRRXWVUYWpKV1xZZ25YZW5YanNrfIdTYWlaZ29nd4JUYmhIU1lHUVtRXWQ+SlA6QkouNzpFT1ZCS1JSXWVxhI98kp53iZZSXmVcaXE5QkdCTFNndn9WY2tZZm5canJfbXVbZ29hcHlXZGxtfYVNWmFRXWVCTFNKVl04QEdoeINnZGxrc3uAk6Fzb3dxg43scHiMAAAAKnRSTlMALwQXZU4MImyJQbCrPOPZRdOHx4X4t2fR0SfsoHhYseyioqbHwOy+59gMe1UiAAAAuElEQVQYlU2P5xKCQAyEI1gABVSKUu3tOgL2938u74Ybx/2xk3yT2SQAPw2Yb8KfRp6VzAxVDDVwYej1ZbHbG9tQTy030sJP+1po4MfSZs+qsrp+KubSg8e7Wq8mk/E44LinwqJr22IskCA4UgBiUqueUUqJ2gLzO0MCC8Ypx1MFXEIEqhFGjB/0zTXNbPvcXOkx7YjFbYDydsq7DIAeKyS9mSYadGBR51A0JVwy/dcyScFxwLAdgC+IFhIbrHyDqAAAAABJRU5ErkJggg=='
}
],
imageWidth: '160pt',
imageHeight: '110pt',
}
]
};
let survey: SurveyPDF = new SurveyPDF(json, TestHelper.defaultOptions);
let controller: DocController = new DocController(TestHelper.defaultOptions);
let flats: IPdfBrick[][] = await FlatSurvey.generateFlats(survey, controller);
expect(flats.length).toBe(1);
expect(flats[0].length).toBe(1);
controller.margins.left += controller.unitWidth;
let assumeFile: IRect = {
xLeft: controller.leftTopPoint.xLeft,
xRight: controller.leftTopPoint.xLeft +
SurveyHelper.parseWidth(json.elements[0].imageWidth,
SurveyHelper.getPageAvailableWidth(controller)),
yTop: controller.leftTopPoint.yTop,
yBot: controller.leftTopPoint.yTop + SurveyHelper.parseWidth(json.elements[0].imageHeight,
SurveyHelper.getPageAvailableWidth(controller)) +
controller.unitHeight * (1.0 + FlatFile.IMAGE_GAP_SCALE)
};
TestHelper.equalRect(expect, flats[0][0], assumeFile);
});

0 comments on commit fca47be

Please sign in to comment.
You can’t perform that action at this time.