Skip to content

Commit c6a9591

Browse files
authored
Merge pull request #71 from thinreports/fix_row_height_has_different_values_for_each_environment
Line-height calculation result will be different values ​​depending on the environment
2 parents e5a1bf9 + 7ee57dc commit c6a9591

3 files changed

Lines changed: 94 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## master
2+
3+
### Bugfixes
4+
5+
* Fixed: the line-height property returns different calculation results depending on environment (#71)
6+
17
## 0.10.0
28

39
### Released as an Electron based desktop application

app/editor/core/abstracttextgroup.js

Lines changed: 86 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ thin.core.AbstractTextGroup = function(element, layout) {
4040
* @private
4141
*/
4242
this.textStyle_ = new thin.core.TextStyle();
43+
44+
/**
45+
* @type {Object?}
46+
* @private
47+
*/
48+
this.rawFormat_ = null
4349
};
4450
goog.inherits(thin.core.AbstractTextGroup, thin.core.AbstractBoxGroup);
4551

@@ -117,6 +123,76 @@ thin.core.AbstractTextGroup.prototype.setVerticalAlign = function(valign) {
117123
};
118124

119125

126+
/**
127+
* @param {Object} rawFormat
128+
*/
129+
thin.core.AbstractTextGroup.prototype.setRawFormat = function (rawFormat) {
130+
this.rawFormat_ = rawFormat;
131+
};
132+
133+
134+
/**
135+
* @return {Object?}
136+
* @private
137+
*/
138+
thin.core.AbstractTextGroup.prototype.getRawStyle_ = function () {
139+
return this.rawFormat_ && this.rawFormat_['style'];
140+
};
141+
142+
143+
/**
144+
* @return {number|string?}
145+
*/
146+
thin.core.AbstractTextGroup.prototype.getRawLineHeight = function () {
147+
var rawStyle = this.getRawStyle_();
148+
var lineHeight;
149+
150+
if (rawStyle) {
151+
lineHeight = rawStyle['line-height'];
152+
153+
if (lineHeight === thin.core.TextStyle.DEFAULT_LINEHEIGHT) {
154+
return lineHeight;
155+
} else {
156+
return Number(lineHeight);
157+
}
158+
} else {
159+
return null;
160+
}
161+
};
162+
163+
164+
/**
165+
* @param {number} fontSize
166+
* @param {string} fontFamily
167+
* @param {number} lineHeightRatio
168+
* @return {boolean}
169+
* @private
170+
*/
171+
thin.core.AbstractTextGroup.prototype.hasLineHeightChanged_ = function (fontSize, fontFamily, lineHeightRatio) {
172+
var fontSizeChanged = false;
173+
var lineHeightRatioChanged = false;
174+
var fontFamilyChanged = false;
175+
176+
var rawStyles = this.getRawStyle_();
177+
178+
var rawFontSize, rawLineHeightRatio, rawFontFamily;
179+
180+
if (rawStyles) {
181+
rawFontSize = /** @type {number} */ (Number(rawStyles['font-size']));
182+
rawLineHeightRatio = /** @type {number} */ (Number(rawStyles['line-height-ratio']));
183+
rawFontFamily = /** @type {string} */ (rawStyles['font-family'][0]);
184+
185+
fontSizeChanged = rawFontSize !== Number(fontSize);
186+
lineHeightRatioChanged = rawLineHeightRatio !== Number(lineHeightRatio);
187+
fontFamilyChanged = rawFontFamily !== fontFamily;
188+
189+
return fontSizeChanged || lineHeightRatioChanged || fontFamilyChanged;
190+
} else {
191+
return true;
192+
}
193+
};
194+
195+
120196
/**
121197
* @param {string} ratio
122198
*/
@@ -129,10 +205,17 @@ thin.core.AbstractTextGroup.prototype.setTextLineHeightRatio = function(ratio) {
129205
} else {
130206
var layout = this.getLayout();
131207
var numRatio = Number(ratio);
132-
var heightAt = thin.Font.getHeight(this.getFontFamily(), this.getFontSize());
208+
209+
var lineHeight;
210+
211+
if (this.hasLineHeightChanged_(this.getFontSize(), this.getFontFamily(), numRatio)) {
212+
lineHeight = thin.Font.getHeight(this.getFontFamily(), this.getFontSize()) * numRatio;
213+
} else {
214+
lineHeight = this.getRawLineHeight();
215+
}
133216

134217
layout.setElementAttributes(element, {
135-
'x-line-height': heightAt * numRatio
218+
'x-line-height': lineHeight
136219
});
137220
layout.setElementAttributes(element, {
138221
'x-line-height-ratio': numRatio
@@ -386,6 +469,7 @@ thin.core.AbstractTextGroup.prototype.updateToolbarUI = function() {
386469
thin.core.AbstractTextGroup.prototype.disposeInternal = function() {
387470
goog.base(this, 'disposeInternal');
388471

472+
delete this.rawFormat_;
389473
delete this.fontStyle_;
390474
delete this.textStyle_;
391475
};

app/editor/core/layout.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ thin.core.Layout.prototype.drawShape = function(item, opt_sectionShape) {
137137

138138
case 'text-block':
139139
shape = this.createTblockShape();
140+
shape.setRawFormat(item);
140141
break;
141142

142143
case 'page-number':
@@ -145,6 +146,7 @@ thin.core.Layout.prototype.drawShape = function(item, opt_sectionShape) {
145146

146147
case 'text':
147148
shape = this.createTextShape();
149+
shape.setRawFormat(item);
148150
break;
149151

150152
case 'image':

0 commit comments

Comments
 (0)