Skip to content

Commit

Permalink
Merge pull request #291 from evolus/development
Browse files Browse the repository at this point in the history
Release 3.0.1
  • Loading branch information
mbrainiac authored Mar 27, 2017
2 parents d0c3199 + 51b8159 commit 21cc44e
Show file tree
Hide file tree
Showing 26 changed files with 1,090 additions and 275 deletions.
1 change: 1 addition & 0 deletions app/app.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@
<script type="text/javascript" src="views/collections/PrivateCollectionDialog.js"></script>
<script type="text/javascript" src="views/collections/PrivateCollectionMenu.js"></script>
<script type="text/javascript" src="views/collections/ShowAllCollectionMenu.js"></script>
<script type="text/javascript" src="views/collections/CollectionResourceBrowserDialog.js"></script>

<script type="text/javascript" src="pencil-core/definition/collectionRepository.js"></script>
<script type="text/javascript" src="views/collections/CollectionBrowserDialog.js"></script>
Expand Down
13 changes: 12 additions & 1 deletion app/lib/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,18 @@ function loadFontManager() {
fmPath = platform;
}

return require(`./font-manager/${fmPath}/fontmanager`);
try {
return require(`./font-manager/${fmPath}/fontmanager`);
} catch (e) {
console.error("Failed to load pre-compiled font manager, returning a dummy version.");
return {
getAvailableFontsSync: function () {
return [
{ family: "Arial"}
];
}
}
}
}

exports.fontManager = loadFontManager();
10 changes: 9 additions & 1 deletion app/lib/widget/Common.js
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,15 @@ BaseWidget.signalOnAttachedRecursively = function (container) {
}
if (container.__widget && container.__widget.onAttached) container.__widget.onAttached();
};

