Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 19 additions & 15 deletions src/app/boot.js
Original file line number Diff line number Diff line change
Expand Up @@ -442,15 +442,19 @@ thin.init_ = function() {

dialog.addEventListener(goog.ui.Dialog.EventType.SELECT, function(e) {
if (e.isOk()) {
var margin = [];
goog.array.insertAt(margin, pageMarginTop.getValue() || 0, 0);
goog.array.insertAt(margin, pageMarginRight.getValue() || 0, 1);
goog.array.insertAt(margin, pageMarginBottom.getValue() || 0, 2);
goog.array.insertAt(margin, pageMarginLeft.getValue() || 0, 3);

var paperTypeValue = paperTypeSelectbox.getValue();
var formatConfig = {
var report = {
'paper-type': paperTypeValue,
'orientation': pageDirectionSelectbox.getValue(),
'margin-top': pageMarginTop.getValue() || 0,
'margin-bottom': pageMarginBottom.getValue() || 0,
'margin-left': pageMarginLeft.getValue() || 0,
'margin-right': pageMarginRight.getValue() || 0
'margin': margin
};

if (thin.layout.FormatPage.isUserType(paperTypeValue)) {
var userWidth = pageWidthInput.getValue();
var userHeight = pageHeightInput.getValue();
Expand All @@ -462,14 +466,13 @@ thin.init_ = function() {
});
return false;
}
formatConfig['width'] = Number(userWidth);
formatConfig['height'] = Number(userHeight);
report['width'] = Number(userWidth);
report['height'] = Number(userHeight);
}
var format = new thin.layout.Format();
format.page = format.setPage({
'title': pageTitleInput.getValue(),
'page': formatConfig
});
format.page = format.setPage(report);
format.page.setTitle(pageTitleInput.getValue());

var workspace = new thin.core.Workspace(format);
tabpane.addPage(new thin.ui.TabPane.TabPage(workspace.getTabName(), workspace));
workspace.setup();
Expand All @@ -490,10 +493,11 @@ thin.init_ = function() {
pageHeightInput.setEnabled(false);
pageHeightInput.setValue('');

pageMarginTop.setValue(thin.layout.FormatPage.DEFAULT_SETTINGS['margin-top']);
pageMarginBottom.setValue(thin.layout.FormatPage.DEFAULT_SETTINGS['margin-bottom']);
pageMarginLeft.setValue(thin.layout.FormatPage.DEFAULT_SETTINGS['margin-left']);
pageMarginRight.setValue(thin.layout.FormatPage.DEFAULT_SETTINGS['margin-right']);
var defaultMargin = thin.layout.FormatPage.DEFAULT_SETTINGS['margin'];
pageMarginTop.setValue(defaultMargin[0]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

順番の仕様が曖昧なので、以下のようにしよう。 generator の方も修正する。

[top, right, bottom, left]

https://docs.google.com/spreadsheets/d/1iLqM1rdavuLLlbl_8xKODIIWZbHAE3D0A4AzhmK9_Pw/edit#gid=1893696187

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

あい。Editorは大丈夫だと思います。

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ん?修正は必要だよね?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

再設定したらおかしくなることが判明。

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

再設定したらおかしくなることが判明。

そもそも順番が違うと思う。今のコードを見る限り、 [top, bottom, left, right] になってる気がする。

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ですな。勘違いしていた。

pageMarginRight.setValue(defaultMargin[1]);
pageMarginBottom.setValue(defaultMargin[2]);
pageMarginLeft.setValue(defaultMargin[3]);

dialog.setVisible(true);
});
Expand Down
257 changes: 217 additions & 40 deletions src/app/core/abstracttextgroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,55 +44,19 @@ thin.core.AbstractTextGroup = function(element, layout) {
goog.inherits(thin.core.AbstractTextGroup, thin.core.AbstractBoxGroup);


/**
* The latest fill applied to this element.
* @type {goog.graphics.Fill?}
* @protected
*/
thin.core.AbstractTextGroup.prototype.fill = null;


/**
* The latest stroke applied to this element.
* @type {goog.graphics.Stroke?}
* @private
*/
thin.core.AbstractTextGroup.prototype.stroke_ = null;


/**
* Sets the fill for this element.
* @param {goog.graphics.Fill?} fill The fill object.
*/
thin.core.AbstractTextGroup.prototype.setFill = function(fill) {
this.fill = fill;
this.getLayout().setElementFill(this, fill);
};


/**
* @return {goog.graphics.Fill?} fill The fill object.
*/
thin.core.AbstractTextGroup.prototype.getFill = function() {
return this.fill;
thin.core.AbstractTextGroup.prototype.setFillInternal = function() {
this.getLayout().setElementFill(this, this.fill);
};


/**
* Sets the stroke for this element.
* @param {goog.graphics.Stroke?} stroke The stroke object.
*/
thin.core.AbstractTextGroup.prototype.setStroke = function(stroke) {
this.stroke_ = stroke;
this.getLayout().setElementStroke(this, stroke);
};


/**
* @return {goog.graphics.Stroke?} stroke The stroke object.
*/
thin.core.AbstractTextGroup.prototype.getStroke = function() {
return this.stroke_;
thin.core.AbstractTextGroup.prototype.setStrokeInternal = function() {
this.getLayout().setElementStroke(this, this.stroke_);
};


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


/**
* @deprecated See: https://github.com/thinreports/thinreports-editor/issues/38
* @param {string|number} spacing
* @return {string}
*/
thin.core.AbstractTextGroup.prototype.convertKerningToDefaultInSince06 = function(spacing) {
if (isNaN(Number(spacing))) {
spacing = thin.core.TextStyle.DEFAULT_KERNING;
}

return spacing;
};


/**
* @param {string} spacing
*/
thin.core.AbstractTextGroup.prototype.setKerning = function(spacing) {
var layout = this.getLayout();
var element = this.getElement();

spacing = this.convertKerningToDefaultInSince06(spacing);

if (thin.isExactlyEqual(spacing, thin.core.TextStyle.DEFAULT_KERNING)) {
layout.setElementAttributes(element, {
'kerning': thin.core.TextStyle.DEFAULT_ELEMENT_KERNING,
Expand Down Expand Up @@ -300,6 +281,15 @@ thin.core.AbstractTextGroup.prototype.getTextLineHeightRatio = function() {
};


/**
* @return {string}
*/
thin.core.AbstractTextGroup.prototype.getTextLineHeight = function() {
return /** @type {string} */ (thin.getValIfNotDef(this.getLayout().getElementAttribute(
this.getElement(), 'x-line-height'), thin.core.TextStyle.DEFAULT_LINEHEIGHT));
};


/**
* @return {string}
*/
Expand Down Expand Up @@ -399,3 +389,190 @@ thin.core.AbstractTextGroup.prototype.disposeInternal = function() {
delete this.fontStyle_;
delete this.textStyle_;
};


/**
* @return {string}
*/
thin.core.AbstractTextGroup.prototype.getTextAnchorAsJSON = function() {
var textAlignAsJSON = '';
var horizonAlignType = thin.core.TextStyle.HorizonAlignType;

// SVG: start, middle, end
// TLF: left, center, right
switch(this.getTextAnchor()) {
case horizonAlignType.MIDDLE:
textAlignAsJSON = 'center';
break;
case horizonAlignType.END:
textAlignAsJSON = 'right';
break;
default:
textAlignAsJSON = 'left';
break;
}

return textAlignAsJSON;
};


/**
* @param {string} textAlignFromJSON
*/
thin.core.AbstractTextGroup.prototype.setTextAnchorFromJSON = function(textAlignFromJSON) {
var anchor = '';
var horizonAlignType = thin.core.TextStyle.HorizonAlignType;

// SVG: start, middle, end
// TLF: left, center, right
switch(textAlignFromJSON) {
case 'center':
anchor = horizonAlignType.MIDDLE;
break;
case 'right':
anchor = horizonAlignType.END;
break;
default:
anchor = horizonAlignType.START;
break;
}

this.setTextAnchor(anchor);
};


/**
* @return {string}
*/
thin.core.AbstractTextGroup.prototype.getVerticalAlignAsJSON = function() {
var verticalAlignAsJSON = '';
var verticalAlignType = thin.core.TextStyle.VerticalAlignType;

// SVG: top, center, bottom
// TLF: top, middle, bottom
switch(this.getVerticalAlign()) {
case verticalAlignType.CENTER:
verticalAlignAsJSON = 'middle';
break;
case verticalAlignType.BOTTOM:
verticalAlignAsJSON = verticalAlignType.BOTTOM;
break;
default:
verticalAlignAsJSON = verticalAlignType.TOP;
break;
}

return verticalAlignAsJSON;
};


/**
* @param {string} verticalAlignFromJSON
*/
thin.core.AbstractTextGroup.prototype.setVerticalAlignFromJSON = function(verticalAlignFromJSON) {
var valign = '';
var verticalAlignType = thin.core.TextStyle.VerticalAlignType;

// SVG: top, center, bottom
// TLF: top, middle, bottom
switch(verticalAlignFromJSON) {
case 'middle':
valign = verticalAlignType.CENTER;
break;
default:
valign = verticalAlignFromJSON;
break;
}

this.setVerticalAlign(valign);
};


/**
* @return {Object}
*/
thin.core.AbstractTextGroup.prototype.asJSON = function() {
var object = this.asJSON_();

var lineHeight = this.getTextLineHeight();
var lineHeightRatio = this.getTextLineHeightRatio();
if (!thin.isExactlyEqual(lineHeightRatio, thin.core.TextStyle.DEFAULT_LINEHEIGHT)) {
lineHeight = Number(lineHeight);
lineHeightRatio = Number(lineHeightRatio);
}

var letterSpecing = this.getKerning();
if (!thin.isExactlyEqual(letterSpecing, thin.core.TextStyle.DEFAULT_KERNING)) {
letterSpecing = Number(letterSpecing);
}

goog.object.extend(object['style'], {
'font-family': [ this.getFontFamily() ],
'font-size': this.getFontSize(),
'color': goog.object.get(object['style'], 'fill-color'),
'text-align': this.getTextAnchorAsJSON(),
'vertical-align': this.getVerticalAlignAsJSON(),
'line-height': lineHeight,
'line-height-ratio': lineHeightRatio,
'letter-spacing': letterSpecing
});
goog.object.extend(object['style'], this.fontStyle_.asJSON());

goog.object.remove(object['style'], 'fill-color');

return object;
};


/**
* @param {Object} attrs
*/
thin.core.AbstractTextGroup.prototype.update = function(attrs) {
this.update_(attrs);

goog.object.forEach(attrs, function(value, attr) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[chore] ここは forEach じゃなくて、普通に

if (attrs['font-family']) {
  this.setFontFamily(attrs['font-family'][0]);
}

if (attrs['font-size']) {
  this.setFontSize(attrs['font-size']);
}

// :

でいいかなぁと思ったけど、このままでもいいかな。

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ここは、このままにする。

switch (attr) {
case 'font-family':
this.setFontFamily(value[0]);
break;
case 'font-size':
this.setFontSize(value);
break;
case 'color':
this.setFillColor(value);
break;
case 'text-align':
this.setTextAnchorFromJSON(value);
break;
case 'vertical-align':
this.setVerticalAlignFromJSON(value);
break;
case 'line-height-ratio':
this.setTextLineHeightRatio(value);
break;
case 'letter-spacing':
this.setKerning(value);
break;
case 'font-style':
goog.array.forEach(value, function(font_style) {
switch(font_style) {
case 'bold':
this.setFontBold(true);
break;
case 'italic':
this.setFontItalic(true);
break;
case 'linethrough':
this.setFontLinethrough(true);
break;
case 'underline':
this.setFontUnderline(true);
break;
}
}, this);
default:
// Do Nothing
break;
}
}, this);
};
Loading