Implement an easier approach in serialization to handle the default value of leading.

This commit is contained in:
Jürg Lehni 2013-10-17 11:53:34 +02:00
parent 1eb6b49e8a
commit c2a34d9f1f
2 changed files with 5 additions and 11 deletions

View file

@ -164,10 +164,10 @@ var Item = Base.extend(Callback, /** @lends Item# */{
function serialize(fields) { function serialize(fields) {
for (var key in fields) { for (var key in fields) {
var value = that[key]; var value = that[key];
// Allow returned values to mark themselves as default through // Style#leading is a special case, as its default value is
// the "hidden" _default property. See Style#getLeading() // dependent on the fontSize. Handle this here separately.
if (!(value && value._default) if (!Base.equals(value, key === 'leading'
&& !Base.equals(value, fields[key])) { ? fields.fontSize * 1.2 : fields[key])) {
props[key] = Base.serialize(value, options, props[key] = Base.serialize(value, options,
// Do not use compact mode for data // Do not use compact mode for data
key !== 'data', dictionary); key !== 'data', dictionary);

View file

@ -238,13 +238,7 @@ var Style = Base.extend(new function() {
getLeading: function getLeading() { getLeading: function getLeading() {
// Override leading to return fontSize * 1.2 by default. // Override leading to return fontSize * 1.2 by default.
var leading = getLeading.base.call(this); var leading = getLeading.base.call(this);
if (leading == null) { return leading != null ? leading : this.getFontSize() * 1.2;
// Box default leading in a Number, and mark it as default, for
// serialization.
leading = new Number(this.getFontSize() * 1.2);
leading._default = true;
}
return leading;
}, },
getFontStyle: function() { getFontStyle: function() {