Skip to content

Commit 3639ddd

Browse files
author
maeda-m
committed
Implemented load a new layout schema
1 parent 2863594 commit 3639ddd

19 files changed

Lines changed: 355 additions & 452 deletions

src/app/boot.js

Lines changed: 40 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -490,10 +490,11 @@ thin.init_ = function() {
490490
pageHeightInput.setEnabled(false);
491491
pageHeightInput.setValue('');
492492

493-
pageMarginTop.setValue(thin.layout.FormatPage.DEFAULT_SETTINGS['margin-top']);
494-
pageMarginBottom.setValue(thin.layout.FormatPage.DEFAULT_SETTINGS['margin-bottom']);
495-
pageMarginLeft.setValue(thin.layout.FormatPage.DEFAULT_SETTINGS['margin-left']);
496-
pageMarginRight.setValue(thin.layout.FormatPage.DEFAULT_SETTINGS['margin-right']);
493+
var defaultMargin = thin.layout.FormatPage.DEFAULT_SETTINGS['margin'];
494+
pageMarginTop.setValue(defaultMargin[0]);
495+
pageMarginBottom.setValue(defaultMargin[1]);
496+
pageMarginLeft.setValue(defaultMargin[2]);
497+
pageMarginRight.setValue(defaultMargin[3]);
497498

498499
dialog.setVisible(true);
499500
});
@@ -572,7 +573,7 @@ thin.init_ = function() {
572573
}
573574
}
574575

