From 1eb6b49e8a073603756fe133766158d98c2f4f41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Thu, 17 Oct 2013 11:47:46 +0200 Subject: [PATCH] Allow serialization values to mark themselves as _default. Solves unnecessarily serialized leading values. --- src/item/Item.js | 6 +++++- src/style/Style.js | 8 +++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/item/Item.js b/src/item/Item.js index 7735930f..93a8652c 100644 --- a/src/item/Item.js +++ b/src/item/Item.js @@ -164,10 +164,14 @@ var Item = Base.extend(Callback, /** @lends Item# */{ function serialize(fields) { for (var key in fields) { var value = that[key]; - if (!Base.equals(value, fields[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])) { 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 ffff0393..6d72394d 100644 --- a/src/style/Style.js +++ b/src/style/Style.js @@ -238,7 +238,13 @@ var Style = Base.extend(new function() { getLeading: function getLeading() { // Override leading to return fontSize * 1.2 by default. var leading = getLeading.base.call(this); - return leading != null ? leading : this.getFontSize() * 1.2; + 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; }, getFontStyle: function() {