@@ -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} ;
4450goog . 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() {
386469thin . core . AbstractTextGroup . prototype . disposeInternal = function ( ) {
387470 goog . base ( this , 'disposeInternal' ) ;
388471
472+ delete this . rawFormat_ ;
389473 delete this . fontStyle_ ;
390474 delete this . textStyle_ ;
391475} ;
0 commit comments