575-
// try {
576+
try {
576577
var workspace = thin.core.Workspace.create(file);
577578
if (workspace) {
578579
var targetVersion = workspace.getLayout().getFormat().getVersion();
@@ -590,42 +591,42 @@ thin.init_ = function() {
590591
}
591592
};
592593

593-
// switch(thin.layout.checkCompatibility(targetVersion)) {
594-
// case compatibilityState.WARNING:
595-
// thin.ui.Message.confirm(thin.t('text_layout_force_edit_confirmation'),
596-
// thin.t('label_confirmation'),
597-
// function(e) {
598-
// if (e.isOk()) {
599-
// addPageHandler();
600-
// }
601-
// });
602-
// break;
603-
// case compatibilityState.ERROR:
604-
// throw new thin.Error(thin.t('error_can_not_edit_layout_file',
605-
// {'required': thin.layout.inspectCompatibleRule(),
606-
// 'version': targetVersion}));
607-
// break;
608-
// default:
594+
switch(thin.layout.checkCompatibility(targetVersion)) {
595+
case compatibilityState.WARNING:
596+
thin.ui.Message.confirm(thin.t('text_layout_force_edit_confirmation'),
597+
thin.t('label_confirmation'),
598+
function(e) {
599+
if (e.isOk()) {
600+
addPageHandler();
601+
}
602+
});
603+
break;
604+
case compatibilityState.ERROR:
605+
throw new thin.Error(thin.t('error_can_not_edit_layout_file',
606+
{'required': thin.layout.inspectCompatibleRule(),
607+
'version': targetVersion}));
608+
break;
609+
default:
609610
addPageHandler();
610-
// break;
611-
// }
611+
break;
612+
}
613+
}
614+
} catch (er) {
615+
var message;
616+
if (er instanceof thin.Error) {
617+
message = er.message;
618+
} else {
619+
message = thin.t('error_unknown');
612620
}
613-
// } catch (er) {
614-
// var message;
615-
// if (er instanceof thin.Error) {
616-
// message = er.message;
617-
// } else {
618-
// message = thin.t('error_unknown');
619-
// }
620-
621-
// thin.ui.Message.alert(message, 'Error',
622-
// function(er) {
623-
// var activeWorkspace = thin.core.getActiveWorkspace();
624-
// if (activeWorkspace) {
625-
// activeWorkspace.focusElement(er);
626-
// }
627-
// });
628-
// }
621+
622+
thin.ui.Message.alert(message, 'Error',
623+
function(er) {
624+
var activeWorkspace = thin.core.getActiveWorkspace();
625+
if (activeWorkspace) {
626+
activeWorkspace.focusElement(er);
627+
}
628+
});
629+
}
629630
},
630631
cancel: goog.nullFunction,
631632
error: function(code) {

src/app/core/abstracttextgroup.js

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -477,16 +477,27 @@ thin.core.AbstractTextGroup.prototype.setVerticalAlignFromHash = function(vertic
477477
thin.core.AbstractTextGroup.prototype.toHash = function() {
478478
var hash = this.toHash_();
479479

480+
var lineHeight = this.getTextLineHeight();
481+
var lineHeightRatio = this.getTextLineHeightRatio();
482+
if (!thin.isExactlyEqual(lineHeightRatio, thin.core.TextStyle.DEFAULT_LINEHEIGHT)) {
483+
lineHeight = Number(lineHeight);
484+
lineHeightRatio = Number(lineHeightRatio);
485+
}
486+
487+
var letterSpecing = this.getKerning();
488+
if (!thin.isExactlyEqual(letterSpecing, thin.core.TextStyle.DEFAULT_KERNING)) {
489+
letterSpecing = Number(letterSpecing);
490+
}
491+
480492
goog.object.extend(hash['style'], {
481-
'font-family': this.getFontFamily(),
493+
'font-family': [ this.getFontFamily() ],
482494
'font-size': this.getFontSize(),
483495
'color': goog.object.get(hash['style'], 'fill-color'),
484496
'text-align': this.getTextAnchorToHash(),
485497
'vertical-align': this.getVerticalAlignToHash(),
486-
// default is blank
487-
'line-height': this.getTextLineHeight(),
488-
'line-height-ratio': this.getTextLineHeightRatio(),
489-
'letter-spacing': this.getKerning()
498+
'line-height': lineHeight,
499+
'line-height-ratio': lineHeightRatio,
500+
'letter-spacing': letterSpecing
490501
});
491502
goog.object.extend(hash['style'], this.fontStyle_.toHash());
492503

@@ -505,7 +516,7 @@ thin.core.AbstractTextGroup.prototype.update = function(attrs) {
505516
goog.object.forEach(attrs, function(value, attr) {
506517
switch (attr) {
507518
case 'font-family':
508-
this.setFontFamily(value);
519+
this.setFontFamily(value[0]);
509520
break;
510521
case 'font-size':
511522
this.setFontSize(value);

src/app/core/action.js

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1338,7 +1338,6 @@ thin.core.Action.prototype.actionDeleteShapes = function(historyMode) {
13381338
var targetIndexByShapes = layout.getTargetIndexOfShapes(targetShapes, parentGroup);
13391339
var captureShapeIdArray = [];
13401340
var captureRefIdArray = [];
1341-
var captureReferenceShapesArray = [];
13421341
var captureReferringShapesArray = [];
13431342
var defaultRefId = thin.core.TblockShape.DEFAULT_REFID;
13441343

@@ -1347,11 +1346,9 @@ thin.core.Action.prototype.actionDeleteShapes = function(historyMode) {
13471346

13481347
if (shape.instanceOfTblockShape()) {
13491348
goog.array.insertAt(captureRefIdArray, shape.getRefId(), count);
1350-
goog.array.insertAt(captureReferenceShapesArray, shape.getReferenceShape(), count);
13511349
goog.array.insertAt(captureReferringShapesArray, shape.getReferringShapes(), count);
13521350
} else {
13531351
goog.array.insertAt(captureRefIdArray, defaultRefId, count);
1354-
goog.array.insertAt(captureReferenceShapesArray, null, count);
13551352
goog.array.insertAt(captureReferringShapesArray, null, count);
13561353
}
13571354

@@ -1399,7 +1396,7 @@ thin.core.Action.prototype.actionDeleteShapes = function(historyMode) {
13991396
if (shape.instanceOfTblockShape()) {
14001397
var captureRefId = captureRefIdArray[count];
14011398
if (!thin.isExactlyEqual(captureRefId, defaultRefId)) {
1402-
shape.setRefId(captureRefId, captureReferenceShapesArray[count]);
1399+
shape.setRefId(captureRefId);
14031400
}
14041401
}
14051402

@@ -1413,10 +1410,9 @@ thin.core.Action.prototype.actionDeleteShapes = function(historyMode) {
14131410
goog.array.forEach(captureReferringShapesArray, function(referringShapes, count) {
14141411
if (goog.isArray(referringShapes) && !goog.array.isEmpty(referringShapes)) {
14151412
var refId = captureShapeIdArray[count];
1416-
var referencesShape = shapes[count];
14171413
goog.array.forEach(referringShapes, function(shape) {
14181414
if (!shape.isReferring()) {
1419-
shape.setRefId(refId, referencesShape);
1415+
shape.setRefId(refId);
14201416
}
14211417
});
14221418
}
@@ -1477,7 +1473,7 @@ thin.core.Action.prototype.actionDeleteShapes = function(historyMode) {
14771473
if (shape.instanceOfTblockShape()) {
14781474
var captureRefId = captureRefIdArray[count];
14791475
if (!thin.isExactlyEqual(captureRefId, defaultRefId)) {
1480-
shape.setRefId(captureRefId, captureReferenceShapesArray[count]);
1476+
shape.setRefId(captureRefId);
14811477
}
14821478
}
14831479

@@ -1491,10 +1487,9 @@ thin.core.Action.prototype.actionDeleteShapes = function(historyMode) {
14911487
goog.array.forEach(captureReferringShapesArray, function(referringShapes, count) {
14921488
if (goog.isArray(referringShapes) && !goog.array.isEmpty(referringShapes)) {
14931489
var refId = captureShapeIdArray[count];
1494-
var referencesShape = shapes[count];
14951490
goog.array.forEach(referringShapes, function(shape) {
14961491
if (!shape.isReferring()) {
1497-
shape.setRefId(refId, referencesShape);
1492+
shape.setRefId(refId);
14981493
}
14991494
});
15001495
}

src/app/core/imageshape.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,10 @@ thin.core.ImageShape.prototype.toHash = function() {
470470
});
471471
}
472472

473+
if (goog.object.isEmpty(hash['style'])) {
474+
goog.object.remove(hash, 'style');
475+
}
476+
473477
return hash;
474478
};
475479

src/app/core/layout.js

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -192,28 +192,10 @@ thin.core.Layout.prototype.drawShapeFromElements = function(elements, opt_sectio
192192
* @param {thin.core.ListSectionShape=} opt_sectionShape
193193
*/
194194
thin.core.Layout.prototype.drawShapes = function(items, opt_sectionShape) {
195-
var shapes = [];
195+
var shape;
196196
goog.array.forEach(items, function(item) {
197-
var shape = this.drawShape(item, opt_sectionShape);
198-
shapes.push(shape);
197+
shape = this.drawShape(item, opt_sectionShape);
199198
}, this);
200-
201-
if (opt_sectionShape) {
202-
var manager = opt_sectionShape.getManager();
203-
} else {
204-
var manager = this.getManager();
205-
}
206-
var shapeIdManager = manager.getShapeIdManager();
207-
208-
goog.array.forEach(shapes, function(shape, i) {
209-
if (shape.instanceOfTblockShape()) {
210-
var refId = items[i]['reference-id'];
211-
if (!thin.isExactlyEqual(refId, thin.core.TblockShape.DEFAULT_REFID) && thin.isDef(refId)) {
212-
shape.setRefId(refId, shapeIdManager.getShapeForShapeId(refId));
213-
}
214-
}
215-
});
216-
217199
};
218200

219201

@@ -494,7 +476,6 @@ thin.core.Layout.prototype.createHelpersElement = function(tagName, attrs) {
494476
* @return {Object}
495477
*/
496478
thin.core.Layout.prototype.toHash = function() {
497-
// TODO: DRY
498479
var childNodes = this.getCanvasElement().getElement().childNodes;
499480
var identifiers = goog.array.map(childNodes, function(element, i) {
500481
return element.getAttribute('id');
@@ -981,7 +962,7 @@ thin.core.Layout.prototype.pasteShapes = function() {
981962
var referringShape = pasteShapes[count];
982963
if (referringShape.instanceOfTblockShape()) {
983964
if (!thin.isExactlyEqual(refId, defaultRefId) && !referringShape.isReferences()) {
984-
referringShape.setRefId(refId, layout.getShapeForShapeId(refId, shapeIdManager));
965+
referringShape.setRefId(refId);
985966
}
986967
}
987968
});
@@ -1000,7 +981,7 @@ thin.core.Layout.prototype.pasteShapes = function() {
1000981
var referringShape = pasteShapes[count];
1001982
if (referringShape.instanceOfTblockShape()) {
1002983
if (!thin.isExactlyEqual(refId, defaultRefId) && !referringShape.isReferences()) {
1003-
referringShape.setRefId(refId, layout.getShapeForShapeId(refId));
984+
referringShape.setRefId(refId);
1004985
}
1005986
}
1006987
});
@@ -1134,23 +1115,23 @@ thin.core.Layout.prototype.removeShape = function(shape) {
11341115
listHelper.clearChangingPageSetShape();
11351116
}
11361117
goog.array.forEach(shape.getPageNumberReferences(), function(target) {
1137-
target.removeTargetShape();
1118+
target.removeTargetShapeId();
11381119
});
11391120
}
11401121

11411122
if (shape.instanceOfTblockShape()) {
11421123
if (shape.isReferences()) {
11431124
goog.array.forEach(shape.getReferringShapes(), function(target) {
1144-
target.removeReferenceShape();
1125+
target.removeReferenceShapeId();
11451126
});
11461127
}
11471128
if (shape.isReferring()) {
1148-
shape.removeReferenceShape();
1129+
shape.removeReferenceShapeId();
11491130
}
11501131
}
11511132

11521133
if (shape.instanceOfPageNumberShape()) {
1153-
shape.removeTargetShape();
1134+
shape.removeTargetShapeId();
11541135
}
11551136

11561137
if (shape.isAffiliationListShape()) {
@@ -1386,7 +1367,7 @@ thin.core.Layout.prototype.createTblockShape = function() {
13861367
shape.setFormatType(thin.core.TblockShape.DEFAULT_FORMAT_TYPE);
13871368
shape.setDefaultValueOfLink(thin.core.TblockShape.DEFAULT_VALUE);
13881369
shape.setBaseFormat(thin.core.TblockShape.DEFAULT_FORMAT_BASE);
1389-
shape.setInternalRefId(thin.core.TblockShape.DEFAULT_REFID);
1370+
shape.setRefId(thin.core.TblockShape.DEFAULT_REFID);
13901371
shape.setKerning(thin.core.TextStyle.DEFAULT_KERNING);
13911372
shape.setDisplay(thin.core.ModuleShape.DEFAULT_DISPLAY);
13921373
shape.setMultiModeInternal(thin.core.TblockShape.DEFAULT_MULTIPLE);

src/app/core/layoutstructure.js

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -57,29 +57,17 @@ thin.core.LayoutStructure.restoreStructure = function(svg) {
5757
*/
5858
thin.core.LayoutStructure.createScreenShot = function(layout) {
5959
var svg;
60-
60+
6161
thin.core.LayoutStructure.inRawLayout_(layout, function() {
6262
svg = layout.getElement().cloneNode(true);
6363
});
6464
thin.core.LayoutStructure.finalizeLayoutElement_(svg);
65-
65+
6666
return thin.platform.String.toBase64(
6767
thin.core.serializeToXML(/** @type {Element} */ (svg)));
6868
};
6969

7070

71-
/**
72-
* @param {thin.core.Layout} layout
73-
* @return {string}
74-
*/
75-
thin.core.LayoutStructure.createBackup = function(layout) {
76-
var svg = layout.getElement().cloneNode(true);
77-
thin.core.LayoutStructure.finalizeLayoutElement_(svg);
78-
79-
return thin.core.serializeToXML(/** @type {Element} */(svg));
80-
};
81-
82-
8371
/**
8472
* @deprecated
8573
* @param {thin.core.Layout} layout
@@ -90,7 +78,7 @@ thin.core.LayoutStructure.inRawLayout_ = function(layout, f) {
9078
var workspace = layout.getWorkspace();
9179
var zoomRate = workspace.getUiStatusForZoom();
9280
var listHelper = layout.getHelpers().getListHelper();
93-
81+
9482
// Set zoom-rate to 100%.
9583
var scrollTarget = workspace.getParent().getParent().getContentElement();
9684
var scrollLeft = Number(scrollTarget.scrollLeft);
@@ -108,15 +96,15 @@ thin.core.LayoutStructure.inRawLayout_ = function(layout, f) {
10896
shapes: listHelper.getActiveShape().getClone()
10997
};
11098
listHelper.inactive();
111-
99+
112100
f();
113-
101+
114102
// Activate list and restore states.
115103
listHelper.active(listStates.target);
116104
listHelper.getActiveShape().set(listStates.shapes);
117105
listHelper.setActiveSectionName(listStates.activeSection);
118106
}
119-
107+
120108
// Restore original zoom-rate.
121109
workspace.getAction().actionSetZoom(zoomRate);
122110
scrollTarget.scrollLeft = scrollLeft;
@@ -131,7 +119,7 @@ thin.core.LayoutStructure.inRawLayout_ = function(layout, f) {
131119
*/
132120
thin.core.LayoutStructure.finalizeLayoutElement_ = function(layoutElement) {
133121
var canvasId = thin.core.Layout.CANVAS_CLASS_ID;
134-
122+
135123
goog.array.forEachRight(layoutElement.childNodes, function(node, i, nodes) {
136124
if (canvasId != node.getAttribute('class')) {
137125
layoutElement.removeChild(nodes[i]);
@@ -178,7 +166,7 @@ thin.core.LayoutStructure.applyRefId = function(layout, shapes, opt_shapeIdManag
178166
if (shape.instanceOfTblockShape()) {
179167
var refId = layout.getElementAttribute(shape.getElement(), 'x-ref-id');
180168
if (!thin.isExactlyEqual(refId, thin.core.TblockShape.DEFAULT_REFID)) {
181-
shape.setRefId(refId, layout.getShapeForShapeId(refId, opt_shapeIdManager));
169+
shape.setRefId(refId);
182170
}
183171
}
184172
}

0 commit comments

Comments
 (0)