1 /**
  2  * Copyright (C) 2014 KO GmbH <copyright@kogmbh.com>
  3  *
  4  * @licstart
  5  * This file is part of WebODF.
  6  *
  7  * WebODF is free software: you can redistribute it and/or modify it
  8  * under the terms of the GNU Affero General Public License (GNU AGPL)
  9  * as published by the Free Software Foundation, either version 3 of
 10  * the License, or (at your option) any later version.
 11  *
 12  * WebODF is distributed in the hope that it will be useful, but
 13  * WITHOUT ANY WARRANTY; without even the implied warranty of
 14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 15  * GNU Affero General Public License for more details.
 16  *
 17  * You should have received a copy of the GNU Affero General Public License
 18  * along with WebODF.  If not, see <http://www.gnu.org/licenses/>.
 19  * @licend
 20  *
 21  * @source: http://www.webodf.org/
 22  * @source: https://github.com/kogmbh/WebODF/
 23  */
 24 
 25 /*global runtime, odf*/
 26 
 27 /**
 28  * @constructor
 29  * @param {!Element} element
 30  * @param {!odf.StyleParseUtils} styleParseUtils
 31  * @param {!odf.TextProperties|undefined} parent
 32  */
 33 odf.TextProperties = function (element, styleParseUtils, parent) {
 34     "use strict";
 35     var self = this,
 36         fons = odf.Namespaces.fons,
 37         getter;
 38     getter = {
 39         fontSize: function () {
 40             var a = element.getAttributeNS(fons, "font-size"),
 41                 value = styleParseUtils.parsePositiveLengthOrPercent(a,
 42                     "fontSize", parent && parent.data);
 43             return value;
 44         }
 45     };
 46     /**
 47      * @return {!number|undefined}
 48      */
 49     this.fontSize = function () {
 50         return /**@type{!number|undefined}*/(self.data.value("fontSize"));
 51     };
 52     /**
 53      * @type {!odf.LazyStyleProperties|undefined}
 54      */
 55     this.data;
 56     function init() {
 57         var p = parent === undefined ? undefined : parent.data;
 58         self.data = new odf.LazyStyleProperties(p, getter);
 59     }
 60     init();
 61 };
 62 /**
 63  * @constructor
 64  */
 65 odf.ComputedTextProperties = function () {
 66     "use strict";
 67     var /**@type{!Object.<!string,*>}*/
 68         data = {},
 69         /**@type{!Array.<!odf.TextProperties>}*/
 70         styleChain = [];
 71     /**
 72      * @param {!string} name
 73      * @return {*}
 74      */
 75     function value(name) {
 76         var v, i;
 77         if (data.hasOwnProperty(name)) {
 78             v = data[name];
 79         } else {
 80             for (i = 0; v === undefined && i < styleChain.length; i += 1) {
 81                 v = /**@type{!function():*}*/(styleChain[i][name])();
 82             }
 83             data[name] = v;
 84         }
 85         return v;
 86     }
 87     /**
 88      * @param {!Array.<!odf.TextProperties>} newStyleChain
 89      * @return {undefined}
 90      */
 91     this.setStyleChain = function setStyleChain(newStyleChain) {
 92         styleChain = newStyleChain;
 93         data = {};
 94     };
 95     /**
 96      * @return {!number}
 97      */
 98     this.fontSize = function () {
 99         return /**@type{!number}*/(value("fontSize")) || 12;
100     };
101 };
102