@@ -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.
6649 */
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.
75- */
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
@@ -300,6 +264,15 @@ thin.core.AbstractTextGroup.prototype.getTextLineHeightRatio = function() {
300264} ;
301265
302266
267+ /**
268+ * @return {string }
269+ */
270+ thin . core . AbstractTextGroup . prototype . getTextLineHeight = function ( ) {
271+ return /** @type {string } */ ( thin . getValIfNotDef ( this . getLayout ( ) . getElementAttribute (
272+ this . getElement ( ) , 'x-line-height' ) , thin . core . TextStyle . DEFAULT_LINEHEIGHT ) ) ;
273+ } ;
274+
275+
303276/**
304277 * @return {string }
305278 */
@@ -399,3 +372,179 @@ thin.core.AbstractTextGroup.prototype.disposeInternal = function() {
399372 delete this . fontStyle_ ;
400373 delete this . textStyle_ ;
401374} ;
375+
376+
377+ /**
378+ * @return {string }
379+ */
380+ thin . core . AbstractTextGroup . prototype . getTextAnchorToHash = function ( ) {
381+ var textAlignToHash = '' ;
382+ var horizonAlignType = thin . core . TextStyle . HorizonAlignType ;
383+
384+ // SVG: start, middle, end
385+ // TLF: left, center, right
386+ switch ( this . getTextAnchor ( ) ) {
387+ case horizonAlignType . MIDDLE :
388+ textAlignToHash = 'center' ;
389+ break ;
390+ case horizonAlignType . END :
391+ textAlignToHash = 'right' ;
392+ break ;
393+ default :
394+ textAlignToHash = 'left' ;
395+ break ;
396+ }
397+
398+ return textAlignToHash ;
399+ } ;
400+
401+
402+ /**
403+ * @param {string } textAlignToHash
404+ */
405+ thin . core . AbstractTextGroup . prototype . setTextAnchorFromHash = function ( textAlignToHash ) {
406+ var anchor = '' ;
407+ var horizonAlignType = thin . core . TextStyle . HorizonAlignType ;
408+
409+ // SVG: start, middle, end
410+ // TLF: left, center, right
411+ switch ( textAlignToHash ) {
412+ case 'center' :
413+ anchor = horizonAlignType . MIDDLE ;
414+ break ;
415+ case 'right' :
416+ anchor = horizonAlignType . END ;
417+ break ;
418+ default :
419+ anchor = horizonAlignType . START ;
420+ break ;
421+ }
422+
423+ this . setTextAnchor ( anchor ) ;
424+ } ;
425+
426+
427+ /**
428+ * @return {string }
429+ */
430+ thin . core . AbstractTextGroup . prototype . getVerticalAlignToHash = function ( ) {
431+ var verticalAlignToHash = '' ;
432+ var verticalAlignType = thin . core . TextStyle . VerticalAlignType ;
433+
434+ // SVG: top, center, bottom
435+ // TLF: top, middle, bottom
436+ switch ( this . getVerticalAlign ( ) ) {
437+ case verticalAlignType . CENTER :
438+ verticalAlignToHash = 'middle' ;
439+ break ;
440+ case verticalAlignType . BOTTOM :
441+ verticalAlignToHash = verticalAlignType . BOTTOM ;
442+ break ;
443+ default :
444+ verticalAlignToHash = verticalAlignType . TOP ;
445+ break ;
446+ }
447+
448+ return verticalAlignToHash ;
449+ } ;
450+
451+
452+ /**
453+ * @param {string } verticalAlignToHash
454+ */
455+ thin . core . AbstractTextGroup . prototype . setVerticalAlignFromHash = function ( verticalAlignToHash ) {
456+ var valign = '' ;
457+ var verticalAlignType = thin . core . TextStyle . VerticalAlignType ;
458+
459+ // SVG: top, center, bottom
460+ // TLF: top, middle, bottom
461+ switch ( verticalAlignToHash ) {
462+ case 'middle' :
463+ valign = verticalAlignType . CENTER ;
464+ break ;
465+ default :
466+ valign = verticalAlignToHash ;
467+ break ;
468+ }
469+
470+ this . setVerticalAlign ( valign ) ;
471+ } ;
472+
473+
474+ /**
475+ * @return {Object }
476+ */
477+ thin . core . AbstractTextGroup . prototype . toHash = function ( ) {
478+ var hash = this . toHash_ ( ) ;
479+
480+ goog . object . extend ( hash [ 'style' ] , {
481+ 'font-family' : this . getFontFamily ( ) ,
482+ 'font-size' : this . getFontSize ( ) ,
483+ 'color' : goog . object . get ( hash [ 'style' ] , 'fill-color' ) ,
484+ 'text-align' : this . getTextAnchorToHash ( ) ,
485+ 'vertical-align' : this . getVerticalAlignToHash ( ) ,
486+ // default is blank
487+ 'line-height' : this . getTextLineHeight ( ) ,
488+ 'line-height-ratio' : this . getTextLineHeightRatio ( ) ,
489+ 'letter-spacing' : this . getKerning ( )
490+ } ) ;
491+ goog . object . extend ( hash [ 'style' ] , this . fontStyle_ . toHash ( ) ) ;
492+
493+ goog . object . remove ( hash [ 'style' ] , 'fill-color' ) ;
494+
495+ return hash ;
496+ } ;
497+
498+
499+ /**
500+ * @param {Object } attrs
501+ */
502+ thin . core . AbstractTextGroup . prototype . update = function ( attrs ) {
503+ this . update_ ( attrs ) ;
504+
505+ goog . object . forEach ( attrs , function ( value , attr ) {
506+ switch ( attr ) {
507+ case 'font-family' :
508+ this . setFontFamily ( value ) ;
509+ break ;
510+ case 'font-size' :
511+ this . setFontSize ( value ) ;
512+ break ;
513+ case 'color' :
514+ this . setFillColor ( value ) ;
515+ break ;
516+ case 'text-align' :
517+ this . setTextAnchorFromHash ( value ) ;
518+ break ;
519+ case 'vertical-align' :
520+ this . setVerticalAlignFromHash ( value ) ;
521+ break ;
522+ case 'line-height-ratio' :
523+ this . setTextLineHeightRatio ( value ) ;
524+ break ;
525+ case 'letter-spacing' :
526+ this . setKerning ( value ) ;
527+ break ;
528+ case 'font-style' :
529+ goog . array . forEach ( value , function ( font_style ) {
530+ switch ( font_style ) {
531+ case 'bold' :
532+ this . setFontBold ( true ) ;
533+ break ;
534+ case 'italic' :
535+ this . setFontItalic ( true ) ;
536+ break ;
537+ case 'linethrough' :
538+ this . setFontLinethrough ( true ) ;
539+ break ;
540+ case 'underline' :
541+ this . setFontUnderline ( true ) ;
542+ break ;
543+ }
544+ } , this ) ;
545+ default :
546+ // Do Nothing
547+ break ;
548+ }
549+ } , this ) ;
550+ } ;
0 commit comments