@@ -44,55 +44,19 @@ thin.core.AbstractTextGroup = function(element, layout) {
4444goog . 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 */
184162thin . 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