Skip to content

Commit

Permalink
Merge pull request #337 from evolus/development
Browse files Browse the repository at this point in the history
PR for 3.0.3 Release
  • Loading branch information
mbrainiac authored Jun 6, 2017
2 parents ac0d2c6 + a1131e4 commit 018e451
Show file tree
Hide file tree
Showing 46 changed files with 1,336 additions and 232 deletions.
2 changes: 2 additions & 0 deletions app/app.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,8 @@
<script type="text/javascript" src="views/tools/TemplateManagementDialog.js"></script>
<script type="text/javascript" src="views/tools/StencilCollectionBuilder.js"></script>
<script type="text/javascript" src="views/tools/StencilCollectionDetailDialog.js"></script>
<script type="text/javascript" src="views/tools/StencilShapeCanvasToolbar.js"></script>
<script type="text/javascript" src="views/tools/ShapeTestCanvasPane.js"></script>
<script type="text/javascript" src="pencil-core/common/EpzHandler.js"></script>
<script type="text/javascript" src="pencil-core/common/EpgzHandler.js"></script>
<script type="text/javascript" src="pencil-core/common/EpHandler.js"></script>
Expand Down
2 changes: 0 additions & 2 deletions app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,5 +134,3 @@ app.on("activate", function() {
process.on('uncaughtException', function (error) {
console.error(error);
});

console.log("Platform: " + process.platform.trim());
3 changes: 2 additions & 1 deletion app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "Pencil",
"productName": "Pencil",
"description": "An open-source GUI prototyping tool that is available for ALL platforms.",
"version": "3.0.2",
"version": "3.0.3",
"author": {
"name": "Evolus",
"url": "http://evolus.vn",
Expand Down Expand Up @@ -56,6 +56,7 @@
"q": "^1.4.1",
"rimraf": "^2.5.4",
"tar": "https://github.com/dgthanhan/node-tar/archive/6086b1ea82137c61eea4efe882dd514590e5b7a8.tar.gz",
"tar-fs": "^1.15.2",
"tar.gz": "^1.0.5",
"tmp": "0.0.31",
"unzip2": "^0.2.5"
Expand Down
2 changes: 1 addition & 1 deletion app/pencil-core/canvasHelper/canvasImpl.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ CanvasImpl.setupGrid = function () {
}
};
CanvasImpl.drawMargin = function () {
var unzommedMargin = Pencil.controller.getDocumentPageMargin();
var unzommedMargin = (Pencil.controller && !this.options.ignorePageMarging) ? Pencil.controller.getDocumentPageMargin() : 0;
if (!unzommedMargin) {
if (this.marginPath) this.marginPath.parentNode.removeChild(this.marginPath);
this.marginPath = null;
Expand Down
2 changes: 1 addition & 1 deletion app/pencil-core/canvasHelper/snappingHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ SnappingHelper.prototype.rebuildSnappingGuide = function () {
}
}

var margin = Pencil.controller.getDocumentPageMargin();
var margin = (Pencil.controller && !this.canvas.options.ignorePageMarging) ? Pencil.controller.getDocumentPageMargin() : 0;
if (margin) {
var uid = Util.newUUID();
this.snappingGuide[uid] = {
Expand Down
54 changes: 33 additions & 21 deletions app/pencil-core/common/Canvas.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function Canvas(element) {
function Canvas(element, options) {
this.element = element;
this.oldElement = "";
this.__delegate("addEventListener", "hasAttribute", "getAttribute", "setAttribute", "setAttributeNS", "removeAttribute", "removeAttributeNS", "dispatchEvent");
Expand All @@ -18,6 +18,9 @@ function Canvas(element) {
var thiz = this;
this.lockPointerFunction = null;
this.autoScrollTimout = null;

this.options = options || {};

this.startAutoScrollFunction = function(func) {
if (this.autoScrollTimout == null) {
// this.lockPointerFunction = function () {
Expand Down Expand Up @@ -206,7 +209,7 @@ function Canvas(element) {
document.removeEventListener("mousemove", arguments.callee, false);
return;
}
if (thiz.controllerHeld && thiz.currentController &&
if (thiz.controllerHeld && thiz.currentController && thiz._scrollPane &&
(thiz._scrollPane.clientHeight < thiz._scrollPane.scrollHeight || thiz._scrollPane.clientWidth < thiz._scrollPane.scrollWidth)) {
thiz.handleScrollPane(event);
}
Expand Down Expand Up @@ -650,23 +653,13 @@ Canvas.prototype.insertShape = function (shapeDef, bound, overridingValueMap) {
overridingValueMap ? overridingValueMap : null ]);

};
Canvas.prototype.insertShapeImpl_ = function (shapeDef, bound,
overridingValueMap) {

// instantiate the shape using the shapedef
var shape = this.ownerDocument.createElementNS(PencilNamespaces.svg, "g");
shape.setAttributeNS(PencilNamespaces.p, "p:type", "Shape");
shape.setAttributeNS(PencilNamespaces.p, "p:def", shapeDef.id);


if (overridingValueMap && overridingValueMap._shortcut) {
shape.setAttributeNS(PencilNamespaces.p, "p:sc",
overridingValueMap._shortcut.displayName);
Canvas.prototype.invalidateShapeContent = function (shape, shapeDef) {
var count = shape.childNodes.length;
for (var i = count - 1; i >= 0; i --) {
var child = shape.childNodes[i];
if (child.namespaceURI == PencilNamespaces.p && child.localName == "metadata") continue;
shape.removeChild(child);
}

shape.appendChild(this.ownerDocument.createElementNS(PencilNamespaces.p,
"p:metadata"));

for (var i = 0; i < shapeDef.contentNode.childNodes.length; i++) {
shape.appendChild(this.ownerDocument.importNode(
shapeDef.contentNode.childNodes[i], true));
Expand All @@ -687,6 +680,25 @@ Canvas.prototype.insertShapeImpl_ = function (shapeDef, bound,
});

Dom.renewId(shape);
};
Canvas.prototype.insertShapeImpl_ = function (shapeDef, bound,
overridingValueMap) {

// instantiate the shape using the shapedef
var shape = this.ownerDocument.createElementNS(PencilNamespaces.svg, "g");
shape.setAttributeNS(PencilNamespaces.p, "p:type", "Shape");
shape.setAttributeNS(PencilNamespaces.p, "p:def", shapeDef.id);


if (overridingValueMap && overridingValueMap._shortcut) {
shape.setAttributeNS(PencilNamespaces.p, "p:sc",
overridingValueMap._shortcut.displayName);
}

shape.appendChild(this.ownerDocument.createElementNS(PencilNamespaces.p,
"p:metadata"));

this.invalidateShapeContent(shape, shapeDef);

// add the newly created shape into the drawing layer
this.drawingLayer.appendChild(shape);
Expand Down Expand Up @@ -872,7 +884,8 @@ Canvas.prototype.handleMouseWheel = function(event) {
}

Canvas.prototype.handleScrollPane = function(event) {
var thiz =this;
if (!this._scrollPane) return;
var thiz = this;
var scrollBarSize = 15;
var scrollValue = 20;
var loc = { x: event.clientX, y: event.clientY };
Expand Down Expand Up @@ -2408,8 +2421,7 @@ Canvas.prototype.run = function (job, targetObject, actionName, args) {
Console.dumpError(e);
} finally {
this._saveMemento(actionName);
if (!Pencil.controller.activePageLoading)
this._sayContentModified();
if (Pencil.controller && !Pencil.controller.activePageLoading) this._sayContentModified();
}

};
Expand Down
3 changes: 3 additions & 0 deletions app/pencil-core/common/DocumentHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ DocumentHandler.prototype.saveDocument = function (onSaved) {
};

DocumentHandler.prototype._saveBoundDocument = function (onSaved) {
this.isSaving = true;
ApplicationPane._instance.busy();
this.controller.updateCanvasState();

Expand All @@ -235,6 +236,7 @@ DocumentHandler.prototype._saveBoundDocument = function (onSaved) {
thiz.getActiveHandler().saveDocument(thiz.controller.documentPath)
.then(function () {
ApplicationPane._instance.unbusy();
thiz.isSaving = false;
thiz.controller.sayDocumentSaved();

if (onSaved) onSaved();
Expand All @@ -244,6 +246,7 @@ DocumentHandler.prototype._saveBoundDocument = function (onSaved) {
})
.catch (function (err) {
ApplicationPane._instance.unbusy();
thiz.isSaving = false;
Dialog.error("Error when saving document: " + err);

thiz.controller.applicationPane.onDocumentChanged();
Expand Down
43 changes: 32 additions & 11 deletions app/pencil-core/common/EpgzHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,41 @@ __extend(FileHandler, EpgzHandler);

EpgzHandler.EXT = ".epgz";
EpgzHandler.prototype.loadDocument = function(filePath) {
const zlib = require('zlib');
const tarfs = require('tar-fs');

var thiz = this;
return new Promise(function (resolve, reject) {
const decompress = require('decompress');
const decompressTargz = require('decompress-targz');

decompress(filePath, Pencil.documentHandler.tempDir.name, {
plugins: [
decompressTargz()
]
}).then(() => {
thiz.parseDocument(filePath, resolve);
}).catch ((err) => {
reject(new Error("File could not be loaded: " + err));
});
var wrappedReject = function (error) {
var recoverable = fs.existsSync(path.join(Pencil.documentHandler.tempDir.name, "content.xml"));
if (!recoverable) {
reject(error);
} else {
ApplicationPane._instance.unbusy();

Dialog.confirm("File loading error", "There was an error that prevented your document from being fully loaded. The document file seems to be corrupted.\n" +
"Do you want Pencil to try loading the document anyway?",
"Yes, try anyway", function () {
ApplicationPane._instance.busy();
thiz.parseDocument(filePath, resolve);
},
"Cancel", function () {
ApplicationPane._instance.busy();
reject(error);
});
}
};

fs.createReadStream(filePath)
.pipe(zlib.Gunzip())
.on("error", wrappedReject)
.pipe(tarfs.extract(Pencil.documentHandler.tempDir.name)
.on("error", wrappedReject)
.on("finish", function() {
console.log("Successfully extracted.");
thiz.parseDocument(filePath, resolve);
}));
});
}

Expand Down
76 changes: 70 additions & 6 deletions app/pencil-core/common/FontLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ FontLoader.prototype.removeFont = function (font, callback) {
});
}.bind(this), "Cancel");
};
FontLoader.prototype.setAutoEmbed = function (font, autoEmbed, callback) {
ApplicationPane._instance.busy();
this.userRepo.setAutoEmbed(font, autoEmbed);
this.loadFonts(function () {
if (callback) callback();
ApplicationPane._instance.unbusy();
});
};
FontLoader.prototype.getAllInstalledFonts = function () {
this.userRepo.load();
if (this.documentRepo) this.documentRepo.load();
Expand Down Expand Up @@ -115,10 +123,21 @@ FontLoader.prototype.embedToDocumentRepo = function (faces) {
var shouldSave = false;
faces.forEach(function (f) {
console.log("Embeding " + f);
if (this.documentRepo.getFont(f)) return;
var font = this.userRepo.getFont(f);
var userFont = this.documentRepo.getFont(f);
if (userFont) {
if (!font.autoEmbed) {
this.documentRepo.removeFont(userFont);
}
return;
}
if (!font) return;
console.log("user font found", font);
if (!font.autoEmbed) {
console.log(" > " + f + " is not auto-embeded.");
return;
}

var font = JSON.parse(JSON.stringify(font));
font.location = null;
console.log(" >> cloned", font);
Expand Down Expand Up @@ -173,10 +192,12 @@ FontRepository.prototype.load = function () {
var fontName = node.getAttribute("name");
var location = node.getAttribute("location");
var source = node.getAttribute("source") || "";
var autoEmbed = node.getAttribute("auto-embed") != "false";
var font = {
name: fontName,
location: location,
source: source,
autoEmbed: autoEmbed,
variants: []
};
thiz.fonts.push(font);
Expand Down Expand Up @@ -205,16 +226,47 @@ FontRepository.prototype.load = function () {
console.error(e);
}
};
FontRepository.SUPPORTED_VARIANTS = {
regular: {weight: "normal", style: "normal"},
bold: {weight: "bold", style: "normal"},
italic: {weight: "normal", style: "italic"},
boldItalic: {weight: "bold", style: "italic"}
FontRepository.SUPPORTED_WEIGHTS = [
{id: "thin", weight: "100", displayName: "Thin", shortName: "T"},
{id: "ulight", weight: "200", displayName: "Ultra Light", shortName: "UL"},
{id: "light", weight: "300", displayName: "Light", shortName: "L"},
{id: "regular", weight: "normal", displayName: "Regular", shortName: "R"},
{id: "medium", weight: "500", displayName: "Medium", shortName: "M"},
{id: "sbold", weight: "600", displayName: "Semi Bold", shortName: "SB"},
{id: "bold", weight: "bold", displayName: "Bold", shortName: "B"},
{id: "xbold", weight: "800", displayName: "Extra Bold", shortName: "XB"},
{id: "black", weight: "900", displayName: "Black", shortName: "BL"},
];

FontRepository.SUPPORTED_VARIANTS = {};
FontRepository.WEIGHT_MAP = {};

for (var weight of FontRepository.SUPPORTED_WEIGHTS) {
FontRepository.SUPPORTED_VARIANTS[weight.id] = {
weight: weight.weight,
style: "normal",
displayName: weight.displayName
};
FontRepository.SUPPORTED_VARIANTS[weight.id + "Italic"] = {
weight: weight.weight,
style: "italic",
displayName: weight.displayName + " Italic"
};

FontRepository.WEIGHT_MAP[weight.weight] = weight;
}
//@DEPRECATED, this is kept for backward compat only
FontRepository.SUPPORTED_VARIANTS["italic"] = {
weight: "normal",
style: "italic",
displayName: "Regular Italic"
};

FontRepository.prototype.addFont = function (data) {
if (!this.loaded) this.load();
var font = {
name: data.fontName,
autoEmbed: typeof(data.autoEmbed) === "boolean" ? data.autoEmbed : false,
location: null,
source: data.source || "",
variants: []
Expand Down Expand Up @@ -264,6 +316,17 @@ FontRepository.prototype.removeFont = function (font) {
this.save();
this.loaded = false;
};
FontRepository.prototype.setAutoEmbed = function (font, autoEmbed) {
if (!this.loaded) this.load();

font = this.getFont(font.name);
if (!font) return;

font.autoEmbed = autoEmbed;
this.save();
this.loaded = false;
};

FontRepository.prototype.save = function () {
if (!fsExistSync(this.dirPath)) {
fs.mkdirSync(this.dirPath);
Expand Down Expand Up @@ -301,6 +364,7 @@ FontRepository.prototype.save = function () {

fontNode.setAttribute("location", font.location);
fontNode.setAttribute("source", font.source || "");
fontNode.setAttribute("auto-embed", font.autoEmbed);

font.variants.forEach(function (variant) {
var fontStyleNode = dom.createElementNS(PencilNamespaces.p, "FontStyle");
Expand Down
Loading

0 comments on commit 018e451

Please sign in to comment.