Skip to content
Open
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
32 changes: 24 additions & 8 deletions lib/element-properties.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class ElementProperties {
this._y = 0;
this._cx = 0;
this._cy = 0;
this._dpi = 72;
this.options = {};
}

Expand All @@ -16,20 +17,21 @@ class ElementProperties {
this.y(this._y);
this.cx(this._cx);
this.cy(this._cy);
this.dpi(this._dpi);
}

x(val) {
if (arguments.length === 0) {
if (this.properties !== undefined) {
return PptxUnitHelper.toPixels(this.properties['a:off'][0]['$'].x);
return PptxUnitHelper.toPixels(this.properties['a:off'][0]['$'].x, this.properties['a:off'][0]['$'].dpi);
} else {
return this._x;
}
} else {
this._x = val;

if (this.properties !== undefined) {
this.properties['a:off'][0]['$'].x = PptxUnitHelper.fromPixels(val);
this.properties['a:off'][0]['$'].x = PptxUnitHelper.fromPixels(val, this._dpi);
}
}

Expand All @@ -39,15 +41,15 @@ class ElementProperties {
y(val) {
if (arguments.length === 0) {
if (this.properties !== undefined) {
return PptxUnitHelper.toPixels(this.properties['a:off'][0]['$'].y);
return PptxUnitHelper.toPixels(this.properties['a:off'][0]['$'].y, this.properties['a:off'][0]['$'].dpi);
} else {
return this._y;
}
} else {
this._y = val;

if (this.properties !== undefined) {
this.properties['a:off'][0]['$'].y = PptxUnitHelper.fromPixels(val);
this.properties['a:off'][0]['$'].y = PptxUnitHelper.fromPixels(val, this._dpi);
}
}

Expand All @@ -57,15 +59,15 @@ class ElementProperties {
cx(val) {
if (arguments.length === 0) {
if (this.properties !== undefined) {
return PptxUnitHelper.toPixels(this.properties['a:ext'][0]['$'].cx);
return PptxUnitHelper.toPixels(this.properties['a:ext'][0]['$'].cx, this.properties['a:off'][0]['$'].dpi);
} else {
return this._cx;
}
} else {
this._cx = val;

if (this.properties !== undefined) {
this.properties['a:ext'][0]['$'].cx = PptxUnitHelper.fromPixels(val);
this.properties['a:ext'][0]['$'].cx = PptxUnitHelper.fromPixels(val, this._dpi);
}
}

Expand All @@ -75,15 +77,29 @@ class ElementProperties {
cy(val) {
if (arguments.length === 0) {
if (this.properties !== undefined) {
return PptxUnitHelper.toPixels(this.properties['a:ext'][0]['$'].cy);
return PptxUnitHelper.toPixels(this.properties['a:ext'][0]['$'].cy, this.properties['a:off'][0]['$'].dpi);
} else {
return this._cy;
}
} else {
this._cy = val;

if (this.properties !== undefined) {
this.properties['a:ext'][0]['$'].cy = PptxUnitHelper.fromPixels(val);
this.properties['a:ext'][0]['$'].cy = PptxUnitHelper.fromPixels(val, this._dpi);
}
}

return this;
}

dpi(val) {
if (arguments.length === 0) {
return this._dpi;
} else {
this._dpi = val;

if (this.properties !== undefined) {
this.properties['a:off'][0]['$'].dpi = val;
}
}

Expand Down
16 changes: 8 additions & 8 deletions lib/helpers/unit-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,24 @@ class PptxUnitHelper {
return Math.floor(val * 914400);
}

static fromPoints(val) {
return Math.floor(val * 914400 / 72);
static fromPoints(val, dpi = 72) {
return Math.floor(val * 914400 / dpi);
}

static fromPixels(val) {
return Math.floor(val * 914400 / 72);
static fromPixels(val, dpi = 72) {
return Math.floor(val * 914400 / dpi);
}

static toPixels(val) {
return val * 72 / 914400;
static toPixels(val, dpi = 72) {
return val * dpi / 914400;
}

static toInches(val) {
return val / 914400;
}

static toPoints(val) {
return val / 914400 * 72;
static toPoints(val, dpi = 72) {
return val / 914400 * dpi;
}

static fromCm(val) {
Expand Down