BaseWidget.signalOnSizeChangedRecursively = function (container) {
if (container.__widget && container.__widget.onSizeChanged) {
container.__widget.onSizeChanged();
}
for (var i = 0; i < container.childNodes.length; i++) {
var child = container.childNodes[i];
BaseWidget.signalOnSizeChangedRecursively(child);
}
};
BaseWidget.prototype.bind = function (eventName, f, node) {
var n = node || this.__node;
var thiz = this;
Expand Down
2 changes: 2 additions & 0 deletions app/lib/widget/SplitView.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ widget.SplitView = function () {
var margin = Math.round(W / 10);
p = Math.min(Math.max(p, margin), W - margin);
currentSplitView.setSplitViewPosition(p);
BaseWidget.signalOnSizeChangedRecursively(currentSplitView.node());

currentSplitView.moved = true;
}

Expand Down
2 changes: 1 addition & 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.0",
"version": "3.0.1",
"author": {
"name": "Evolus",
"url": "http://evolus.vn",
Expand Down
2 changes: 0 additions & 2 deletions app/pencil-core/behavior/SVGTextLayout.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ SVGHTMLRenderer.prototype.isInline = function (node) {
return (display == "inline" || display == "inline-block");
};
SVGHTMLRenderer.prototype.layout = function (nodes, view, outmost) {
console.log("NODES" , nodes);
var layouts = [];
var inlines = [];
for (var i = 0; i < nodes.length; i ++) {
Expand Down Expand Up @@ -283,7 +282,6 @@ SVGHTMLRenderer.prototype.renderHTML = function (html, container, view) {
}

div.innerHTML = html;
console.log("IMPORT HTML:", div);
this.render(div.childNodes, container, view);

div.parentNode.removeChild(div);
Expand Down
2 changes: 1 addition & 1 deletion app/pencil-core/behavior/commonBehaviors.js
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ Pencil.behaviors.NPatchDomContent = function (nPatch, dim) {
this.appendChild(buildNPatchDomFragment(nPatch, dim));
};

Pencil.behaviors.NPatchDomContentFromImage = function (imageData, dim) {
Pencil.behaviors.NPatchDomContentFromImage = function (imageData, dim, xAnchorMaps, yAnchorMaps) {
//sorting
var xCells = imageData.xCells;
if (!xCells || xCells.length == 0) xCells = [{from: 0, to: imageData.w}];
Expand Down
130 changes: 130 additions & 0 deletions app/pencil-core/common/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -1284,6 +1284,136 @@ Controller.prototype.prepareForEmbedding = function (node, onPreparingDoneCallba
});
};

Controller.prototype.exportAsLayout = function () {
var container = Pencil.activeCanvas.drawingLayer;

var pw = parseFloat(this.activePage.width);
var ph = parseFloat(this.activePage.height);

var items = [];

var outputPath = null;
var outputDir = null;
const IMAGE_FILE = "layout_image.png";

var devCollection = CollectionManager.getDeveloperStencil();

Dom.workOn("//svg:g[@p:type='Shape']", container, function (g) {
var dx = 0; //rect.left;
var dy = 0; //rect.top;

var owner = g.ownerSVGElement;

if (owner.parentNode && owner.parentNode.getBoundingClientRect) {
var rect = owner.parentNode.getBoundingClientRect();
dx = rect.left;
dy = rect.top;
}

debug("dx, dy: " + [dx, dy]);

rect = g.getBoundingClientRect();

var linkingInfo = {
node: g,
sc: g.getAttributeNS(PencilNamespaces.p, "sc"),
refId: g.getAttributeNS(PencilNamespaces.p, "def"),
geo: {
x: rect.left - dx,
y: rect.top - dy,
w: rect.width - 2,
h: rect.height - 2
}
};

if (devCollection) {
if (linkingInfo.sc) {
if (!devCollection.getShortcutByDisplayName(devCollection.id + ":" + linkingInfo.sc)) return;
} else if (linkingInfo.refId) {
if (!devCollection.getShapeDefById(linkingInfo.refId)) return;
}
}
// if (!linkingInfo.refId) return;

items.push(linkingInfo);
});

var current = 0;
var thiz = this;
var done = function () {
var html = document.createElementNS(PencilNamespaces.html, "html");

var body = document.createElementNS(PencilNamespaces.html, "body");
html.appendChild(body);

var div = document.createElementNS(PencilNamespaces.html, "div");
div.setAttribute("style", "position: relative; padding: 0px; margin: 0px; width: " + pw + "px; height: " + ph + "px;");
body.appendChild(div);

/*
var canvas = document.createElementNS(PencilNamespaces.html, "canvas");
canvas.setAttribute("width", pw);
canvas.setAttribute("height", ph);
*/

var bg = document.createElementNS(PencilNamespaces.html, "img");
bg.setAttribute("style", "width: " + pw + "px; height: " + ph + "px;");
bg.setAttribute("src", IMAGE_FILE + "?ts=" + (new Date().getTime()));
div.appendChild(bg);

for (var i = 0; i < items.length; i ++) {
var link = items[i];
var img = document.createElementNS(PencilNamespaces.html, "img");
img.setAttribute("src", "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVQYV2NgYAAAAAMAAWgmWQ0AAAAASUVORK5CYII=");
if (link.sc) {
img.setAttribute("sc-ref", link.sc);
} else {
img.setAttribute("ref", link.refId);
}
img.setAttribute("id", link.refId);
var css = new CSS();
css.set("position", "absolute");
css.set("left", "" + link.geo.x + "px");
css.set("top", "" + link.geo.y + "px");
css.set("width", "" + link.geo.w + "px");
css.set("height", "" + link.geo.h + "px");
/*
css.set("left", "" + (100 * link.geo.x / pw) + "%");
css.set("top", "" + (100 * link.geo.y / ph) + "%");
css.set("width", "" + (100 * link.geo.w / pw) + "%");
css.set("height", "" + (100 * link.geo.h / ph) + "%");
*/
img.setAttribute("style", css.toString());

div.appendChild(img);
}

Dom.serializeNodeToFile(html, outputPath, "");
CollectionManager.reloadDeveloperStencil();
};


var defaultPath = "Layout.xhtml";
if (devCollection) {
defaultPath = path.join(devCollection.installDirPath, defaultPath);
}

dialog.showSaveDialog(remote.getCurrentWindow(), {
title: "Export Layout",
defaultPath: defaultPath,
filters: [{name: 'XHTML Layout', extensions: ["xhtml"]}]
}, function (filePath) {
if (filePath) {
outputPath = filePath;
outputImage = path.join(path.dirname(outputPath), IMAGE_FILE);
Pencil.rasterizer.rasterizePageToFile(thiz.activePage, outputImage, function (p, error) {
done();
});
}
});
};


window.onbeforeunload = function (event) {
// Due to a change of Chrome 51, returning non-empty strings or true in beforeunload handler now prevents the page to unload
Expand Down
Loading

0 comments on commit 21cc44e

Please sign in to comment.