mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-01 02:38:43 -05:00
Implement an easier approach in serialization to handle the default value of leading.
This commit is contained in:
parent
1eb6b49e8a
commit
c2a34d9f1f
2 changed files with 5 additions and 11 deletions
|
@ -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);
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Reference in a new issue