From c2a34d9f1f2fe35fafafba08461191cfaeb30f88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Thu, 17 Oct 2013 11:53:34 +0200 Subject: [PATCH] Implement an easier approach in serialization to handle the default value of leading. --- src/item/Item.js | 8 ++++---- src/style/Style.js | 8 +------- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/src/item/Item.js b/src/item/Item.js index 93a8652c..84b386da 100644 --- a/src/item/Item.js +++ b/src/item/Item.js @@ -164,10 +164,10 @@ var Item = Base.extend(Callback, /** @lends Item# */{ function serialize(fields) { for (var key in fields) { var value = that[key]; - // Allow returned values to mark themselves as default through - // the "hidden" _default property. See Style#getLeading() - if (!(value && value._default) - && !Base.equals(value, fields[key])) { + // Style#leading is a special case, as its default value is + // dependent on the fontSize. Handle this here separately. + if (!Base.equals(value, key === 'leading' + ? fields.fontSize * 1.2 : fields[key])) { props[key] = Base.serialize(value, options, // Do not use compact mode for data key !== 'data', dictionary); diff --git a/src/style/Style.js b/src/style/Style.js index 6d72394d..ffff0393 100644 --- a/src/style/Style.js +++ b/src/style/Style.js @@ -238,13 +238,7 @@ var Style = Base.extend(new function() { getLeading: function getLeading() { // Override leading to return fontSize * 1.2 by default. var leading = getLeading.base.call(this); - if (leading == null) { - // 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; + return leading != null ? leading : this.getFontSize() * 1.2; }, getFontStyle: function() {