Skip to content

Commit 17ea011

Browse files
committed
Merge pull request #56 from thinreports/new-layout-schema
New format for layout file
2 parents 083e55b + 4b29500 commit 17ea011

30 files changed

Lines changed: 2102 additions & 1459 deletions

src/app/boot.js

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -442,15 +442,19 @@ thin.init_ = function() {
442442

443443
dialog.addEventListener(goog.ui.Dialog.EventType.SELECT, function(e) {
444444
if (e.isOk()) {
445+
var margin = [];
446+
goog.array.insertAt(margin, pageMarginTop.getValue() || 0, 0);
447+
goog.array.insertAt(margin, pageMarginRight.getValue() || 0, 1);
448+
goog.array.insertAt(margin, pageMarginBottom.getValue() || 0, 2);
449+
goog.array.insertAt(margin, pageMarginLeft.getValue() || 0, 3);
450+
445451
var paperTypeValue = paperTypeSelectbox.getValue();
446-
var formatConfig = {
452+
var report = {
447453
'paper-type': paperTypeValue,
448454
'orientation': pageDirectionSelectbox.getValue(),
449-
'margin-top': pageMarginTop.getValue() || 0,
450-
'margin-bottom': pageMarginBottom.getValue() || 0,
451-
'margin-left': pageMarginLeft.getValue() || 0,
452-
'margin-right': pageMarginRight.getValue() || 0
455+
'margin': margin
453456
};
457+
454458
if (thin.layout.FormatPage.isUserType(paperTypeValue)) {
455459
var userWidth = pageWidthInput.getValue();
456460
var userHeight = pageHeightInput.getValue();
@@ -462,14 +466,13 @@ thin.init_ = function() {
462466
});
463467
return false;
464468
}
465-
formatConfig['width'] = Number(userWidth);
466-
formatConfig['height'] = Number(userHeight);
469+
report['width'] = Number(userWidth);
470+
report['height'] = Number(userHeight);
467471
}
468472
var format = new thin.layout.Format();
469-
format.page = format.setPage({
470-
'title': pageTitleInput.getValue(),
471-
'page': formatConfig
472-
});
473+
format.page = format.setPage(report);
474+
format.page.setTitle(pageTitleInput.getValue());
475+
473476
var workspace = new thin.core.Workspace(format);
474477
tabpane.addPage(new thin.ui.TabPane.TabPage(workspace.getTabName(), workspace));
475478
workspace.setup();
@@ -490,10 +493,11 @@ thin.init_ = function() {
490493
pageHeightInput.setEnabled(false);
491494
pageHeightInput.setValue('');
492495

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']);
496+
var defaultMargin = thin.layout.FormatPage.DEFAULT_SETTINGS['margin'];
497+
pageMarginTop.setValue(defaultMargin[0]);
498+
pageMarginRight.setValue(defaultMargin[1]);
499+
pageMarginBottom.setValue(defaultMargin[2]);
500+
pageMarginLeft.setValue(defaultMargin[3]);
497501

498502
dialog.setVisible(true);
499503
});

src/app/core/abstracttextgroup.js

Lines changed: 217 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -44,55 +44,19 @@ thin.core.AbstractTextGroup = function(element, layout) {
4444
goog.inherits(thin.core.AbstractTextGroup, thin.core.AbstractBoxGroup);
4545

4646

47-
/**
48-
* The latest fill applied to this element.
49-
* @type {goog.graphics.Fill?}
50-
* @protected
51-
*/
52-
thin.core.AbstractTextGroup.prototype.fill = null;
53-
54-
55-
/**
56-
* The latest stroke applied to this element.
57-
* @type {goog.graphics.Stroke?}
58-
* @private
59-
*/
60-
thin.core.AbstractTextGroup.prototype.stroke_ = null;
61-
62-
6347
/**
6448
* Sets the fill for this element.
65-
* @param {goog.graphics.Fill?} fill The fill object.
66-
*/
67-
thin.core.AbstractTextGroup.prototype.setFill = function(fill) {
68-
this.fill = fill;
69-
this.getLayout().setElementFill(this, fill);
70-
};
71-
72-
73-
/**
74-
* @return {goog.graphics.Fill?} fill The fill object.
7549
*/
76-
thin.core.AbstractTextGroup.prototype.getFill = function() {
77-
return this.fill;
50+
thin.core.AbstractTextGroup.prototype.setFillInternal = function() {
51+
this.getLayout().setElementFill(this, this.fill);
7852
};
7953

8054

8155
/**
8256
* Sets the stroke for this element.
83-
* @param {goog.graphics.Stroke?} stroke The stroke object.
84-
*/
85-
thin.core.AbstractTextGroup.prototype.setStroke = function(stroke) {
86-
this.stroke_ = stroke;
87-
this.getLayout().setElementStroke(this, stroke);
88-
};
89-
90-
91-
/**
92-
* @return {goog.graphics.Stroke?} stroke The stroke object.
9357
*/
94-
thin.core.AbstractTextGroup.prototype.getStroke = function() {
95-
return this.stroke_;
58+
thin.core.AbstractTextGroup.prototype.setStrokeInternal = function() {
59+
this.getLayout().setElementStroke(this, this.stroke_);
9660
};
9761

9862

@@ -178,12 +142,29 @@ thin.core.AbstractTextGroup.prototype.setTextLineHeightRatio = function(ratio) {
178142
};
179143

180144

145+
/**
146+
* @deprecated See: https://github.com/thinreports/thinreports-editor/issues/38
147+
* @param {string|number} spacing
148+
* @return {string}
149+
*/
150+
thin.core.AbstractTextGroup.prototype.convertKerningToDefaultInSince06 = function(spacing) {
151+
if (isNaN(Number(spacing))) {
152+
spacing = thin.core.TextStyle.DEFAULT_KERNING;
153+
}
154+
155+
return spacing;
156+
};
157+
158+
181159
/**
182160
* @param {string} spacing
183161
*/
184162
thin.core.AbstractTextGroup.prototype.setKerning = function(spacing) {
185163
var layout = this.getLayout();
186164
var element = this.getElement();
165+
166+
spacing = this.convertKerningToDefaultInSince06(spacing);
167+
187168
if (thin.isExactlyEqual(spacing, thin.core.TextStyle.DEFAULT_KERNING)) {
188169
layout.setElementAttributes(element, {
189170
'kerning': thin.core.TextStyle.DEFAULT_ELEMENT_KERNING,
@@ -300,6 +281,15 @@ thin.core.AbstractTextGroup.prototype.getTextLineHeightRatio = function() {
300281
};
301282

302283

284+
/**
285+
* @return {string}
286+
*/
287+
thin.core.AbstractTextGroup.prototype.getTextLineHeight = function() {
288+
return /** @type {string} */ (thin.getValIfNotDef(this.getLayout().getElementAttribute(
289+
this.getElement(), 'x-line-height'), thin.core.TextStyle.DEFAULT_LINEHEIGHT));
290+
};
291+
292+
303293
/**
304294
* @return {string}
305295
*/
@@ -399,3 +389,190 @@ thin.core.AbstractTextGroup.prototype.disposeInternal = function() {
399389
delete this.fontStyle_;
400390
delete this.textStyle_;
401391
};
392+
393+
394+
/**
395+
* @return {string}
396+
*/
397+
thin.core.AbstractTextGroup.prototype.getTextAnchorAsJSON = function() {
398+
var textAlignAsJSON = '';
399+
var horizonAlignType = thin.core.TextStyle.HorizonAlignType;
400+
401+
// SVG: start, middle, end
402+
// TLF: left, center, right
403+
switch(this.getTextAnchor()) {
404+
case horizonAlignType.MIDDLE:
405+
textAlignAsJSON = 'center';
406+
break;
407+
case horizonAlignType.END:
408+
textAlignAsJSON = 'right';
409+
break;
410+
default:
411+
textAlignAsJSON = 'left';
412+
break;
413+
}
414+
415+
return textAlignAsJSON;
416+
};
417+
418+
419+
/**
420+
* @param {string} textAlignFromJSON
421+
*/
422+
thin.core.AbstractTextGroup.prototype.setTextAnchorFromJSON = function(textAlignFromJSON) {
423+
var anchor = '';
424+
var horizonAlignType = thin.core.TextStyle.HorizonAlignType;
425+
426+
// SVG: start, middle, end
427+
// TLF: left, center, right
428+
switch(textAlignFromJSON) {
429+
case 'center':
430+
anchor = horizonAlignType.MIDDLE;
431+
break;
432+
case 'right':
433+
anchor = horizonAlignType.END;
434+
break;
435+
default:
436+
anchor = horizonAlignType.START;
437+
break;
438+
}
439+
440+
this.setTextAnchor(anchor);
441+
};
442+
443+
444+
/**
445+
* @return {string}
446+
*/
447+
thin.core.AbstractTextGroup.prototype.getVerticalAlignAsJSON = function() {
448+
var verticalAlignAsJSON = '';
449+
var verticalAlignType = thin.core.TextStyle.VerticalAlignType;
450+
451+
// SVG: top, center, bottom
452+
// TLF: top, middle, bottom
453+
switch(this.getVerticalAlign()) {
454+
case verticalAlignType.CENTER:
455+
verticalAlignAsJSON = 'middle';
456+
break;
457+
case verticalAlignType.BOTTOM:
458+
verticalAlignAsJSON = verticalAlignType.BOTTOM;
459+
break;
460+
default:
461+
verticalAlignAsJSON = verticalAlignType.TOP;
462+
break;
463+
}
464+
465+
return verticalAlignAsJSON;
466+
};
467+
468+
469+
/**
470+
* @param {string} verticalAlignFromJSON
471+
*/
472+
thin.core.AbstractTextGroup.prototype.setVerticalAlignFromJSON = function(verticalAlignFromJSON) {
473+
var valign = '';
474+
var verticalAlignType = thin.core.TextStyle.VerticalAlignType;
475+
476+
// SVG: top, center, bottom
477+
// TLF: top, middle, bottom
478+
switch(verticalAlignFromJSON) {
479+
case 'middle':
480+
valign = verticalAlignType.CENTER;
481+
break;
482+
default:
483+
valign = verticalAlignFromJSON;
484+
break;
485+
}
486+
487+
this.setVerticalAlign(valign);
488+
};
489+
490+
491+
/**
492+
* @return {Object}
493+
*/
494+
thin.core.AbstractTextGroup.prototype.asJSON = function() {
495+
var object = this.asJSON_();
496+
497+
var lineHeight = this.getTextLineHeight();
498+
var lineHeightRatio = this.getTextLineHeightRatio();
499+
if (!thin.isExactlyEqual(lineHeightRatio, thin.core.TextStyle.DEFAULT_LINEHEIGHT)) {
500+
lineHeight = Number(lineHeight);
501+
lineHeightRatio = Number(lineHeightRatio);
502+
}
503+
504+
var letterSpecing = this.getKerning();
505+
if (!thin.isExactlyEqual(letterSpecing, thin.core.TextStyle.DEFAULT_KERNING)) {
506+
letterSpecing = Number(letterSpecing);
507+
}
508+
509+
goog.object.extend(object['style'], {
510+
'font-family': [ this.getFontFamily() ],
511+
'font-size': this.getFontSize(),
512+
'color': goog.object.get(object['style'], 'fill-color'),
513+
'text-align': this.getTextAnchorAsJSON(),
514+
'vertical-align': this.getVerticalAlignAsJSON(),
515+
'line-height': lineHeight,
516+
'line-height-ratio': lineHeightRatio,
517+
'letter-spacing': letterSpecing
518+
});
519+
goog.object.extend(object['style'], this.fontStyle_.asJSON());
520+
521+
goog.object.remove(object['style'], 'fill-color');
522+
523+
return object;
524+
};
525+
526+
527+
/**
528+
* @param {Object} attrs
529+
*/
530+
thin.core.AbstractTextGroup.prototype.update = function(attrs) {
531+
this.update_(attrs);
532+
533+
goog.object.forEach(attrs, function(value, attr) {
534+
switch (attr) {
535+
case 'font-family':
536+
this.setFontFamily(value[0]);
537+
break;
538+
case 'font-size':
539+
this.setFontSize(value);
540+
break;
541+
case 'color':
542+
this.setFillColor(value);
543+
break;
544+
case 'text-align':
545+
this.setTextAnchorFromJSON(value);
546+
break;
547+
case 'vertical-align':
548+
this.setVerticalAlignFromJSON(value);
549+
break;
550+
case 'line-height-ratio':
551+
this.setTextLineHeightRatio(value);
552+
break;
553+
case 'letter-spacing':
554+
this.setKerning(value);
555+
break;
556+
case 'font-style':
557+
goog.array.forEach(value, function(font_style) {
558+
switch(font_style) {
559+
case 'bold':
560+
this.setFontBold(true);
561+
break;
562+
case 'italic':
563+
this.setFontItalic(true);
564+
break;
565+
case 'linethrough':
566+
this.setFontLinethrough(true);
567+
break;
568+
case 'underline':
569+
this.setFontUnderline(true);
570+
break;
571+
}
572+
}, this);
573+
default:
574+
// Do Nothing
575+
break;
576+
}
577+
}, this);
578+
};

0 commit comments

Comments
 (0)