@@ -1284,6 +1284,136 @@ Controller.prototype.prepareForEmbedding = function (node, onPreparingDoneCallba
12841284 } ) ;
12851285} ;
12861286
1287+ Controller . prototype . exportAsLayout = function ( ) {
1288+ var container = Pencil . activeCanvas . drawingLayer ;
1289+
1290+ var pw = parseFloat ( this . activePage . width ) ;
1291+ var ph = parseFloat ( this . activePage . height ) ;
1292+
1293+ var items = [ ] ;
1294+
1295+ var outputPath = null ;
1296+ var outputDir = null ;
1297+ const IMAGE_FILE = "layout_image.png" ;
1298+
1299+ var devCollection = CollectionManager . getDeveloperStencil ( ) ;
1300+
1301+ Dom . workOn ( "//svg:g[@p:type='Shape']" , container , function ( g ) {
1302+ var dx = 0 ; //rect.left;
1303+ var dy = 0 ; //rect.top;
1304+
1305+ var owner = g . ownerSVGElement ;
1306+
1307+ if ( owner . parentNode && owner . parentNode . getBoundingClientRect ) {
1308+ var rect = owner . parentNode . getBoundingClientRect ( ) ;
1309+ dx = rect . left ;
1310+ dy = rect . top ;
1311+ }
1312+
1313+ debug ( "dx, dy: " + [ dx , dy ] ) ;
1314+
1315+ rect = g . getBoundingClientRect ( ) ;
1316+
1317+ var linkingInfo = {
1318+ node : g ,
1319+ sc : g . getAttributeNS ( PencilNamespaces . p , "sc" ) ,
1320+ refId : g . getAttributeNS ( PencilNamespaces . p , "def" ) ,
1321+ geo : {
1322+ x : rect . left - dx ,
1323+ y : rect . top - dy ,
1324+ w : rect . width - 2 ,
1325+ h : rect . height - 2
1326+ }
1327+ } ;
1328+
1329+ if ( devCollection ) {
1330+ if ( linkingInfo . sc ) {
1331+ if ( ! devCollection . getShortcutByDisplayName ( devCollection . id + ":" + linkingInfo . sc ) ) return ;
1332+ } else if ( linkingInfo . refId ) {
1333+ if ( ! devCollection . getShapeDefById ( linkingInfo . refId ) ) return ;
1334+ }
1335+ }
1336+ // if (!linkingInfo.refId) return;
1337+
1338+ items . push ( linkingInfo ) ;
1339+ } ) ;
1340+
1341+ var current = 0 ;
1342+ var thiz = this ;
1343+ var done = function ( ) {
1344+ var html = document . createElementNS ( PencilNamespaces . html , "html" ) ;
1345+
1346+ var body = document . createElementNS ( PencilNamespaces . html , "body" ) ;
1347+ html . appendChild ( body ) ;
1348+
1349+ var div = document . createElementNS ( PencilNamespaces . html , "div" ) ;
1350+ div . setAttribute ( "style" , "position: relative; padding: 0px; margin: 0px; width: " + pw + "px; height: " + ph + "px;" ) ;
1351+ body . appendChild ( div ) ;
1352+
1353+ /*
1354+ var canvas = document.createElementNS(PencilNamespaces.html, "canvas");
1355+ canvas.setAttribute("width", pw);
1356+ canvas.setAttribute("height", ph);
1357+
1358+ */
1359+
1360+ var bg = document . createElementNS ( PencilNamespaces . html , "img" ) ;
1361+ bg . setAttribute ( "style" , "width: " + pw + "px; height: " + ph + "px;" ) ;
1362+ bg . setAttribute ( "src" , IMAGE_FILE + "?ts=" + ( new Date ( ) . getTime ( ) ) ) ;
1363+ div . appendChild ( bg ) ;
1364+
1365+ for ( var i = 0 ; i < items . length ; i ++ ) {
1366+ var link = items [ i ] ;
1367+ var img = document . createElementNS ( PencilNamespaces . html , "img" ) ;
1368+ img . setAttribute ( "src" , "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVQYV2NgYAAAAAMAAWgmWQ0AAAAASUVORK5CYII=" ) ;
1369+ if ( link . sc ) {
1370+ img . setAttribute ( "sc-ref" , link . sc ) ;
1371+ } else {
1372+ img . setAttribute ( "ref" , link . refId ) ;
1373+ }
1374+ img . setAttribute ( "id" , link . refId ) ;
1375+ var css = new CSS ( ) ;
1376+ css . set ( "position" , "absolute" ) ;
1377+ css . set ( "left" , "" + link . geo . x + "px" ) ;
1378+ css . set ( "top" , "" + link . geo . y + "px" ) ;
1379+ css . set ( "width" , "" + link . geo . w + "px" ) ;
1380+ css . set ( "height" , "" + link . geo . h + "px" ) ;
1381+ /*
1382+ css.set("left", "" + (100 * link.geo.x / pw) + "%");
1383+ css.set("top", "" + (100 * link.geo.y / ph) + "%");
1384+ css.set("width", "" + (100 * link.geo.w / pw) + "%");
1385+ css.set("height", "" + (100 * link.geo.h / ph) + "%");
1386+ */
1387+ img . setAttribute ( "style" , css . toString ( ) ) ;
1388+
1389+ div . appendChild ( img ) ;
1390+ }
1391+
1392+ Dom . serializeNodeToFile ( html , outputPath , "" ) ;
1393+ CollectionManager . reloadDeveloperStencil ( ) ;
1394+ } ;
1395+
1396+
1397+ var defaultPath = "Layout.xhtml" ;
1398+ if ( devCollection ) {
1399+ defaultPath = path . join ( devCollection . installDirPath , defaultPath ) ;
1400+ }
1401+
1402+ dialog . showSaveDialog ( remote . getCurrentWindow ( ) , {
1403+ title : "Export Layout" ,
1404+ defaultPath : defaultPath ,
1405+ filters : [ { name : 'XHTML Layout' , extensions : [ "xhtml" ] } ]
1406+ } , function ( filePath ) {
1407+ if ( filePath ) {
1408+ outputPath = filePath ;
1409+ outputImage = path . join ( path . dirname ( outputPath ) , IMAGE_FILE ) ;
1410+ Pencil . rasterizer . rasterizePageToFile ( thiz . activePage , outputImage , function ( p , error ) {
1411+ done ( ) ;
1412+ } ) ;
1413+ }
1414+ } ) ;
1415+ } ;
1416+
12871417
12881418window . onbeforeunload = function ( event ) {
12891419 // Due to a change of Chrome 51, returning non-empty strings or true in beforeunload handler now prevents the page to unload
0 commit comments